Repository navigation
style: adopt ruff and pre-commit - #267
Conversation
Replace setup.py and the requirements*.txt files with PEP 621 metadata in pyproject.toml (setuptools backend). Distribution name, import package and the `dev` and `docs` extras are unchanged. - declare `requires-python = ">=3.10"` (3.9 is end of life) - ship `py.typed` inside the package so the "Typed" classifier holds - package only `foca*`, so `tests` is no longer installed into site-packages; configure pytest `pythonpath` so tests still import - declare `typing_extensions` as a runtime dependency (it is imported by `foca.models.config`) - drop the obsolete `typing` backport and the unused `toml`, `mypy-extensions`, `types-urllib3`, `types-setuptools`, `pylint`, `python-semantic-release` and `readthedocs-sphinx-ext` - drop `setup_requires` and the setuptools-git based MANIFEST.in - remove the stale semantic-release config from setup.cfg; move the mypy config to pyproject.toml (flake8 config stays in setup.cfg until ruff replaces it) - install FOCA directly from the source tree in the Docker image Closes #232 Co-Authored-By: Claude Opus 5.5 <[email protected]>
FOCA now requires Python >= 3.10. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Update runtime, dev and docs dependencies while staying on Connexion 2. Ranges now allow minor/patch updates within the current major version. - connexion >=2.15.1,<3: makes explicit what was already resolved (2.15 is the only 2.x line compatible with Werkzeug 3) - Flask >=3.1.3,<4 (fixes CVE-2026-27205); Flask-PyMongo 3.x - cryptography >=50 (fixes six advisories in 44.x) - flask-authz <2.8 (2.8+ hard-pins a vulnerable Flask) - swagger-ui-bundle >=1.1 (Swagger UI 4; required by connexion 2.15) - raise floors of celery, Flask-Cors, PyJWT, requests and dev/docs tools (Sphinx >=8, sphinx-rtd-theme >=3) pip-audit reports no known vulnerabilities for the updated set. BREAKING CHANGE: FOCA now requires Flask 3. Apps using APIs removed in Flask 3 (e.g. `flask.Markup`, `_app_ctx_stack`, custom JSON encoders) need to be updated. Closes #216 Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Docker: default to python:3.13-slim-trixie (Debian 13), use trixie-based images in CI, fix Dockerfile lint (`AS`, `ENV K=V`) - examples: MongoDB 8.0, Python 3.13 images, drop obsolete compose `version` key - Read the Docs: Ubuntu 24.04 and Python 3.13; install only the `docs` extra Co-Authored-By: Claude Opus 5.5 <[email protected]>
- update actions (Node 24 versions) and pin them by commit SHA - split into lint/build, unit test, integration test and image jobs - test Python 3.10-3.14 against MongoDB 8.0 (plus 3.13 on 7.0) instead of 16 jobs with EOL MongoDB versions; upload coverage and run the petstore integration tests once - check that sdist and wheel build and pass `twine check` - wait for the petstore app instead of sleeping; show logs on failure - push Docker images only for pushes to `dev`, add Python 3.13/3.14 images and move `latest` to 3.13; skip image builds on PRs (the integration job already builds one) - restrict token permissions, cancel superseded PR runs, set job timeouts, cache pip downloads - replace the blanket `-W ignore::DeprecationWarning` with targeted pytest filters for connexion's use of deprecated jsonschema APIs - add Python 3.13 and 3.14 classifiers Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build sdist and wheel when a GitHub release is published, check that the release tag matches the package version, and upload to PyPI via trusted publishing from the `pypi` environment (no API token). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Weekly grouped updates for Python dependencies, GitHub Actions and the Docker base image, targeting `dev`. Connexion major updates are ignored until the Connexion 3 migration (#188). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Configure ruff for linting and formatting (line length 79, as used by the existing code) with pycodestyle, Pyflakes, isort, pyupgrade, pydocstyle (Google convention), Pylint, bugbear, simplify, comprehensions and Ruff-specific rules. Complexity limits are left disabled for now. Tests are exempt from docstring and magic-value rules. Run `ruff check` and `ruff format --check` in CI instead of flake8, and add a pre-commit config with ruff and basic file hygiene hooks. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Automatic, behaviour-preserving fixes by `ruff check --fix`: PEP 585 and PEP 604 annotations (closes #231), sorted imports, docstring whitespace, f-strings, and simplified conditionals and with-blocks. Co-Authored-By: Claude Opus 5.5 <[email protected]>
One-off reformat of all Python files with `ruff format` (Black style, line length 79). No functional changes; one `type: ignore` comment was moved back to the line it applies to. Closes #237 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Docstrings (closes #239): - add package, class and method docstrings where missing - shorten multi-line summaries to one line (Google convention) Linting (closes #238): - chain exceptions raised in `except` blocks (`raise ... from exc`) - replace mutable argument default in `_validate_jwt_public_key()` - replace attribute probe with `hasattr()` and try/except/pass with `contextlib.suppress()` in exception config validation - merge nested `with` statements in tests; minor simplifications Disable magic-value comparisons (PLR2004), which only flag HTTP status codes and Casbin rule lengths, and docstring rules for docs and examples. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # .github/workflows/checks.yml # pyproject.toml
Reviewer's GuideThis PR replaces the flake8-era tooling with Ruff and pre-commit, reformats and modernizes the codebase to satisfy the new rules, and refreshes CI, dependency automation, Docker validation, and release publishing around pinned actions, newer Python versions, and trusted PyPI publishing; functional behavior is intended to remain unchanged apart from preserved exception causes. Flow diagram for release distribution publishingflowchart LR
Release[Published GitHub release] --> TagCheck[Check release tag and package version]
TagCheck --> Build[Build distributions]
Build --> Twine[twine check]
Twine --> Artifact[Upload distribution artifact]
Artifact --> TrustedPublish[Trusted PyPI publishing]
TrustedPublish --> PyPI[PyPI]
Flow diagram for CI image validation and publishingflowchart LR
Push[Push to default branch] --> Gates[Lint type-check build tests and integration]
Gates --> DockerBuild[Build Docker images for Python 3.10 to 3.14]
DockerBuild --> DockerHub[Push versioned images to Docker Hub]
DockerBuild --> Latest[Python 3.13 image receives latest tag]
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #267 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 22 22
Lines 1113 1103 -10
=========================================
- Hits 1113 1103 -10
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 Changes recommended
The YAML hook needs an exclusion for the intentionally malformed fixture so the documented all-files check can pass.
1 open issue
What changed in this PR
Adopts Ruff and pre-commit for consistent FOCA code quality, building on the dependency and CI modernization in #265 and #266.
Changes:
- Replaces Flake8 with Ruff linting, formatting, and pre-commit hooks.
- Modernizes Python annotations, formatting, docstrings, and exception chaining.
- Includes updated dependencies, runtime images, CI, and release automation.
| File | Description |
|---|---|
| tests/utils/test_misc.py | Cleans up test docstrings. |
| tests/utils/test_logging.py | Reformats logging tests. |
| tests/utils/test_db.py | Standardizes string quotes. |
| tests/test_foca.py | Sorts imports and formats paths. |
| tests/test_files/models_petstore.py | Modernizes model annotations. |
| tests/test_files/model_valid.py | Formats model fixture. |
| tests/security/test_cors.py | Standardizes quotes. |
| tests/security/test_auth.py | Formats tests and combines context managers. |
| tests/security/access_control/test_register_access_control.py | Formats permission tests. |
| tests/security/access_control/test_enforcement.py | Modernizes annotations and formats tests. |
| tests/security/access_control/test_access_control_server.py | Formats controller tests. |
| tests/security/access_control/foca_casbin_adapter/test_casbin_rule.py | Formats rule fixtures. |
| tests/security/access_control/foca_casbin_adapter/test_adapter.py | Modernizes test annotations. |
| tests/models/test_config.py | Formats configuration tests. |
| tests/mock_data.py | Formats shared fixtures. |
| tests/factories/test_connexion_app.py | Sorts imports and standardizes quotes. |
| tests/factories/test_celery_app.py | Simplifies import formatting. |
| tests/errors/test_errors.py | Formats exception tests. |
| tests/database/test_register_mongodb.py | Formats database tests. |
| tests/config/test_config_parser.py | Formats tests and uses type identity checks. |
| tests/api/test_register_openapi.py | Formats specification tests. |
| setup.cfg | Removes Flake8 configuration. |
| README.md | Formats Python examples. |
| pyproject.toml | Configures Ruff and updates dependencies. |
| foca/version.py | Standardizes quotes only. |
| foca/utils/misc.py | Formats identifier utility. |
| foca/utils/logging.py | Modernizes annotations and string formatting. |
| foca/utils/db.py | Modernizes annotations and formats queries. |
| foca/utils/__init__.py | Adds package docstring. |
| foca/security/cors.py | Cleans up documentation and formatting. |
| foca/security/auth.py | Uses immutable algorithm default and exception chaining. |
| foca/security/access_control/register_access_control.py | Modernizes annotations and formatting. |
| foca/security/access_control/foca_casbin_adapter/casbin_rule.py | Updates annotations and representation formatting. |
| foca/security/access_control/foca_casbin_adapter/adapter.py | Modernizes annotations and docstrings. |
| foca/security/access_control/foca_casbin_adapter/__init__.py | Adds package docstring. |
| foca/security/access_control/enforcement.py | Modernizes annotations and formats enforcement code. |
| foca/security/access_control/constants.py | Cleans up module docstring. |
| foca/security/access_control/api/__init__.py | Adds package docstring. |
| foca/security/access_control/access_control_server.py | Formats controllers and chains exceptions. |
| foca/security/__init__.py | Adds package docstring. |
| foca/models/config.py | Modernizes annotations and simplifies validation code. |
| foca/models/__init__.py | Adds package docstring. |
| foca/foca.py | Adds class documentation and simplifies branching. |
| foca/factories/connexion_app.py | Modernizes annotations and logging formatting. |
| foca/factories/celery_app.py | Formats factory code and docstrings. |
| foca/factories/__init__.py | Adds package docstring. |
| foca/errors/exceptions.py | Modernizes annotations and formatting. |
| foca/errors/__init__.py | Adds package docstring. |
| foca/database/register_mongodb.py | Formats database registration code. |
| foca/database/__init__.py | Adds package docstring. |
| foca/config/config_parser.py | Modernizes annotations and chains import errors. |
| foca/config/__init__.py | Adds package docstring. |
| foca/api/register_openapi.py | Modernizes annotations and formats registration code. |
| foca/api/__init__.py | Adds package docstring. |
| examples/petstore/docker-compose.yaml | Updates Python and MongoDB images. |
| examples/petstore/controllers.py | Formats controllers and simplifies comparisons. |
| examples/petstore/app.py | Formats application entry point. |
| examples/petstore-access-control/exceptions.py | Sorts imports. |
| examples/petstore-access-control/docker-compose.yaml | Updates Python and MongoDB images. |
| examples/petstore-access-control/controllers.py | Formats permission-protected controllers. |
| examples/petstore-access-control/app.py | Formats application entry point. |
| docs/api/conf.py | Formats configuration and closes version file explicitly. |
| docker/Dockerfile | Updates base image and Dockerfile syntax. |
| .readthedocs.yaml | Updates build environment and limits extras. |
| .pre-commit-config.yaml | Adds Ruff and file-hygiene hooks. |
| .github/workflows/release.yml | Adds validated PyPI trusted publishing. |
| .github/workflows/checks.yml | Adds Ruff checks and modernizes CI jobs. |
| .github/dependabot.yml | Adds scheduled dependency updates. |
Review effort: Balanced
Exclude the deliberately malformed YAML fixture from `check-yaml` and keep Markdown hard line breaks in `trailing-whitespace`, so that `pre-commit run --all-files` passes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
One-off fixes by the `end-of-file-fixer` and `trailing-whitespace` pre-commit hooks. No content changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path=".github/workflows/checks.yml" line_range="120" />
<code_context>
+ - name: Wait for petstore app
+ run: |
+ for _ in $(seq 1 30); do
+ curl -s -o /dev/null http://localhost:8080/ && exit 0
+ sleep 2
+ done
</code_context>
<issue_to_address>
**Integration tests race MongoDB startup**
When mongoDB is still starting when the app begins responding to HTTP requests, the readiness loop accepts any HTTP response from the app, then immediately starts database-dependent tests; if MongoDB is not ready, those requests fail and the integration job fails.
Wait for MongoDB to become healthy, or make the readiness probe verify a database-backed request before running the integration tests.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 1 finding to address first, and publishing a GitHub release now uploads distributions to PyPI, and pushes can publish Docker image tags; a bad artifact can be installed or pulled before the workflow is reverted. Reverting stops future uploads but does not remove artifacts already published or undo downstream installs.
Blocking findings: .github/workflows/checks.yml:120
Resolve conflicts with the squash-merged #264, #265 and #266: - CI workflow: keep linting and format checks with ruff from this branch, take the commit-timestamp Docker tags from dev. - Release workflow: take the release commit check and skip-existing uploads from dev. - pyproject.toml: keep ruff and pre-commit instead of flake8 in the dev extra. Co-Authored-By: Claude Opus 5.5 <[email protected]>

