Skip to content

ci: add lint, type checks and pyproject.toml - #73

Merged
uniqueg merged 11 commits into
devfrom
ci/lint-pyproject
Nov 7, 2026
Merged

uniqueg merged 11 commits into
devfrom
ci/lint-pyproject

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Summary

Brings Pubgrade's tooling in line with cloud-registry and proTES. The reformat landed separately in #72 and is listed in .git-blame-ignore-revs.

  • Packaging: pyproject.toml replaces setup.py, setup.cfg and requirements.txt. It holds the runtime dependencies and the dependency groups dev and docs, and uv.lock pins them. The app keeps running from its source directory (package = false). The image installs the locked runtime dependencies with hashes, wheels only (uv export + uv pip install --require-hashes). Read the Docs installs the docs group. Dependabot gets the uv ecosystem and pre-commit.
  • Lint: pre-commit runs ruff (lint + format), mypy (complete hints: disallow_untyped_defs, disallow_any_generics), gitleaks (staged changes; CI also scans all files), actionlint and the standard file hooks. The Lint job runs them, checks that the lock matches, and keeps the citation check; it is part of the gate CI passed. make lint runs the same hooks locally.
  • Code:
    • Complete type hints and Google-style docstrings across the app, the updater, the scripts and the tests.
    • Collections and endpoint settings are read through the new pubgrade/settings.py, which uses FOCA 0.21's get_collection().
    • Ruff fixes: yaml.safe_load, timeouts on outgoing requests (GitHub dispatch, updater), %-style logging, and raise ... from None.
  • Updater: the loop is split into report_build(), report_builds() and main(), so that it can be imported and tested. Its behaviour is unchanged, except that pods without spec or status are skipped and failed reports are logged instead of ending the process. It's now tested and under coverage. It no longer reads BROKER_PORT, which it never used; the chart doesn't set it.
  • Tests:
    • Shared helpers live in tests/helpers.py.
    • Coverage goes to Codecov (coverage.xml), still at 100%.
  • Docs:
    • docs/development.md covers uv, the Lint section and CI.
    • docs/deployment.md describes what the updater does.

Closes #38

Verification

  • Tests: pytest --cov: 484 passed, 100% coverage (app, scripts, updater).
  • Lint:
    • ruff check, ruff format --check and mypy: clean.
    • pre-commit run --all-files: all hooks passed, including the manual-stage gitleaks-all (no findings).
    • actionlint wasn't run locally because the sandbox couldn't download its Go toolchain. The adversarial reviewer ran actionlint with shellcheck on all workflows, and it passed.
  • Lock: uv lock --check: OK.
  • Docs: mkdocs build --strict: OK.
  • Images:
    • docker build of both images works.
    • In the app image, import pubgrade.app works and FOCA is 0.21.0.
    • In the updater image, the module imports.
  • Not run locally: the smoke, chart and upgrade tests (they need a cluster or a running stack). CI runs them.
  • CI: all checks pass on the second run, including CodeQL and Codecov.
    • First run: Lint failed because mypy lacked the docs group (MkDocs) for docs/hooks.py; Lint and make lint now install all groups.
    • CodeQL: it flagged a path in create_dockerhub_config_file that depends on the build identifier. create_build() now checks that the build's directory is inside BASE_DIR before it clones or writes anything (regression test test_create_build_outside_base_dir). Build identifiers are generated, so valid builds are unaffected.

Review

Full review: adversarial and quality reviewers, two rounds.

  • Round 1:

    • The adversarial reviewer found fixes left uncommitted at the time (whitespace, gitleaks markers for the fake test token). They were committed.
    • The quality reviewer found duplicated test helpers and an untested updater. Both are fixed.
    • Low findings fixed: a separate uv cache for the docs job, the docs build command, and re-wrapped lines.
  • Round 2: no high findings. The CodeQL fix came after round 2; I reviewed it myself, since the review allows at most two rounds.

  • Round 2 fixes: Fixed: the wording of the updater's timeout in the docs, reading BROKER_URL once, and a fixture that returned via yield.

  • Sourcery (6 threads):

    • Fixed: the base-directory check now accepts . and / (it compares absolute paths); the updater logs error responses as failed reports (raise_for_status()); make lint also runs gitleaks-all.
    • Declined (see below): an overall deadline for updater requests; the claim that uv run drops the docs group; pubgrade.__version__.
  • CI: all checks pass on a41b1d9, including CodeQL, Codecov and Sourcery.

