-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Update the FastAPI template for current practices
Update for current FastAPI recommendations and warnings: - Use a lifespan function instead of hooks - Update to Pydantic v2 - Use Annotated for injected dependencies in route functions Use Pydantic's support for environment variable prefixes to use the same prefix for all environment variables used for configuration, instead of using SAFIR_ for the default options. Update the Makefile for current best practices: - Add a make help default target - Upgrade pip before updating dependencies - Run pre-commit autoupdate during make update-deps - Add --allow-unsafe to pip-compile because setuptools is normally needed (and we've not had any problems with it in the past) Remove the dependency update CI job. We've found this is more annoying than helpful; it's easier to update using make update at the start of a development cycle. Switch to Ruff for both linting and reformatting; remove the Black, isort, and flake8 configurations; and update the Ruff configuration with more exclusions. Update the default and minimum version of Python to 3.12.
Showing
22 changed files
with
226 additions
and
228 deletions.
There are no files selected for viewing
24 changes: 8 additions & 16 deletions
24
project_templates/fastapi_safir_app/example/.pre-commit-config.yaml
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 |
---|---|---|
@@ -1,22 +1,14 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.4.0 | ||
rev: v4.5.0 | ||
hooks: | ||
- id: check-yaml | ||
- id: check-toml | ||
- id: check-yaml | ||
- id: trailing-whitespace | ||
|
||
- repo: https://github.com/pycqa/isort | ||
rev: 5.12.0 | ||
hooks: | ||
- id: isort | ||
additional_dependencies: [toml] | ||
|
||
- repo: https://github.com/psf/black | ||
rev: 23.3.0 | ||
hooks: | ||
- id: black | ||
|
||
- repo: https://github.com/pycqa/flake8 | ||
rev: 6.0.0 | ||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
rev: v0.1.14 | ||
hooks: | ||
- id: flake8 | ||
- id: ruff | ||
args: [--fix, --exit-non-zero-on-fix] | ||
- id: ruff-format |
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
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 |
---|---|---|
@@ -1,27 +1,51 @@ | ||
.PHONY: update-deps | ||
update-deps: | ||
pip install --upgrade pip-tools pip setuptools | ||
pip-compile --upgrade --resolver=backtracking --build-isolation --generate-hashes --output-file requirements/main.txt requirements/main.in | ||
pip-compile --upgrade --resolver=backtracking --build-isolation --generate-hashes --output-file requirements/dev.txt requirements/dev.in | ||
|
||
# Useful for testing against a Git version of Safir. | ||
.PHONY: update-deps-no-hashes | ||
update-deps-no-hashes: | ||
pip install --upgrade pip-tools pip setuptools | ||
pip-compile --upgrade --resolver=backtracking --build-isolation --allow-unsafe --output-file requirements/main.txt requirements/main.in | ||
pip-compile --upgrade --resolver=backtracking --build-isolation --allow-unsafe --output-file requirements/dev.txt requirements/dev.in | ||
.PHONY: help | ||
help: | ||
@echo "Make targets for Gafaelfawr" | ||
@echo "make init - Set up dev environment" | ||
@echo "make run - Start a local development instance" | ||
@echo "make update - Update pinned dependencies and run make init" | ||
@echo "make update-deps - Update pinned dependencies" | ||
@echo "make update-deps-no-hashes - Pin dependencies without hashes" | ||
|
||
.PHONY: init | ||
init: | ||
pip install --upgrade pip | ||
pip install --upgrade pre-commit tox | ||
pip install --editable . | ||
pip install --upgrade -r requirements/main.txt -r requirements/dev.txt | ||
rm -rf .tox | ||
pip install --upgrade pre-commit tox | ||
pre-commit install | ||
|
||
.PHONY: update | ||
update: update-deps init | ||
|
||
.PHONY: run | ||
run: | ||
tox run -e run | ||
|
||
.PHONY: update | ||
update: update-deps init | ||
|
||
# The dependencies need --allow-unsafe because kubernetes-asyncio and | ||
# (transitively) pre-commit depends on setuptools, which is normally not | ||
# allowed to appear in a hashed dependency file. | ||
.PHONY: update-deps | ||
update-deps: | ||
pip install --upgrade pip | ||
pip install --upgrade pre-commit | ||
pre-commit autoupdate | ||
pip install --upgrade pip-tools pip setuptools | ||
pip-compile --upgrade --resolver=backtracking --build-isolation \ | ||
--allow-unsafe --generate-hashes \ | ||
--output-file requirements/main.txt requirements/main.in | ||
pip-compile --upgrade --resolver=backtracking --build-isolation \ | ||
--allow-unsafe --generate-hashes \ | ||
--output-file requirements/dev.txt requirements/dev.in | ||
|
||
# Useful for testing against a Git version of Safir. | ||
.PHONY: update-deps-no-hashes | ||
update-deps-no-hashes: | ||
pip install --upgrade pip-tools pip setuptools | ||
pip-compile --upgrade --resolver=backtracking --build-isolation \ | ||
--allow-unsafe \ | ||
--output-file requirements/main.txt requirements/main.in | ||
pip-compile --upgrade --resolver=backtracking --build-isolation \ | ||
--allow-unsafe \ | ||
--output-file requirements/dev.txt requirements/dev.in |
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
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 |
---|---|---|
|
@@ -19,6 +19,7 @@ pydantic | |
pytest | ||
pytest-asyncio | ||
pytest-cov | ||
ruff | ||
|
||
# Documentation | ||
scriv |
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 |
---|---|---|
|
@@ -13,4 +13,6 @@ starlette | |
uvicorn[standard] | ||
|
||
# Other dependencies. | ||
safir>=3.4.0 | ||
pydantic | ||
pydantic-settings | ||
safir>=5 |
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
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
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
7 changes: 0 additions & 7 deletions
7
project_templates/fastapi_safir_app/{{cookiecutter.name}}/.flake8
This file was deleted.
Oops, something went wrong.
35 changes: 0 additions & 35 deletions
35
...ect_templates/fastapi_safir_app/{{cookiecutter.name}}/.github/workflows/dependencies.yaml
This file was deleted.
Oops, something went wrong.
24 changes: 8 additions & 16 deletions
24
project_templates/fastapi_safir_app/{{cookiecutter.name}}/.pre-commit-config.yaml
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 |
---|---|---|
@@ -1,22 +1,14 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.4.0 | ||
rev: v4.5.0 | ||
hooks: | ||
- id: check-yaml | ||
- id: check-toml | ||
- id: check-yaml | ||
- id: trailing-whitespace | ||
|
||
- repo: https://github.com/pycqa/isort | ||
rev: 5.12.0 | ||
hooks: | ||
- id: isort | ||
additional_dependencies: [toml] | ||
|
||
- repo: https://github.com/psf/black | ||
rev: 23.3.0 | ||
hooks: | ||
- id: black | ||
|
||
- repo: https://github.com/pycqa/flake8 | ||
rev: 6.0.0 | ||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
rev: v0.1.14 | ||
hooks: | ||
- id: flake8 | ||
- id: ruff | ||
args: [--fix, --exit-non-zero-on-fix] | ||
- id: ruff-format |
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
56 changes: 40 additions & 16 deletions
56
project_templates/fastapi_safir_app/{{cookiecutter.name}}/Makefile
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 |
---|---|---|
@@ -1,27 +1,51 @@ | ||
.PHONY: update-deps | ||
update-deps: | ||
pip install --upgrade pip-tools pip setuptools | ||
pip-compile --upgrade --resolver=backtracking --build-isolation --generate-hashes --output-file requirements/main.txt requirements/main.in | ||
pip-compile --upgrade --resolver=backtracking --build-isolation --generate-hashes --output-file requirements/dev.txt requirements/dev.in | ||
|
||
# Useful for testing against a Git version of Safir. | ||
.PHONY: update-deps-no-hashes | ||
update-deps-no-hashes: | ||
pip install --upgrade pip-tools pip setuptools | ||
pip-compile --upgrade --resolver=backtracking --build-isolation --allow-unsafe --output-file requirements/main.txt requirements/main.in | ||
pip-compile --upgrade --resolver=backtracking --build-isolation --allow-unsafe --output-file requirements/dev.txt requirements/dev.in | ||
.PHONY: help | ||
help: | ||
@echo "Make targets for Gafaelfawr" | ||
@echo "make init - Set up dev environment" | ||
@echo "make run - Start a local development instance" | ||
@echo "make update - Update pinned dependencies and run make init" | ||
@echo "make update-deps - Update pinned dependencies" | ||
@echo "make update-deps-no-hashes - Pin dependencies without hashes" | ||
|
||
.PHONY: init | ||
init: | ||
pip install --upgrade pip | ||
pip install --upgrade pre-commit tox | ||
pip install --editable . | ||
pip install --upgrade -r requirements/main.txt -r requirements/dev.txt | ||
rm -rf .tox | ||
pip install --upgrade pre-commit tox | ||
pre-commit install | ||
|
||
.PHONY: update | ||
update: update-deps init | ||
|
||
.PHONY: run | ||
run: | ||
tox run -e run | ||
|
||
.PHONY: update | ||
update: update-deps init | ||
|
||
# The dependencies need --allow-unsafe because kubernetes-asyncio and | ||
# (transitively) pre-commit depends on setuptools, which is normally not | ||
# allowed to appear in a hashed dependency file. | ||
.PHONY: update-deps | ||
update-deps: | ||
pip install --upgrade pip | ||
pip install --upgrade pre-commit | ||
pre-commit autoupdate | ||
pip install --upgrade pip-tools pip setuptools | ||
pip-compile --upgrade --resolver=backtracking --build-isolation \ | ||
--allow-unsafe --generate-hashes \ | ||
--output-file requirements/main.txt requirements/main.in | ||
pip-compile --upgrade --resolver=backtracking --build-isolation \ | ||
--allow-unsafe --generate-hashes \ | ||
--output-file requirements/dev.txt requirements/dev.in | ||
|
||
# Useful for testing against a Git version of Safir. | ||
.PHONY: update-deps-no-hashes | ||
update-deps-no-hashes: | ||
pip install --upgrade pip-tools pip setuptools | ||
pip-compile --upgrade --resolver=backtracking --build-isolation \ | ||
--allow-unsafe \ | ||
--output-file requirements/main.txt requirements/main.in | ||
pip-compile --upgrade --resolver=backtracking --build-isolation \ | ||
--allow-unsafe \ | ||
--output-file requirements/dev.txt requirements/dev.in |
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
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 |
---|---|---|
|
@@ -19,6 +19,7 @@ pydantic | |
pytest | ||
pytest-asyncio | ||
pytest-cov | ||
ruff | ||
|
||
# Documentation | ||
scriv |
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 |
---|---|---|
|
@@ -13,4 +13,6 @@ starlette | |
uvicorn[standard] | ||
|
||
# Other dependencies. | ||
safir>=3.4.0 | ||
pydantic | ||
pydantic-settings | ||
safir>=5 |
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
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
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
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
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