-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core: Added base files + custom errors
- Loading branch information
Showing
30 changed files
with
1,019 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[flake8] | ||
max-line-length = 120 | ||
exclude = venv/* .venv/* scripts/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Tests | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: [3.8, 3.9, 3.10, 3.11, 3.12] | ||
flask-version: [2.0, 2.1, 2.2, 2.3, 3.0] | ||
|
||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install tox | ||
tox -e py${{ matrix.python-version | replace('.', '') }}-flask${{ matrix.flask-version | replace('.', '') }} | ||
- name: Run tests | ||
run: | | ||
tox -e py${{ matrix.python-version | replace('.', '') }}-flask${{ matrix.flask-version | replace('.', '') }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
repos: | ||
- repo: local | ||
hooks: | ||
- id: meta-lint-commit | ||
name: Lint commit messages | ||
entry: ./scripts/lint-commit.sh | ||
language: script | ||
stages: [commit-msg] | ||
- repo: https://github.com/pycqa/flake8 | ||
rev: 7.0.0 | ||
hooks: | ||
- id: flake8 | ||
- repo: https://github.com/psf/black | ||
rev: 24.4.2 | ||
hooks: | ||
- id: black | ||
language_version: python3.11 | ||
- repo: https://github.com/asottile/reorder_python_imports | ||
rev: v3.13.0 | ||
hooks: | ||
- id: reorder-python-imports | ||
args: [--py3-plus] | ||
- repo: https://github.com/pre-commit/mirrors-mypy | ||
rev: v1.10.0 | ||
hooks: | ||
- id: mypy | ||
additional_dependencies: | ||
- types-flask | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.6.0 | ||
hooks: | ||
- id: check-merge-conflict | ||
- id: debug-statements | ||
- id: check-case-conflict | ||
- id: check-ast | ||
- id: check-builtin-literals | ||
- id: check-docstring-first | ||
- id: detect-private-key | ||
- id: end-of-file-fixer | ||
- id: forbid-submodules | ||
- id: mixed-line-ending | ||
- id: name-tests-test | ||
args: [--pytest-test-first] | ||
exclude: tests/utils.py | ||
- id: requirements-txt-fixer | ||
- id: trailing-whitespace | ||
args: [--markdown-linebreak-ext=md] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Flask-Utils | ||
|
||
A collection of useful Flask utilities I use every day in my Flask projects. | ||
|
||
## Installation | ||
|
||
```bash | ||
pip install flask-utils | ||
``` | ||
|
||
## Usage | ||
|
||
```python | ||
from flask import Flask | ||
from flask_utils import register_error_handlers | ||
from flask_utils import BadRequestError | ||
|
||
app = Flask(__name__) | ||
|
||
register_error_handlers(app) | ||
|
||
@app.route('/') | ||
def index(): | ||
raise BadRequestError | ||
``` | ||
|
||
## Testing | ||
|
||
Install the requirements | ||
```bash | ||
pip install -r requirements-dev.txt | ||
``` | ||
|
||
Make sure tox is at the latest version | ||
```bash | ||
pip install --upgrade tox | ||
``` | ||
|
||
Run the tests | ||
```bash | ||
tox | ||
``` | ||
|
||
OR | ||
|
||
Run the tests multi-threaded | ||
```bash | ||
tox -p | ||
``` | ||
|
||
# TODO: | ||
|
||
- [ ] Documentation | ||
- [ ] Licence | ||
- [ ] Badges | ||
- [ ] Automatic build/deployment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Increment versions here according to SemVer | ||
__version__ = "0.1.0" | ||
|
||
from flask_utils.errors import ConflictError | ||
from flask_utils.errors import ForbiddenError | ||
from flask_utils.errors import UnauthorizedError | ||
from flask_utils.errors import NotFoundError | ||
from flask_utils.errors import BadRequestError | ||
from flask_utils.errors import FailedDependencyError | ||
from flask_utils.errors import OriginIsUnreachableError | ||
from flask_utils.errors import WebServerIsDownError | ||
from flask_utils.errors import GoneError | ||
from flask_utils.errors import UnprocessableEntityError | ||
from flask_utils.errors import ServiceUnavailableError | ||
|
||
|
||
from flask_utils.errors import register_error_handlers | ||
|
||
__all__ = [ | ||
"ConflictError", | ||
"ForbiddenError", | ||
"UnauthorizedError", | ||
"NotFoundError", | ||
"BadRequestError", | ||
"register_error_handlers", | ||
"FailedDependencyError", | ||
"OriginIsUnreachableError", | ||
"WebServerIsDownError", | ||
"GoneError", | ||
"UnprocessableEntityError", | ||
"ServiceUnavailableError", | ||
] |
Oops, something went wrong.