Declined review findings

  • Overall deadline for updater requests (Sourcery). The updater only talks to its own Pubgrade; the per-connect and per-read timeouts are as before this PR.

  • uv run drops the docs group (Sourcery). It doesn't: uv run syncs inexactly, which I verified locally.

  • pubgrade.__version__ (Sourcery). Pubgrade is a service and isn't installed as a package; pyproject.toml is the only source of the version.

  • Pytest options appear in three places (CI, Makefile, docs; low). They differ on purpose: CI and make test also write coverage.xml, while the docs show the shortest command.

  • The Dockerfile's uv version is separate from the lock's (low). The Dockerfile pins uv by digest and Dependabot updates it, and both versions read the same lock format. Not worth a check for now.

Open questions

None.

🤖 Generated with Claude Code

uniqueg and others added 8 commits November 7, 2026 06:43
Replace setup.py, setup.cfg and requirements.txt by pyproject.toml, with
the runtime dependencies and the dependency groups dev and docs, locked
in uv.lock. The image installs the locked runtime dependencies, hash-
checked; CI's test and docs jobs install from the lock with uv, Read the
Docs from the ranges. The version moves to [project] of pyproject.toml,
which check_versions.py reads; Dependabot updates the uv ecosystem and
pre-commit hooks.

Refs #38

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Configure ruff (the rule set of FOCA apps, Google-style docstrings) and
mypy (complete type hints) in pyproject.toml, and run them with
gitleaks, actionlint and file checks as pre-commit hooks, in the Lint
job of CI, which also checks the lock.

Refs #38

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Apply ruff's fixes for the new rules (builtin generics, typing imports,
combined with statements, simplifications) and annotate the mock data
of the tests, whose duplicate first MOCK_REPOSITORY_1 was never used.

