Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit aaa583e

Browse files
committed
Core: Added base files + custom errors
1 parent df0bed1 commit aaa583e

30 files changed

+1019
-0
lines changed

.flake8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
max-line-length = 120
3+
exclude = venv/* .venv/* scripts/*

.github/workflows/tests.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
tests:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
python-version: [3.8, 3.9, 3.10, 3.11, 3.12]
12+
flask-version: [2.0, 2.1, 2.2, 2.3, 3.0]
13+
14+
steps:
15+
- name: Check out repository
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Python ${{ matrix.python-version }}
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install tox
27+
tox -e py${{ matrix.python-version | replace('.', '') }}-flask${{ matrix.flask-version | replace('.', '') }}
28+
29+
- name: Run tests
30+
run: |
31+
tox -e py${{ matrix.python-version | replace('.', '') }}-flask${{ matrix.flask-version | replace('.', '') }}

.gitignore

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
target/
76+
77+
# Jupyter Notebook
78+
.ipynb_checkpoints
79+
80+
# IPython
81+
profile_default/
82+
ipython_config.py
83+
84+
# pyenv
85+
.python-version
86+
87+
# pipenv
88+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91+
# install all needed dependencies.
92+
#Pipfile.lock
93+
94+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
95+
__pypackages__/
96+
97+
# Celery stuff
98+
celerybeat-schedule
99+
celerybeat.pid
100+
101+
# SageMath parsed files
102+
*.sage.py
103+
104+
# Environments
105+
.env
106+
.venv
107+
env/
108+
venv/
109+
ENV/
110+
env.bak/
111+
venv.bak/
112+
113+
# Spyder project settings
114+
.spyderproject
115+
.spyproject
116+
117+
# Rope project settings
118+
.ropeproject
119+
120+
# mkdocs documentation
121+
/site
122+
123+
# mypy
124+
.mypy_cache/
125+
.dmypy.json
126+
dmypy.json
127+
128+
# Pyre type checker
129+
.pyre/

.pre-commit-config.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
repos:
2+
- repo: local
3+
hooks:
4+
- id: meta-lint-commit
5+
name: Lint commit messages
6+
entry: ./scripts/lint-commit.sh
7+
language: script
8+
stages: [commit-msg]
9+
- repo: https://github.com/pycqa/flake8
10+
rev: 7.0.0
11+
hooks:
12+
- id: flake8
13+
- repo: https://github.com/psf/black
14+
rev: 24.4.2
15+
hooks:
16+
- id: black
17+
language_version: python3.11
18+
- repo: https://github.com/asottile/reorder_python_imports
19+
rev: v3.13.0
20+
hooks:
21+
- id: reorder-python-imports
22+
args: [--py3-plus]
23+
- repo: https://github.com/pre-commit/mirrors-mypy
24+
rev: v1.10.0
25+
hooks:
26+
- id: mypy
27+
additional_dependencies:
28+
- types-flask
29+
- repo: https://github.com/pre-commit/pre-commit-hooks
30+
rev: v4.6.0
31+
hooks:
32+
- id: check-merge-conflict
33+
- id: debug-statements
34+
- id: check-case-conflict
35+
- id: check-ast
36+
- id: check-builtin-literals
37+
- id: check-docstring-first
38+
- id: detect-private-key
39+
- id: end-of-file-fixer
40+
- id: forbid-submodules
41+
- id: mixed-line-ending
42+
- id: name-tests-test
43+
args: [--pytest-test-first]
44+
exclude: tests/utils.py
45+
- id: requirements-txt-fixer
46+
- id: trailing-whitespace
47+
args: [--markdown-linebreak-ext=md]

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Flask-Utils
2+
3+
A collection of useful Flask utilities I use every day in my Flask projects.
4+
5+
## Installation
6+
7+
```bash
8+
pip install flask-utils
9+
```
10+
11+
## Usage
12+
13+
```python
14+
from flask import Flask
15+
from flask_utils import register_error_handlers
16+
from flask_utils import BadRequestError
17+
18+
app = Flask(__name__)
19+
20+
register_error_handlers(app)
21+
22+
@app.route('/')
23+
def index():
24+
raise BadRequestError
25+
```
26+
27+
## Testing
28+
29+
Install the requirements
30+
```bash
31+
pip install -r requirements-dev.txt
32+
```
33+
34+
Make sure tox is at the latest version
35+
```bash
36+
pip install --upgrade tox
37+
```
38+
39+
Run the tests
40+
```bash
41+
tox
42+
```
43+
44+
OR
45+
46+
Run the tests multi-threaded
47+
```bash
48+
tox -p
49+
```
50+
51+
# TODO:
52+
53+
- [ ] Documentation
54+
- [ ] Licence
55+
- [ ] Badges
56+
- [ ] Automatic build/deployment

flask_utils/__init__.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Increment versions here according to SemVer
2+
__version__ = "0.1.0"
3+
4+
from flask_utils.errors import ConflictError
5+
from flask_utils.errors import ForbiddenError
6+
from flask_utils.errors import UnauthorizedError
7+
from flask_utils.errors import NotFoundError
8+
from flask_utils.errors import BadRequestError
9+
from flask_utils.errors import FailedDependencyError
10+
from flask_utils.errors import OriginIsUnreachableError
11+
from flask_utils.errors import WebServerIsDownError
12+
from flask_utils.errors import GoneError
13+
from flask_utils.errors import UnprocessableEntityError
14+
from flask_utils.errors import ServiceUnavailableError
15+
16+
17+
from flask_utils.errors import register_error_handlers
18+
19+
__all__ = [
20+
"ConflictError",
21+
"ForbiddenError",
22+
"UnauthorizedError",
23+
"NotFoundError",
24+
"BadRequestError",
25+
"register_error_handlers",
26+
"FailedDependencyError",
27+
"OriginIsUnreachableError",
28+
"WebServerIsDownError",
29+
"GoneError",
30+
"UnprocessableEntityError",
31+
"ServiceUnavailableError",
32+
]

0 commit comments

Comments
 (0)