Repository navigation
build: set up the plugin monorepo - #2
Conversation
Add the code of conduct, the security policy, code owners, editor settings and the ignore list from cloud-registry, adapted to a repository of plugin distributions, with the caches of a monorepo, and fill in the license's copyright line. Refs #1 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add the root `pyproject.toml`, a virtual uv workspace root for development only (never built or published), with the meta distribution and every `plugins/<group>/<subgroup>/<name>/` as members. It holds the shared configuration of ruff, mypy, pytest and coverage (100%), following cloud-registry, the dependency groups `dev`, `docs` and `release` (twine, locked), and pins the build backend for reproducible release builds. FOCA comes from its dev branch, where the plugin engine is, until 0.18.0 is released (marked with TODOs). Refs #1 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add the plugin `generic.example.noop`, a complete minimal distribution against the plugin API on FOCA's dev branch (`foca.plugins.Plugin`, entry point group `foca.plugins`): settings models, metadata with an explicit description, `request` and `route` hooks that change nothing and record annotations, PEP 420 namespace packages, unit tests and a pipeline test through FOCA's engine (100% coverage), a README and a changelog. It is the template of new plugins and is never published: it carries the `Private :: Do Not Upload` classifier, which PyPI refuses. `requires-python` is FOCA's (>=3.11). Refs #1 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add the meta distribution `foca-plugins`: no code, calendar-versioned (a release train), with extras per group (`generic`, `tes`, `wes`), `all` (stable plugins) and `experimental`. The extras stay empty until the first plugins are released; the example plugin is never published, so it is in none of them. Refs #1 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add the repository's scripts, run as `python -m scripts.<name>`, each command used by a workflow or hook (named in the module docs): - `packages`: discovery of the packages, CI's change detection (`changed`, without rename detection, so that moves affect both packages) and mypy with the plugins' `src/` on the search path; - `checks`: the package conventions (`check`) and built wheels (`dist`); - `release`: the package of a release tag, refusing other versions and the example plugin, and its notes from the changelog; - `new_plugin`: copies the example plugin to a new group, subgroup and name. Add their tests, at 100% coverage. Refs #1 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add the pre-commit hooks of cloud-registry (pre-commit-hooks, ruff, semgrep, gitleaks, actionlint, ast-grep with rule tests, mypy) and a hook for the package conventions. Add the ast-grep rule `no-framework-imports`, which refuses imports of Flask, Werkzeug, Connexion, Starlette and `foca.plugins.adapter` in the plugins' code, with tests; keep cloud-registry's `pydantic-v1-dict`. Add semgrep rules for unverified tokens and disabled TLS verification, and the Sourcery configuration. Refs #1 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add READMEs to `plugins/` and to the groups `generic`, `tes` and `wes`: groups follow the gateway API, subgroups the function (routing, policy, data, identity, example). Refs #1 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Replace the generated README with one in the structure of cloud-registry's: badges, what the repository is and how it relates to FOCA, proTES and proWES, its status, installation, layout and naming conventions, and contributing, with sections that the docs include. Add CONTRIBUTING.md, MAINTAINERS.md (repository settings, done and open setup tasks; not part of the published docs) and CITATION.cff, without a version, as every distribution has its own. Refs #1 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add the documentation, set up as in cloud-registry (MkDocs with Material, strict builds, Read the Docs): overview, installing (meta extras, single distributions, the derived-image recipe; nothing is published yet), writing a plugin (FOCA's plugin docs for the API, plus the conventions of this repository), the plugin catalogue, contributing and releasing. A docs hook generates the catalogue from the plugins' READMEs; its tests run with those of the scripts, at 100% coverage. Read the Docs installs the `docs` dependency group with pip. Refs #1 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add `ci.yml` (`CI`), named and gated as in cloud-registry and FOCA: - `changes` maps the changed files to the affected plugins; - `lint` runs pre-commit (incl. mypy of all packages and the package conventions), gitleaks and cffconvert, and builds and checks all distributions, with `uv.lock` checked to be up to date; - `test` runs per affected plugin, on FOCA's lowest and highest declared Python (3.11, 3.15) and the default 3.13, with FOCA dev: ruff, ast-grep, mypy, pytest at 100% coverage (uploaded to Codecov with the distribution name as the flag) and pip-audit, each plugin installed alone; - `scripts` tests the scripts and docs hooks; `docs` builds the docs; - `passed` (`CI passed`) is the gate, which allows only the skip of `test` when no plugin is affected. uv comes from `astral-sh/setup-uv`, pinned by commit. No `paths:` filters. Add `codecov.yml` with 100% targets and carried forward flags. Refs #1 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add `release.yml` (`Release`) as an untested draft, marked as such: a tag `<distribution>-v<version>` releases that package, in a run of its own (concurrency per tag). Before anything is built, it checks the tag against the package's version and refuses the example plugin, then that the commit is on `main`. It builds with pinned tools (setup-uv by commit, the pinned build backend, twine from `uv.lock`), attests the build provenance, publishes to PyPI with trusted publishing from the `pypi` environment and PEP 740 attestations (as in FOCA), and creates the GitHub release from the package's changelog. `## Commits` holds GitHub's notes since the package's own previous tag or, on a first release, the commits of the package's directory. The build uses the commit's time as `SOURCE_DATE_EPOCH`, which makes the wheels reproducible; sdists of the build backend are not, so only "Re-run failed jobs" may complete a partial release (documented). The previous tag is the package's newest among the tag's ancestors; only a missing GitHub release counts as none, other errors fail. It needs a dry run in a fork before the first release. Refs #1 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Update the uv workspace (`uv.lock` and all `pyproject.toml` files), the actions and the pre-commit hooks monthly, against `dev`, grouped as in cloud-registry. FOCA is left out while it comes from its dev branch. Refs #1 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideSets up the complete foca-plugins monorepo: a uv-managed workspace with a template plugin and meta distribution, convention and release tooling, comprehensive CI/security automation, documentation, and operational policy files. Review the package-discovery and validation rules first, then the isolated CI matrix and draft release workflow, with particular attention to tag handling, artifact reproducibility, trusted publishing prerequisites, and the documented FOCA 0.18.0 transition. Sequence diagram for the per-package release workflowsequenceDiagram
participant Maintainer
participant GitHub as GitHub Actions
participant Validator as scripts.release
participant Builder as uv and setuptools
participant Attestor as Attestation service
participant PyPI
participant Release as GitHub Release
Maintainer->>GitHub: Push <distribution>-v<version> tag
GitHub->>Validator: release TAG
Validator-->>GitHub: Package, version and path
GitHub->>Validator: checks check and notes TAG
GitHub->>Builder: uv build --package NAME
Builder-->>GitHub: Wheel and sdist
GitHub->>Attestor: Attest build provenance
Attestor-->>GitHub: Provenance attestation
GitHub->>PyPI: Publish distributions with trusted publishing
PyPI-->>GitHub: PEP 740 attestations
GitHub->>Release: Create draft release and upload distributions
GitHub->>Release: Publish release
Flow diagram for affected-plugin CI testingflowchart TD
Changes["scripts.packages changed"] --> Affected["Affected plugin matrix"]
Affected --> Lint["Lint and build distributions"]
Affected --> Test["Test each plugin"]
Test --> Matrix["Python 3.11 / 3.13 / 3.15\nFOCA dev"]
Lint --> Gate["CI passed"]
Test --> Gate
Scripts["Test scripts"] --> Gate
Docs["Build docs"] --> Gate
Lint --> Gate
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. Thanks for integrating Codecov - We've got you covered ☂️ |
There was a problem hiding this comment.
Hey - I've found 1 security issue, and 12 other issues
Security issues:
- Detected subprocess function 'run' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'. (link)
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="scripts/checks.py" line_range="158" />
<code_context>
+ if PRIVATE_CLASSIFIER in project.get("classifiers", []):
+ problems.append(f"[{extra}] {plugin.name} is never published")
+ listed.setdefault(plugin.name, set()).add(extra)
+ for name, names in listed.items():
+ group, subgroup, _ = projects[name][0].parts
+ for extra in (group, f"{group}-{subgroup}"):
</code_context>
<issue_to_address>
**Omitted plugins pass meta checks**
When a publishable plugin is absent from every optional-dependency list, `_check_meta` iterates only over plugins already in `listed`, so it never checks the omitted plugin in `projects` and `scripts.checks check` passes; users installing its group or `[all]` do not receive it.
Validate every non-private plugin in `projects` and require it in its group extras and exactly one of `[all]` or `[experimental]`.
</issue_to_address>
### Comment 2
<location path="scripts/checks.py" line_range="232-233" />
<code_context>
+ problems.append(f"{wheel.name}: no package of this repository")
+ continue
+ current = package_version(package, root)
+ if version != current:
+ problems.append(f"{wheel.name}: version is not {current!r}")
+ info = f"{name}-{version}.dist-info/"
+ module = (
</code_context>
<issue_to_address>
**Prerelease wheels fail release checks**
When a package uses a valid hyphenated prerelease version, `check_dist` compares the normalized wheel filename version with the raw project version, so CI and release builds reject the wheel; the release workflow also looks for a wheel using the raw version.
Use the normalized version consistently when validating wheel filenames and locating release artifacts.
Also at `.github/workflows/release.yml:81`, `.github/workflows/release.yml:124`, `.github/workflows/release.yml:258-259`.
</issue_to_address>
### Comment 3
<location path=".github/workflows/release.yml" line_range="258" />
<code_context>
+ # `--match` takes globs: check the tag exactly (names have no
+ # parts like `-v<digit>`, so other packages' tags don't match)
+ if [[ -n "${previous}" ]] \
+ && ! grep -qE "^${NAME}-v[0-9][^-]*$" <<< "${previous}"; then
+ echo "::error::Unexpected previous tag ${previous}"
+ exit 1
</code_context>
<issue_to_address>
**Prerelease tags block release completion**
When the newest ancestor tag for the package is a SemVer prerelease, such as `foca-plugin-example-v1.0.0-rc.1`, the `grep` check rejects a valid SemVer prerelease tag such as `-rc.1`, so the release job exits after PyPI has accepted the distribution and leaves the GitHub release unfinished.
Validate previous tags with a pattern that accepts valid prerelease versions, or use a version parser instead of excluding hyphens.
</issue_to_address>
### Comment 4
<location path=".github/workflows/release.yml" line_range="55" />
<code_context>
+ outputs:
+ packages: ${{ steps.detect.outputs.packages }}
+ steps:
+ - name: Check out repository
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
</code_context>
<issue_to_address>
**Release artifacts use different commits**
When the tag is moved to another main commit while a release run is between build and publish, `build` validates and packages the original tag target, but the later `publish` checkout resolves the tag again and reads its new target for release notes. `--verify-tag` checks only that the tag exists, so GitHub can publish the original distributions with notes for the new commit.
Pin both checkouts and tag-based Git operations to the event commit, and fail before publishing if the tag no longer points to it.
Also at `.github/workflows/release.yml:198`.
</issue_to_address>
### Comment 5
<location path=".github/workflows/release.yml" line_range="188" />
<code_context>
+ attestations: true
+ # PyPI files are immutable; skip those already uploaded, so that
+ # re-running a partially failed upload completes the release
+ skip-existing: true
+
+ publish:
</code_context>
<issue_to_address>
**Moved tags leave stale release artifacts**
When an existing release tag is force-updated to another `main` commit that retains the same package version, the release job skips existing PyPI files, then exits when it finds an already-published GitHub release. If a release tag is moved to a different `main` commit with the same package version, the tag points at the new code while PyPI and the GitHub release retain the old artifacts.
Protect release tags from updates and fail a run if an existing published release does not match the tagged commit and its artifacts.
Also at `.github/workflows/release.yml:246-248`.
</issue_to_address>
### Comment 6
<location path="scripts/checks.py" line_range="164" />
<code_context>
+ if extra not in names:
+ problems.append(f"{name} is missing in [{extra}]")
+ if len(names & {"all", "experimental"}) != 1:
+ problems.append(f"{name} must be in exactly one of [all], [experimental]")
+ return problems
+
</code_context>
<issue_to_address>
**Maturity mismatches pass checks**
When a plugin's pin is in the extra that does not match its declared maturity, `_check_meta` checks only that a listed plugin appears in exactly one of `[all]` or `[experimental]`; it does not compare that extra with the plugin's maturity, so users receive the wrong plugin set.
Have `_check_meta` verify that each plugin's `[all]` or `[experimental]` placement matches its declared maturity.
</issue_to_address>
### Comment 7
<location path="scripts/checks.py" line_range="91" />
<code_context>
+ f"{namespace.relative_to(root)} must be a namespace package"
+ " (no __init__.py)"
+ )
+ for required in ("README.md", "CHANGELOG.md", "tests"):
+ if not (directory / required).exists():
+ problems.append(f"{required} is missing")
</code_context>
<issue_to_address>
**Typed plugins lack their marker**
When a plugin's `py.typed` marker is missing from its source or built wheel, `check` and `check_dist` accept the plugin without `py.typed`, so it can be published with `Typing :: Typed` while downstream type checkers treat its inline types as unavailable.
Require `py.typed` in the plugin source and in the built wheel.
Also at `scripts/checks.py:251`.
</issue_to_address>
### Comment 8
<location path="scripts/release.py" line_range="76-81" />
<code_context>
+ package = release(tag, root)
+ text = (root / package["path"] / "CHANGELOG.md").read_text()
+ heading = re.compile(rf"^## {re.escape(package['version'])}(\s.*)?$", re.M)
+ match = heading.search(text)
+ if match is None:
+ raise ValueError(
+ f"{package['path']}/CHANGELOG.md has no section '## {package['version']}'"
+ )
+ following = re.compile(r"^## ", re.M).search(text, match.end())
+ body = text[match.end() : following.start() if following else None].strip()
+ if not body:
</code_context>
<issue_to_address>
**Duplicate versions hide release notes**
When a package changelog contains two `## <version>` headings for the release version, `heading.search` selects the first matching version section and `notes` stops at the next level-two heading. The release workflow publishes only that section, silently omitting content in a second section with the same version.
Reject changelogs with more than one matching version heading before returning release notes.
</issue_to_address>
### Comment 9
<location path="scripts/new_plugin.py" line_range="209" />
<code_context>
+ target = root / new["directory"]
+ if target.exists():
+ raise FileExistsError(f"{new['directory']} exists")
+ shutil.copytree(root / old["directory"], target, ignore=IGNORED)
+ src = target / "src"
+ shutil.rmtree(src / "foca_plugins")
</code_context>
<issue_to_address>
**Failed generation blocks retries**
When generation stops or a filesystem error occurs after package creation starts, `create` writes directly into the final target, leaving partial files behind; the next call rejects the existing target, so the caller must remove it manually before retrying.
Build the package in a temporary directory and move it to the final target only after generation succeeds.
</issue_to_address>
### Comment 10
<location path="docs/hooks.py" line_range="82" />
<code_context>
+ """
+ rows = []
+ for package in packages.plugins(packages.discover(root)):
+ project = packages.load_pyproject(root / package.path / "pyproject.toml")
+ published = packages.PRIVATE_CLASSIFIER not in project["project"].get(
+ "classifiers", []
</code_context>
<issue_to_address>
**Unreleased plugins appear published**
When a generated plugin has not yet had a release, `catalogue` treats the absence of `Private :: Do Not Upload` as proof of publication, so it marks the plugin as available before its distribution exists.
Determine publication status from release availability rather than the absence of the private classifier.
Also at `docs/hooks.py:83-85`.
</issue_to_address>
### Comment 11
<location path="tests/test_packages.py" line_range="164" />
<code_context>
+ monkeypatch: Patches.
+ """
+ monkeypatch.setattr(packages, "changed_files", lambda *_: ["docs/index.md"])
+ assert packages.main(["changed", "a", "b"], repo) == 0
+
+
</code_context>
<issue_to_address>
**Wrong plugin selection passes test**
When `packages.main` prints a matrix that selects the wrong plugins, `test_main_changed` checks only the zero exit status, so it passes without verifying the printed selection.
Capture and assert the expected output, including `[]` for the docs-only change.
</issue_to_address>
### Comment 12
<location path="tests/test_packages.py" line_range="174" />
<code_context>
+ repo: Repository root.
+ monkeypatch: Patches.
+ """
+ monkeypatch.setattr(packages, "mypy", lambda paths, root: len(paths))
+ assert packages.main(["mypy", "a", "b"], repo) == 2
</code_context>
<issue_to_address>
**Mypy invocation can go unchecked**
When the mypy command returns the path count instead of invoking mypy, when `packages.main` returns the number of requested paths without invoking mypy, `test_main_mypy` still passes: its mock returns `len(paths)`, which is also 2 for the two supplied paths. Use a distinct mock exit code and assert the mock was called with the expected arguments.
Have the mock return a value distinct from the path count and assert it was called with the paths and root.
</issue_to_address>
### Comment 13
<location path="scripts/packages.py" line_range="255-257" />
<code_context>
return subprocess.run(
[sys.executable, "-m", "mypy", *targets], cwd=root, env=env, check=False
).returncode
</code_context>
<issue_to_address>
**security (python.lang.security.audit.dangerous-subprocess-use-audit):** Detected subprocess function 'run' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'.
*Source: opengrep*
</issue_to_address>Sourcery assessment
Needs a human reviewer. 13 findings to address first, and a mistake in the release workflow could publish incorrect distributions to PyPI; those files and published releases cannot be fully undone by reverting this PR. Reverting would stop future runs, but any artifacts already published would remain.
Blocking findings: scripts/checks.py:158, scripts/checks.py:233, .github/workflows/release.yml:258, .github/workflows/release.yml:55, .github/workflows/release.yml:188, and 8 more
Check the meta distribution's extras for every plugin that may be published and is released (has a version section in its changelog) or listed, not only for listed ones: it must be in its group's and subgroup's extras, and in `[all]` or `[experimental]` according to the `maturity` of its class (read from the code). Pins must name released versions. Require normalized PEP 440 versions (no epoch or local part), so that versions, wheel names and release tags agree, and `py.typed` in each plugin's module and wheel. Refs #1 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Check out and use the pushed commit (`github.sha`) instead of the tag, and fail before publishing to PyPI and before creating the GitHub release if the tag no longer points to it. Fail if a published release exists whose assets differ from the built distributions. Find the previous tag with `python -m scripts.release previous`, which checks the found tag exactly (normalized PEP 440 versions, pre-releases included), and refuse changelogs with several sections of the released version. Mark post releases of pre-releases as GitHub pre-releases. Document the tag ruleset that the maintainer must add. Refs #1 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build the new package in a temporary directory next to the plugins and move it into place, so that a failure leaves nothing behind. Refs #1 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Replace the column "Published", which called unreleased plugins published, with "Latest release": the topmost version section of the plugin's changelog, "not yet released" without one, and "never" for the example. No network lookups at build time. Refs #1 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Assert the printed matrix of `changed`, including `[]`, and that the `mypy` command passes its arguments and returns mypy's status. Refs #1 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sourcery's opengrep check blocks on the subprocess audit rule. The arguments are lists built from repository data and no shell is involved, so suppress the rule inline with that reason. Refs #1 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
This PR sets up the
foca-pluginsmonorepo, following cloud-registry's conventions adapted to a monorepo of plugin packages.plugins/<group>/<subgroup>/<name>/with one distribution per plugin, namedfoca-plugin-<group>-<subgroup>-<name>. Thefoca_plugins.*packages are PEP 420 namespace packages.meta/holds thefoca-pluginsmeta distribution. It is calendar-versioned and has extras per group; the extras stay empty until the first plugins are released.generic.example.noopis a copyable template. It is never published: it has thePrivate :: Do Not Uploadclassifier, belongs to no extra, and the release workflow refuses its tags.scripts/new_plugin.pycreates new plugins from it.scripts.packages,scripts.checks,scripts.release):--no-renames) and the package matrix;-v<digit>name parts);ci.yml):dev, Codecov per package flag), Test scripts, Docs.CI passedallows only the skip of Test when no plugin changed.release.yml):<distribution>-v<version>, with one concurrency group per tag.main.SOURCE_DATE_EPOCH. twine comes from a locked group.pypienvironment, with attestations. The release starts as a draft and is published last..gitignore,.editorconfig. Maintainer setup notes are inMAINTAINERS.md, kept out of the public docs.FOCA is installed from its
devbranch until v0.18.0, the plugin engine, is released. The places to change are markedTODO(FOCA 0.18.0).Closes #1
Verification
Run locally on the final tree:
uv sync, with FOCAdevinstalled from git: pass.pre-commit run --all-files(ruff, mypy, actionlint and shellcheck, semgrep, ast-grep, gitleaks, package conventions): pass.pytest: 55 script tests and 13 plugin tests pass, with 100% branch coverage.mkdocs build --strictanduv lock --check: pass.uv build --all-packagesand the dist checks: pass.new_plugin.py tes routing distancepassed its checks and tests. The generated plugin was then removed.Review: two rounds of adversarial and quality review. Fixed:
-v<digit>names;requires-pythonwording;CI (first run): all 12 checks pass. That covers
CI passed, Changes, Lint, Test on Python 3.11, 3.13 and 3.15 against FOCAdev, Test scripts, Docs, and Codecov patch and project per package.Sourcery: 13 findings. 12 were fixed in the commits on top of c028e9a; one, the subprocess audit rule, is suppressed inline with a reason in 211d24f. After that, CI is all green again, including the
Sourcery reviewcheck.Declined review findings
SOURCE_DATE_EPOCH, so sdists of the same commit still differ. This is harmless as long as only failed jobs are re-run, which the docs and the workflow comment require. Fully reproducible sdists would need another build backend, e.g. hatchling or uv_build. That can be a follow-up if wanted.🤖 Generated with Claude Code