Refs #38

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Annotate all functions of the app, the updater and the tests for
mypy's strict settings, add the missing module docstrings, and
access the database collections and endpoint settings through
pubgrade/settings.py, on FOCA's get_collection(). Requests to GitHub
and to Pubgrade from the updater get timeouts, and YAML files are
read with yaml.safe_load. Document the lint setup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
List the squash commit of the ruff reformat (#72) in
.git-blame-ignore-revs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Move the FOCA helpers that test modules had copied into
tests/helpers.py. Split the updater's loop into report_build(),
report_builds() and main(), so that it can be imported and tested,
measure its coverage, and document what it does. Mark the fake
Docker Hub token of the tests for gitleaks, let pre-commit fix
trailing whitespace and file endings, and re-wrap long lines.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The docs job installs the docs group only; with the cache key of the
lint and test jobs, it could save a cache without the dev
dependencies for them. Fix the docs build command, as uv run syncs
the default groups otherwise.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Read BROKER_URL once, return the updater fixture instead of yielding
it, and describe the updater's timeouts accurately. The updater no
longer reads BROKER_PORT, which it never used.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Review the OpenAPI specification edits as changes to the public API contract; they primarily remove trailing whitespace.

  • pubgrade/api/pubgrade.yaml L6-10, L236-241, L1116-1121 (+25 small edits)

Implementation

Review the shared FOCA settings and collection accessors together with the application and endpoint refactors that depend on them.

  • pubgrade/app.py L12-15, L66-69 (+2 small edits)
  • pubgrade/charsets.py L31, L238
  • pubgrade/errors/exceptions.py L1-2
  • pubgrade/gunicorn_config.py L11
  • pubgrade/modules/__init__.py L1
  • pubgrade/modules/endpoints/builds.py L303-317, L468-480, L618-636 (+39 small edits)
  • pubgrade/modules/endpoints/repositories.py L47-57, L76-86, L166-172 (+12 small edits)
  • pubgrade/modules/endpoints/subscriptions.py L1-6, L65-71, L400-408 (+20 small edits)
  • pubgrade/modules/endpoints/users.py L1-4, L46-56, L76-86 (+14 small edits)
  • pubgrade/modules/server.py L36-41, L101-105, L221-225 (+16 small edits)
  • pubgrade/settings.py L1-38
  • pubgrade/timestamps.py L17-166 (9 small edits)

Review the updater's importable reporting loop and its handling of incomplete pods, request failures, and HTTP error responses.

  • build-complete-updater/updater.py L1-14, L19-104

Configuration

Review project metadata, dependency groups, lint and type-check settings, and coverage configuration as the foundation for the new tooling.

  • pyproject.toml L1-163

Review the image dependency installation from the lock and its base-image compatibility assumptions.

  • Dockerfile L2-5, L10-12, L35-51
  • build-complete-updater/Dockerfile L6, L25
  • build-complete-updater/requirements.txt L2 (removed lines)

Review the CI, documentation-host, and Dependabot changes that install and enforce the new tooling and dependency workflow.

  • .github/dependabot.yml L13-30, L64-72 (+2 small edits)
  • .github/workflows/ci.yml L2-12, L75-100, L117-132 (+5 small edits)
  • .readthedocs.yaml L9-18, L29 (removed lines)

Review the pre-commit hook set, local lint target, and related repository and Helm build exclusions.

  • .dockerignore L6-7
  • .pre-commit-config.yaml L1-49
  • Makefile L19-26
  • helm/.helmignore L1 (removed lines)

Documentation

Review the development guide's tooling, lint, CI, and release-version instructions alongside the deployment description of updater behavior.

  • .github/workflows/release.yml L14
  • docs/deployment.md L97-101
  • docs/development.md L10-24, L50-79, L145-148 (+4 small edits)
  • docs/hooks.py L101
  • helm/Chart.yaml L7-8
  • pubgrade/__init__.py L1-4
  • scripts/check_versions.py L48-63, L91-94 (+3 small edits)

Review the SVG asset's formatting change.

  • docs/images/app-schema.svg L1 (removed lines)

Tests

Review the updater, build-path regression, and image-lock consistency tests with the test helpers and fixtures they rely on.

  • tests/__init__.py L1
  • tests/conftest.py L3-5, L24
  • tests/helpers.py L1-63
  • tests/pubgrade/__init__.py L1
  • tests/scripts/__init__.py L1
  • tests/test_image.py L1, L7-10, L29-54
  • tests/test_updater.py L1-219

Review the expanded type annotations, fixtures, and behavior assertions across the application and script tests.

  • tests/mock_data.py L1-19 (+16 small edits)
  • tests/pubgrade/endpoints/test_builds.py L57-175, L180-253, L646-734 (+62 small edits)
  • tests/pubgrade/endpoints/test_repositories.py L76-97, L147-163, L171-191 (+14 small edits)
  • tests/pubgrade/endpoints/test_subscriptions.py L47-115, L258-304, L401-445 (+40 small edits)
  • tests/pubgrade/endpoints/test_users.py L38-59, L101-118, L148-189 (+12 small edits)
  • tests/pubgrade/test_server.py L52-82, L267-308, L451-482 (+24 small edits)
  • tests/scripts/test_check_versions.py L21-28, L74-78, L85-97 (+4 small edits)
  • tests/test_app.py L51-54, L60-66, L89-107 (+6 small edits)
  • tests/test_charsets.py L118, L174-178, L186-188
  • tests/test_config.py L63-66 (+8 small edits)
  • tests/test_exceptions.py L4, L26, L46-50
  • tests/test_timestamps.py L68-73, L81-86, L153-161 (+6 small edits)

Lock files and vendored code

Review the resolved dependency lock after evaluating the project dependency declarations and image installation.

  • uv.lock L1-1851

Review the recorded formatting commit and updater-requirements newline cleanup as repository-maintenance artifacts.

  • .git-blame-ignore-revs L1-5

Review the removed legacy package marker and packaging files as the recorded removal of the previous packaging setup.

  • __init__.py (deleted)
  • requirements.txt (deleted)
  • setup.cfg (deleted)
  • setup.py (deleted)

Other changes

Files not grouped.

  • codecov.yml L3

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

@codecov

codecov Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (24a809e) to head (a41b1d9).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev       #73   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           16        17    +1     
  Lines         1192      1257   +65     
=========================================
+ Hits          1192      1257   +65     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@read-the-docs-community

read-the-docs-community Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 Pubgrade | 🛠️ Build #35714714 | 📁 Comparing a41b1d9 against latest (24a809e)

  🔍 Preview build  

2 files changed
± deployment/index.html
± development/index.html

uniqueg and others added 2 commits November 7, 2026 07:14
mypy checks docs/hooks.py, which imports MkDocs from the docs group,
so Lint and make lint install all groups.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
create_build() now checks that the directory of a build is inside
BASE_DIR before it clones or writes anything, and builds its file
paths from that directory. Build identifiers are generated, so this
changes nothing for valid builds; CodeQL can follow the check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg marked this pull request as ready for review November 7, 2026 06:20
@uniqueg
uniqueg requested a review from akash2237778 as a code owner November 7, 2026 06:20

@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 found 6 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="pubgrade/modules/endpoints/builds.py" line_range="311" />
<code_context>
+    # Build identifiers are generated, but keep the files of a build in
+    # `base_dir` regardless
+    build_dir = os.path.normpath(os.path.join(base_dir, build_id))
+    if not build_dir.startswith(os.path.normpath(base_dir) + os.sep):
+        logger.error("Directory of build %s is outside the base directory.", build_id)
+        raise InternalServerError
</code_context>
<issue_to_address>
**Build requests leave stuck queued records**

When the configured `BASE_DIR` is `.` or `/` (or empty), `create_build` rejects the normalized child path because the base prefix is built in a different form, so `register_builds` leaves a queued record that the caller cannot start.

Normalize the base and candidate paths consistently, then use a path-aware containment check.
</issue_to_address>

### Comment 2
<location path="build-complete-updater/updater.py" line_range="75-76" />
<code_context>
+    }
+    try:
+        requests.request(
+            "PUT", url, headers=headers, data=payload, timeout=REQUEST_TIMEOUT
+        )
+    except requests.exceptions.RequestException as error:
+        # Only the type: messages of requests can quote the headers
</code_context>
<issue_to_address>
**HTTP failures are reported as successful**

When pubgrade returns a non-2xx response, `requests.request` returns normally, so `report_build` skips its exception handler and logs no failure; the updater treats the report as successful and operators see no failure indication.

Call `raise_for_status()` on the response inside the `try` block.

Also at `docs/deployment.md:97-100`.
</issue_to_address>

### Comment 3
<location path="build-complete-updater/updater.py" line_range="75-76" />
<code_context>
+    }
+    try:
+        requests.request(
+            "PUT", url, headers=headers, data=payload, timeout=REQUEST_TIMEOUT
+        )
+    except requests.exceptions.RequestException as error:
+        # Only the type: messages of requests can quote the headers
</code_context>
<issue_to_address>
**Slow responses can stall updater**

When the response keeps producing data without an inactivity gap, the scalar Requests timeout limits connection and read inactivity, not total response duration; a server or proxy that keeps sending data can keep `report_build` blocked indefinitely, preventing `report_builds` from reporting later pods.

Use an explicit overall deadline or otherwise ensure a slow response cannot block processing indefinitely.
</issue_to_address>

### Comment 4
<location path="Makefile" line_range="25" />
<code_context>
+
+lint: ## Runs the linters, type checks and security checks of pre-commit on all files.
+	uv sync --locked --all-groups
+	uv run --locked pre-commit run --all-files

 install-pubgrade: # build ## Install pubgrade on cluster using helm (values in HELM_ARGS, see the README).
</code_context>
<issue_to_address>
**Local lint drops docs dependencies**