Summary
Fourth and last tooling PR of the v0.14.0 maintenance series. Builds on #266 (and #265); please merge those first. The commits specific to this PR are the
build:/style:commits on top.Adopts ruff for linting and formatting and adds pre-commit, superseding #252 (thanks @JaeAeich for the initial proposal).
Tooling
ruff checkandruff format --checkrun in CIsetattr()with constants is used deliberately for dynamic config attributes; "fixing" it breaks mypy).pre-commit-config.yamlwith ruff and basic file hygiene hooks (pre-commit install)setup.cfgremoved (it only held the flake8 config)check-yamlskips the deliberately malformed test fixturetests/test_files/invalid_conf.yaml;trailing-whitespacekeeps Markdown hard line breaks (thanks Copilot)Code changes
style: apply ruff autofixes: PEP 585/604 annotations (dict[...],X | None), sorted imports, docstring whitespace, f-strings, simplified conditionals/with-blocksstyle: format code with ruff: one-off reformat (Black style); onetype: ignorecomment moved back to the line it applies tostyle: fix remaining ruff findings: missing docstrings, one-line docstring summaries, exception chaining (raise ... from exc), immutable default foralgorithmsin_validate_jwt_public_key(),hasattr()/contextlib.suppress()in exception config validation, merged nestedwithblocks in testsstyle: fix trailing whitespace and final newlines: one-off fixes by the pre-commit file hygiene hooks (whitespace only)No functional changes intended. The only behavioural nuance: exceptions re-raised in
exceptblocks now carry the original exception as__cause__.Closes #231, closes #237, closes #238, closes #239
Follow-up after merging
If this is squash-merged, add the squash commit's SHA to a
.git-blame-ignore-revsfile so thatgit blame(and GitHub's blame view) skips the reformat. I did not add it here because the commit SHA changes on squash.Noted for the code audit (not changed here)
mypy --warn-unused-ignoresreports 7 unusedtype: ignorecomments (pre-existing; Fix ignoredmypyerrors #144)CasbinRule.__repr__()contains a leftover debugprint()Verification
Locally (Python 3.13 and 3.10):
ruff check .: all checks passed;ruff format --check .: all files formattedmypy foca: no issuespytest(unit tests without MongoDB): 246 passed on 3.13 and 3.10 (parenthesized context managers require Python >= 3.10, which is the minimum since build: migrate to pyproject.toml #264)Not run locally (no MongoDB/Docker access in my environment): MongoDB-dependent tests and petstore integration tests; covered by CI.
CI: all checks pass (run): ruff lint + format check, mypy, build, unit tests incl. MongoDB-dependent tests on Python 3.10–3.14, petstore integration tests, Read the Docs.
Open questions
None.
🤖 Generated with Claude Code
Summary by Sourcery
Adopt Ruff and pre-commit as the project's standardized linting, formatting, and file-hygiene tooling.
New Features:
Bug Fixes:
Enhancements:
Build:
CI:
Tests: