Repository navigation
ci: add lint, type checks and pyproject.toml - #73
Conversation
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]>
Reviewer's GuideAPIReview the OpenAPI specification edits as changes to the public API contract; they primarily remove trailing whitespace.
ImplementationReview the shared FOCA settings and collection accessors together with the application and endpoint refactors that depend on them.
Review the updater's importable reporting loop and its handling of incomplete pods, request failures, and HTTP error responses.
ConfigurationReview project metadata, dependency groups, lint and type-check settings, and coverage configuration as the foundation for the new tooling.
Review the image dependency installation from the lock and its base-image compatibility assumptions.
Review the CI, documentation-host, and Dependabot changes that install and enforce the new tooling and dependency workflow.
Review the pre-commit hook set, local lint target, and related repository and Helm build exclusions.
DocumentationReview the development guide's tooling, lint, CI, and release-version instructions alongside the deployment description of updater behavior.
Review the SVG asset's formatting change.
TestsReview the updater, build-path regression, and image-lock consistency tests with the test helpers and fixtures they rely on.
Review the expanded type annotations, fixtures, and behavior assertions across the application and script tests.
Lock files and vendored codeReview the resolved dependency lock after evaluating the project dependency declarations and image installation.
Review the recorded formatting commit and updater-requirements newline cleanup as repository-maintenance artifacts.
Review the removed legacy package marker and packaging files as the recorded removal of the previous packaging setup.
Other changesFiles not grouped.
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 #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. 🚀 New features to boost your workflow:
|
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]>
There was a problem hiding this comment.
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
- 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]>
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.pyproject.tomlreplacessetup.py,setup.cfgandrequirements.txt. It holds the runtime dependencies and the dependency groupsdevanddocs, anduv.lockpins 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 thedocsgroup. Dependabot gets the uv ecosystem and pre-commit.disallow_untyped_defs,disallow_any_generics), gitleaks (staged changes; CI also scans all files), actionlint and the standard file hooks. TheLintjob runs them, checks that the lock matches, and keeps the citation check; it is part of the gateCI passed.make lintruns the same hooks locally.pubgrade/settings.py, which uses FOCA 0.21'sget_collection().yaml.safe_load, timeouts on outgoing requests (GitHub dispatch, updater), %-style logging, andraise ... from None.report_build(),report_builds()andmain(), 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 readsBROKER_PORT, which it never used; the chart doesn't set it.tests/helpers.py.coverage.xml), still at 100%.docs/development.mdcovers uv, the Lint section and CI.docs/deployment.mddescribes what the updater does.Closes #38
Verification
pytest --cov: 484 passed, 100% coverage (app, scripts, updater).ruff check,ruff format --checkandmypy: clean.pre-commit run --all-files: all hooks passed, including the manual-stagegitleaks-all(no findings).uv lock --check: OK.mkdocs build --strict: OK.docker buildof both images works.import pubgrade.appworks and FOCA is 0.21.0.docs/hooks.py; Lint andmake lintnow install all groups.create_dockerhub_config_filethat depends on the build identifier.create_build()now checks that the build's directory is insideBASE_DIRbefore it clones or writes anything (regression testtest_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:
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_URLonce, and a fixture that returned viayield.Sourcery (6 threads):
.and/(it compares absolute paths); the updater logs error responses as failed reports (raise_for_status());make lintalso runsgitleaks-all.uv rundrops 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 rundrops the docs group (Sourcery). It doesn't:uv runsyncs inexactly, which I verified locally.pubgrade.__version__(Sourcery). Pubgrade is a service and isn't installed as a package;pyproject.tomlis the only source of the version.Pytest options appear in three places (CI, Makefile, docs; low). They differ on purpose: CI and
make testalso writecoverage.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