When a developer runs `make lint` or follows the documented manual lint command, `uv run` syncs the project using its default groups after the preceding all-groups sync, so it removes the `docs` group before running pre-commit; mypy then cannot import MkDocs from `docs/hooks.py`, and `make lint` and the documented manual lint command fail.

Run pre-commit without a resync (for example, `uv run --no-sync`) or include all groups in each `uv run`.

Also at `docs/development.md:71`, `.pre-commit-config.yaml:44`.
</issue_to_address>

### Comment 5
<location path="Makefile" line_range="25" />
<code_context>
+
+lint: ## Runs the linters, type checks and security checks of pre-commit on all files.
+	uv sync --locked --all-groups
+	uv run --locked pre-commit run --all-files

 install-pubgrade: # build ## Install pubgrade on cluster using helm (values in HELM_ARGS, see the README).
</code_context>
<issue_to_address>
**Lint skips the secret scan**

When a developer runs `make lint` with secrets outside staged changes, `pre-commit run --all-files` skips the manual-stage `gitleaks-all` hook, so those secrets are not scanned despite the target being described as running the checks used by CI.

Invoke the manual-stage `gitleaks-all` hook from the lint target.
</issue_to_address>

### Comment 6
<location path="pubgrade/__init__.py" line_range="1" />
<code_context>
-__version__ = "0.1.0"
</code_context>
<issue_to_address>
**Version imports break**

When an external consumer still imports `pubgrade.__version__`, consumers importing `pubgrade.__version__` now get an `AttributeError`: the package initializer contains only a docstring and no compatibility attribute, so callers that previously read the version from the package fail.

Keep a backwards-compatible `__version__` attribute while making `pyproject.toml` the version source.
</issue_to_address>

Linked issues

#38 ci: add lint, type checks and pyproject.toml · 6 of 7 met

# Requirement Status Notes
1 Use pyproject.toml for metadata and all dependencies instead of setup.py, setup.cfg and requirements.txt. 🟡 Partly met The app's metadata and dependencies moved to pyproject.toml and uv.lock, but the updater still has a separate requirements.txt that its Dockerfile installs with pip.
2 Add ruff, mypy, pre-commit and gitleaks, and a lint job in ci.yml. ✅ Met The pre-commit hooks include ruff, mypy, gitleaks, actionlint and file checks; CI runs them in the Lint job.
3 Use Google-style docstrings and type hints. ✅ Met Ruff's pydocstyle convention is Google, and mypy checks the app, updater, scripts, docs hook and tests with untyped definitions disallowed.
4 Send coverage reports to Codecov. ✅ Met The test job generates coverage.xml and uploads it with the Codecov action.
5 Keep FOCA where it is unless it has moved by then. ✅ Met The FOCA base image remains at 0.21.0.
6 Put reformatting in a commit of its own. ✅ Met The description says the reformat landed separately in #72, and that commit is listed in .git-blame-ignore-revs.
7 The Lint job passes and is part of the gate. ✅ Met The gate includes lint in its required jobs, and the verification notes report that CI passed.

Sourcery assessment

Approval pending. 6 findings to address first.

Blocking findings: pubgrade/modules/endpoints/builds.py:311, build-complete-updater/updater.py:76, build-complete-updater/updater.py:76, Makefile:25, Makefile:25, and 1 more


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

Comment thread pubgrade/modules/endpoints/builds.py Resolved
Comment thread build-complete-updater/updater.py Resolved
Comment thread build-complete-updater/updater.py Resolved
Comment thread Makefile Resolved
Comment thread Makefile Resolved
Comment thread pubgrade/__init__.py Resolved
- Accept every base directory in create_build(), including . and /,
  by comparing absolute paths.
- Log error responses of Pubgrade in the updater as failed reports.
- Let make lint also scan all files for secrets, as CI does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit 3107df6 into dev Nov 7, 2026
43 checks passed
@uniqueg
uniqueg deleted the ci/lint-pyproject branch November 7, 2026 06:40
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.

ci: add lint, type checks and pyproject.toml

2 participants