Skip to content

style: adopt the shared ruff, mypy and pre-commit - #231

Merged
uniqueg merged 8 commits into
devfrom
style/shared-lint
Oct 22, 2026
Merged

uniqueg merged 8 commits into
devfrom
style/shared-lint

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #206 and #116. This is part 2: the reformat landed in #227 and is listed in .git-blame-ignore-revs. Supersedes PR #180.

This adopts the standard that FOCA and FOCA apps share, exactly as in cloud-registry.

  • ruff (pyproject.toml): rule set B C4 D E F G I PL RUF S SIM UP W with cloud-registry's ignores, Google docstrings everywhere, line length 88.
  • mypy: disallow_untyped_defs, disallow_any_generics and warn_unused_ignores over pro_tes and tests. Packages without type information (connexion, py-tes, geopy, ip2geotools, gunicorn) get overrides instead of inline ignores.
  • pre-commit (.pre-commit-config.yaml, hooks pinned to commits):
    • pre-commit-hooks, ruff (check and format), gitleaks (staged files, plus all files in CI), actionlint.
    • semgrep with .semgrep/pro-tes.yml: Flask debug mode, unverified JWTs.
    • Local ast-grep with rule tests: untyped FOCA config access, Pydantic v1 .dict(), string status codes.
    • Local mypy.
  • CI:
    • One "Static code analysis" job runs pre-commit (and gitleaks-all), builds the distributions and checks the wheel.
    • All actions are pinned to commits. Superseded runs of a pull request are cancelled, and every job has a timeout.
    • Python versions stay as they are until build!: require FOCA 0.17 and Python 3.13 #214 (3.13 only).
  • Removed: flake8 and pylint, their settings (.flake8, pylintrc) and all pylint comments.
  • Findings fixed:
    • Logging uses lazy arguments.
    • Asserts in app code are replaced by explicit errors:
      • a missing body raises BadRequest;
      • a body removed by middlewares raises MiddlewareException (500);
      • missing logs, metadata or forwards raise ValueError (500, as before).
    • Integration tests have request timeouts.
    • The TES models and tests have docstrings, and type hints are complete.
    • States uses ClassVar.
    • Bug fixed: get_task() had the type str as the default of its task identifier.
  • Whitespace: docs/images/overview.svg gets a final newline only, as agreed with the docs work (docs/middleware.md was removed on dev in docs: switch to a MkDocs Material site #228).
  • Docs site (docs: switch to a MkDocs Material site #228): mkdocs.yml is excluded from check-yaml because of its !ENV tag, and docs/hooks.py is type-checked, both as in cloud-registry. The CI publish job also needs the new docs job. docs/development.md describes the pre-commit workflow instead of flake8 and pylint, using the cloud-registry wording.
  • Left for later:

Full review lane.

How it was verified

  • pre-commit run --all-files: all hooks pass, as does pre-commit run --all-files --hook-stage manual gitleaks-all.
  • pytest tests --ignore=tests/unitTest --ignore=tests/test_integration: 41 passed.
  • Review: two rounds of adversarial and quality reviews. The high finding (actionlint/shellcheck would fail on an unquoted $GITHUB_ENV) and all medium findings (dead pylint comments) are fixed.

CI: all checks pass (Static code analysis, including actionlint with ShellCheck on the runner; documentation build; unit tests on 3.10 and 3.12; Compose integration tests; CodeQL). mkdocs build --strict also passes locally.

Declined review findings

Open questions

None.

🤖 Generated with Claude Code

Summary by Sourcery

Adopt the shared FOCA code-quality standard across formatting, typing, security checks, documentation, and CI.

Bug Fixes:

  • Replace assertion-based runtime failures with explicit application errors and correct the task identifier typing default.
  • Add request timeouts to integration tests.

Enhancements:

  • Adopt the shared Ruff and mypy standards with complete typing, Google-style docstrings, and modern Python type syntax.
  • Replace Flake8 and Pylint with a pinned pre-commit workflow covering formatting, linting, type checking, security scanning, workflow validation, and project-specific anti-pattern checks.
  • Improve CI reliability and security through consolidated static analysis, pinned actions, caching, concurrency cancellation, job timeouts, and distribution checks.
  • Use lazy logging arguments throughout the application and clarify TES model and test documentation.

Build:

  • Update development dependencies and project configuration for Ruff, mypy, pre-commit, ast-grep, and related checks; remove Flake8 and Pylint configuration.

CI:

  • Consolidate static analysis in CI and pin GitHub Actions to commits while adding workflow and secret scanning.

Documentation:

  • Update development documentation to describe the pre-commit-based validation workflow and project-specific checks.

Tests:

  • Add ast-grep rule tests and complete typing and docstrings across the tested code.
  • Strengthen model tests and make integration tests bounded by request timeouts.

Chores:

  • Add repository-wide security and anti-pattern rules for unsafe Flask debug mode, unverified JWT decoding, untyped FOCA configuration access, Pydantic v1 serialization, and string HTTP status codes.

uniqueg and others added 7 commits October 22, 2026 21:18
Format all Python code with ruff format, line length 88, as in
cloud-registry and FOCA; strip trailing whitespace and end files with
one newline, as the pre-commit hooks of the shared standard will
require. Only formatting changes, so that the commit can be ignored by
git blame; the shared lint rules, strict mypy and pre-commit follow
separately. Vendored GA4GH specifications are kept as published; the
README, docs and community files are left to the docs work. flake8
accepts the line length and slice spacing of ruff format until ruff
replaces it.

Refs #206

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Adopt the standard shared by FOCA and FOCA apps, as in cloud-registry:
ruff with the rule set B C4 D E F G I PL RUF S SIM UP W and Google
docstrings everywhere; strict mypy (disallow_untyped_defs,
disallow_any_generics, warn_unused_ignores) over pro_tes and tests;
pre-commit with pre-commit-hooks, ruff, semgrep (Flask debug mode,
unverified JWTs), gitleaks, actionlint, ast-grep (untyped FOCA config
access, Pydantic v1 dict(), string status codes) and mypy. Remove
flake8, pylint and their settings.

Fix the findings: lazy logging arguments, explicit errors instead of
asserts in app code, request timeouts in the integration tests,
docstrings of the TES models, complete type hints. get_task() had the
type str as the default of its task identifier.

tests/unitTest is excluded until #207 fixes or removes it.

List the reformat (#227) in .git-blame-ignore-revs, and fix the file
ends and trailing whitespace of docs/middleware.md and
docs/images/overview.svg, which the reformat left to the docs work.

CI runs pre-commit in one "Static code analysis" job; actions are
pinned to commits, runs of a pull request are cancelled when superseded,
and jobs have timeouts.

Closes #206
Closes #116

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	.flake8
#	pro_tes/ga4gh/tes/models.py
#	pro_tes/ga4gh/tes/server.py
#	pro_tes/ga4gh/tes/task_runs.py
#	pro_tes/middleware/middleware_handler.py
#	pyproject.toml
#	tests/conftest.py
#	tests/test_integration/test_endpoints.py
#	tests/test_tasks.py
pylint is replaced by ruff, whose PL rules need none of the
suppressions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Quote $GITHUB_ENV, which shellcheck (via actionlint) flags on the
runners. A request whose JSON body the middlewares removed is a server
fault (MiddlewareException, 500), not a bad request. Tasks without logs
fail loudly again when the forward is recorded, instead of the forward
being dropped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	.github/workflows/checks.yaml
#	docs/middleware.md
@sourcery-ai

sourcery-ai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

This PR replaces Flake8/Pylint with the shared Ruff, mypy, and pre-commit standard, adds pinned quality and security checks—including Semgrep and ast-grep rules—and integrates them into reproducible CI. It also updates the application and tests with complete typing, lazy logging, explicit error handling, docstrings, request timeouts, and related documentation/CI adjustments.

Sequence diagram for typed task creation and middleware validation

sequenceDiagram
    participant Client
    participant TaskRuns
    participant MiddlewareHandler
    participant TES
    participant Database
    Client->>TaskRuns: create_task()
    alt missing request body
        TaskRuns-->>Client: BadRequest
    else body present
        TaskRuns->>MiddlewareHandler: apply_middlewares()
        alt middleware removes body
            MiddlewareHandler-->>TaskRuns: MiddlewareException
        else body remains
            TaskRuns->>Database: _write_doc_to_db()
            TaskRuns->>TES: create_task()
            TES-->>TaskRuns: remote_task_id
            TaskRuns->>Database: _update_doc_in_db()
        end
    end
Loading

Flow diagram for project-specific anti-pattern checks

flowchart TD
    Python[Python source] --> AstGrep[ast-grep scan]
    AstGrep --> ConfigRule[FOCA config attribute access]
    AstGrep --> PydanticRule[Pydantic v1 dict call]
    AstGrep --> StatusRule[String HTTP status code]
    Python --> Semgrep[Semgrep scan]
    Config[Configuration files] --> Semgrep
    Semgrep --> FlaskRule[Flask debug mode]
    Semgrep --> JwtRule[Unverified JWT decode]
Loading

File-Level Changes

Change Details Files
Replace the previous linting and typing setup with the shared Ruff, mypy, and pre-commit standard.
  • Configure Ruff with shared rules, Google docstrings, formatting, import sorting, and scoped exclusions.
  • Configure strict mypy checks with dependency-specific missing-type-information overrides.
  • Remove Flake8, Pylint, their configuration files, and legacy suppression comments.
  • Update development documentation to describe the pre-commit workflow.
pyproject.toml
docs/development.md
.flake8
pylintrc
.git-blame-ignore-revs
Add layered automated quality, security, and anti-pattern checks to the developer and CI workflows.
  • Pin pre-commit-hooks, Ruff, Semgrep, Gitleaks, actionlint, ast-grep, and mypy hooks.
  • Add Semgrep rules for Flask debug mode and unverified JWT decoding.
  • Add ast-grep rules and tests for untyped FOCA configuration access, Pydantic v1 .dict(), and string HTTP status codes.
  • Run all checks, full secret scanning, distribution builds, and wheel validation in a consolidated static-analysis CI job.
.pre-commit-config.yaml
.semgrep/pro-tes.yml
.ast-grep/rules/foca-config-attribute.yml
.ast-grep/rules/pydantic-v1-dict.yml
.ast-grep/rules/string-status-code.yml
.ast-grep/rule-tests/foca-config-attribute-test.yml
.ast-grep/rule-tests/pydantic-v1-dict-test.yml
.ast-grep/rule-tests/string-status-code-test.yml
sgconfig.yml
.github/workflows/checks.yaml
Strengthen CI reproducibility, security, and execution controls.
  • Pin GitHub Actions to commit SHAs and disable checkout credential persistence.
  • Add concurrency cancellation for superseded pull-request runs, job timeouts, dependency caching, and non-failing test matrices.
  • Quote the GitHub environment-file assignment and include the static-analysis job in publishing dependencies.
.github/workflows/checks.yaml
Bring application, models, utilities, and tests into compliance with the new typing and linting rules while preserving behavior.
  • Add complete annotations, modernize generic and optional type syntax, mark class-level state with ClassVar, and add required Google-style docstrings.
  • Replace eager f-string logging with lazy logging arguments and correct the get_task identifier annotation/default bug.
  • Remove inline third-party typing ignores in favor of mypy module overrides.
  • Add explicit application errors where assertions previously guarded missing request bodies, logs, metadata, or forwards.
  • Add timeouts and annotations to integration tests and improve typed test fixtures.
pro_tes/app.py
pro_tes/config_models.py
pro_tes/exceptions.py
pro_tes/ga4gh/tes/models.py
pro_tes/ga4gh/tes/server.py
pro_tes/ga4gh/tes/states.py
pro_tes/ga4gh/tes/task_runs.py
pro_tes/gunicorn_config.py
pro_tes/middleware/abstract_middleware.py
pro_tes/middleware/middleware_handler.py
pro_tes/plugins/middlewares/task_distribution/base.py
pro_tes/plugins/middlewares/task_distribution/distance.py
pro_tes/plugins/middlewares/task_distribution/random.py
pro_tes/tasks/track_task_progress.py
pro_tes/utils/db.py
pro_tes/utils/misc.py
pro_tes/utils/models.py
tests/__init__.py
tests/conftest.py
tests/gunicorn_settings.py
tests/test_app.py
tests/test_gunicorn_config.py
tests/test_integration/test_endpoints.py
tests/test_models.py
tests/test_tasks.py
tests/test_track_task_progress.py
Align documentation validation and publication with the new shared tooling.
  • Exclude MkDocs' custom !ENV syntax from generic YAML validation while type-checking documentation hooks.
  • Make the publish workflow depend on the documentation job and add the final SVG newline.
mkdocs.yml
docs/hooks.py
docs/images/overview.svg
.github/workflows/checks.yaml

Assessment against linked issues

Issue Objective Addressed Explanation
#206 Adopt the shared Ruff rules, formatting, and Google docstring convention, and record the reformatting in the blame-ignore file. ✅
#206 Configure strict mypy checks for pro_tes, tests, and scripts, and add the requested shared pre-commit hooks and project-specific rules. ❌ The PR configures the requested mypy strictness and pre-commit hooks, but mypy's configured files are pro_tes, tests, and docs/hooks.py; scripts are not included.
#206 Run the static checks in CI and remove the legacy flake8, pylint, and black configuration. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Replace flake8 and pylint in the development docs with the pre-commit
workflow, as in cloud-registry.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg marked this pull request as ready for review October 22, 2026 19:51

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@uniqueg
uniqueg merged commit 90f88d4 into dev Oct 22, 2026
10 checks passed
@uniqueg
uniqueg deleted the style/shared-lint branch October 22, 2026 19:53
This was referenced Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

style: adopt the shared ruff, mypy and pre-commit

1 participant