Skip to content

python-dependencies: a built-in extractor for Python projects - #386

Open
agorischek wants to merge 7 commits into
mainfrom
extractors/python-dependencies
Open

agorischek wants to merge 7 commits into
mainfrom
extractors/python-dependencies

Conversation

@agorischek

@agorischek agorischek commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

A new built-in extractor, python-dependencies, draws a Python project's dependency graph with the same dependencies renderer and presentation as workspace-dependencies, cargo-dependencies and nuget-dependencies (so it picks up #343's churn folding when that lands). Until now explore proposed nothing Python-specific for Python libraries and applications; the only Python built-in was django-schema.

It reads the revision's files only — no Python, no installs, no --trust:

  • Lockfiles: uv.lock (version 1), poetry.lock (lock-version 1.x and 2.x), pdm.lock (4.x), and pinned requirements files (requirements*.txt, requirements/*.txt, following -r), where name==version lines are pinned packages.
  • Projects: from pyproject.toml — PEP 621 [project] (dependencies, optional-dependencies), PEP 735 [dependency-groups] with include-group, Poetry's [tool.poetry] dependencies, groups and extras, PDM's and uv's development dependencies, and uv workspace members ([tool.uv.workspace] members/exclude). uv members' declarations come from what uv.lock recorded for them.
  • Entities: project (project:<name>) and package (package:<name>, PEP 503-normalized; versions are data, so an upgrade is one modified package; several locked copies of one name get @<line> suffixes, as workspace-dependencies does).
  • Direct vs transitive comes from the lockfile's graph. Requirements files are direct-only, except that pip-compile/uv pip compile # via annotations, where present, say what pulls each pin in.
  • Extras and markers: a project's extras and dependency groups are always included; a package's extras are followed only where something in the graph requests them (httpx[http2] adds h2). Markers are recorded on relationships as data.marker, not evaluated.
  • Limitations recorded in metadata.limitations: markers aren't evaluated (the graph covers every platform and Python version); every project extra and group is included; requirements files have no graph without # via, and unpinned lines (ranges, URLs, -e) are dropped and listed in metadata.skipped; Poetry/PDM don't say which of several copies of a name a dependency uses, so it points at each; without a lockfile, declarations keep their ranges with no resolution.

explore proposes it as python-dependencies when the root has a pyproject.toml, lockfile or requirements files, mirroring the cargo and npm candidates; when Python projects live only in subdirectories, it proposes each top-most one with inputs.root (at most 8).

Also: the extractor README, a docs page (docs/builtins/extractors/python-dependencies.md), catalog registration, the extractors reference and built-ins tables, and cross-links from the other dependency built-ins.

A dependencies renderer scenario, python-uv-workspace ("Python uv workspace: a year of releases"), beside the npm and NuGet ones: two revisions of a three-project uv workspace (packages/renderers/graph/fixtures/python-workspace/), locked a year apart and read by python-dependencies into python-workspace-2025.json and python-workspace-2026.json. The files are named by year, not -v1/-v2, so the rules comparator's golden corpus doesn't pick them up as a pair. fixtures/make-python.mjs regenerates them. The lockfiles are committed as uv.lock.fixture and copied in as uv.lock, because GitHub's dependency graph reads every uv.lock and the 2025 lock deliberately holds releases with since-published advisories (dependency review failed on anyio < 4.14.2). The pair joins the dependency-graph tests (primary paths, every change visible, no route through a card). Like the npm major upgrade, its crossing check runs at rest and at each step's hold, not mid-step: at 0.82 of the transition one route (pytest → exceptiongroup) brushes the packaging card while cards make room.

Review fixes: relationship IDs stay unique when one dependency is declared under several markers. uv dependency entries' source selects the copy they mean, and a member's specifier is matched by the edge's marker. Requirements files keep every copy of a name pinned under exclusive markers and read inline # via annotations. Poetry's resolved_reference and PDM's revision are part of a Git package's source. include-group compares normalized names. Each fix has a test that fails without it. The scenario fixtures, golden extractions and the fastapi comparison are unchanged.

Housekeeping: graph.rs was over the repository's complexity limit (considered: 75, max 60), so PEP 440 ordering moved to version.rs and package identities to graph/identity.rs, unchanged. Two clippy warnings are fixed. DollarLint excludes the fixture pyproject.toml files, as it does other third-party formats extractor tests read, because SchemaStore's catalog points pyproject.toml at a schema on raw.githubusercontent.com, outside the allowed domains.

Trial: fastapi/fastapi#16849

projections compare cf65d62e..cbedbf8b -p python-dependencies --png on a fastapi/fastapi clone (the 24-bump dependency PR). explore proposes python-dependencies first, and the comparison runs without adopting it. Result: one project, 167 locked packages, 31 upgraded or downgraded, logfire-cli added (logfire 6 depends on it), pyee removed (playwright 1.65 drops it), and 134 unchanged packages hidden. Each changed package keeps the path that pulls it in. The bumped direct dependencies sit on the project's edges, and transitive changes (the opentelemetry exporters, deepmerge, httpcore2, pydantic-core) show beside them.

python-dependencies comparison of fastapi/fastapi#16849

Evidence

  • cargo test -p projections-extractor-python-dependencies passed (14 unit, 12 integration). The uv (multi-project workspace), Poetry, PDM and requirements-file fixtures were locked by uv, Poetry and PDM themselves (tests/fixtures/lock.mjs), and golden extractions compare each one.

  • cargo test -p projections-cli --test first_party passed (1, including the new python-dependencies case). node --test packages/cli/test/cli.test.mjs passed (7/7) against a debug build.

  • cargo test -p projections-cli --lib explore passed (34), including the new nested-project proposals.

  • node --test packages/renderers/graph/test/dependencies.test.mjs passed (14), and tools test packages/renderers/graph passed (50).

  • npm run docs:generate -- --only builtins,extractors,cli,renderers,agents: the hand-filled built-in doc regions were already current. Only docs/reference/renderers.md changed, to list the new scenario.

  • tools check --fast passed (considered, clippy, format, lint, typecheck of what changed). Under tools check --affected, cargo-check, clippy, considered, notices, comparators, boundaries and links pass. Its build, typecheck and lint gates failed here only on the VS Code extension's unbuilt host-vscode dependency, which this change doesn't touch.

  • The scenario's 2025 lock is resolved against pypi.org's index, as make-python.mjs does by default. uv lock only reads metadata and installs nothing. The package feed proxy can't serve --exclude-newer, because its simple index reports each file's upload time as when the proxy cached it (all 2026), so no release appears to predate 2025-03-01.

  • Documentation that this change affects is updated, and generated reference
    pages are regenerated (npm run docs:generate).

  • Fixes include a regression test.

  • A changelog fragment at changelog.d/<this PR's number>.md describes what
    users will notice, or the PR has the no changelog label (see
    changelog.d/README.md).

  • No credentials, private source or machine-specific paths are included.

agorischek and others added 2 commits December 4, 2026 21:14
Reads uv.lock, poetry.lock, pdm.lock and pinned requirements files with the
projects pyproject.toml declares (PEP 621, Poetry, uv workspaces), and draws
them with the dependencies renderer. explore proposes it for Python projects.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
…'s style

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

Copilot AI 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.

🟡 Changes recommended

Unresolved extraction errors can drop or misattribute dependency relationships, reject valid dependency-group references, and hide locked Git revision updates.

8 open issues
What changed in this PR

Adds a file-only Python dependency extractor to Projections, using the existing dependencies presentation without requiring Python, installs, or trust.

Changes:

  • Reads uv, Poetry, PDM, and pinned requirements files into dependency graphs.
  • Registers the extractor and adds discovery for root and nested Python projects.
  • Adds fixtures, tests, documentation, and a changelog entry.
File Description
packages/​renderers/​graph/​README.md Documents Python dependency graphs.
packages/​extractors/​README.md Lists runtime requirements.
packages/​extractors/​python-dependencies/​tests/​lockfiles.rs Adds extraction integration tests.
packages/​extractors/​python-dependencies/​tests/​fixtures/​uv-workspace/​uv.lock Supplies locked workspace dependencies.
packages/​extractors/​python-dependencies/​tests/​fixtures/​uv-workspace/​pyproject.toml Defines workspace fixture.
packages/​extractors/​python-dependencies/​tests/​fixtures/​uv-workspace/​packages/​legacy/​pyproject.toml Exercises member exclusion.
packages/​extractors/​python-dependencies/​tests/​fixtures/​uv-workspace/​packages/​core/​src/​harbor_core/​__init__.py Supplies fixture package structure.
packages/​extractors/​python-dependencies/​tests/​fixtures/​uv-workspace/​packages/​core/​pyproject.toml Defines core workspace member.
packages/​extractors/​python-dependencies/​tests/​fixtures/​uv-workspace/​packages/​api/​src/​harbor_api/​__init__.py Supplies fixture package structure.
packages/​extractors/​python-dependencies/​tests/​fixtures/​uv-workspace/​packages/​api/​pyproject.toml Defines API member and extras.
packages/​extractors/​python-dependencies/​tests/​fixtures/​requirements/​requirements.txt Supplies annotated dependency pins.
packages/​extractors/​python-dependencies/​tests/​fixtures/​requirements/​requirements.in Defines compilation inputs.
packages/​extractors/​python-dependencies/​tests/​fixtures/​requirements/​requirements-dev.txt Exercises includes and skipped requirements.
packages/​extractors/​python-dependencies/​tests/​fixtures/​requirements.expected.json Records expected requirements graph.
packages/​extractors/​python-dependencies/​tests/​fixtures/​poetry/​pyproject.toml Defines Poetry fixture.
packages/​extractors/​python-dependencies/​tests/​fixtures/​poetry.expected.json Records expected Poetry graph.
packages/​extractors/​python-dependencies/​tests/​fixtures/​pdm/​pyproject.toml Defines PDM fixture.
packages/​extractors/​python-dependencies/​tests/​fixtures/​pdm/​pdm.lock Supplies locked PDM dependencies.
packages/​extractors/​python-dependencies/​tests/​fixtures/​pdm.expected.json Records expected PDM graph.
packages/​extractors/​python-dependencies/​tests/​fixtures/​lock.mjs Regenerates fixture lockfiles.
packages/​extractors/​python-dependencies/​src/​requirement.rs Parses names and requirements.
packages/​extractors/​python-dependencies/​src/​pyproject.rs Reads projects, extras, and groups.
packages/​extractors/​python-dependencies/​src/​model.rs Defines shared dependency models.
packages/​extractors/​python-dependencies/​src/​lockfile/​uv.rs Parses uv lockfiles.
packages/​extractors/​python-dependencies/​src/​lockfile/​requirements.rs Parses pins, includes, and annotations.
packages/​extractors/​python-dependencies/​src/​lockfile/​poetry.rs Parses Poetry lockfiles.
packages/​extractors/​python-dependencies/​src/​lockfile/​pdm.rs Parses PDM lockfiles.
packages/​extractors/​python-dependencies/​src/​lockfile.rs Provides shared parsing helpers.
packages/​extractors/​python-dependencies/​src/​lib.rs Coordinates detection and extraction.
packages/​extractors/​python-dependencies/​src/​graph.rs Builds graph entities and relationships.
packages/​extractors/​python-dependencies/​README.md Documents inputs and extraction semantics.
packages/​extractors/​python-dependencies/​Cargo.toml Defines extractor crate.
packages/​extractors/​catalog/​src/​lib.rs Registers the extractor.
packages/​extractors/​catalog/​Cargo.toml Adds catalog dependency.
packages/​cli/​tests/​first_party.rs Adds first-party extraction case.
packages/​cli/​test/​cli.test.mjs Updates expected catalog entries.
packages/​cli/​src/​explore/​python.rs Proposes nested Python projects.
packages/​cli/​src/​explore.rs Integrates Python discovery.
docs/​reference/​extractors.md Adds extractor reference entry.
docs/​builtins/​renderers/​graph.md Lists Python renderer integration.
docs/​builtins/​README.md Adds built-in catalog entry.
docs/​builtins/​extractors/​workspace-dependencies.md Cross-links Python support.
docs/​builtins/​extractors/​python-dependencies.md Adds usage and limitations guide.
docs/​builtins/​extractors/​nuget-dependencies.md Cross-links Python support.
docs/​builtins/​extractors/​cargo-dependencies.md Cross-links Python support.
changelog.d/​386.md Announces Python dependency extraction.
Cargo.lock Records the new crate dependency.

Review effort: Balanced

agorischek and others added 4 commits December 4, 2026 22:20
Two revisions of a uv workspace, locked a year apart and read by
python-dependencies: python-workspace-2025.json and -2026.json, named by year
so the rules comparator's golden corpus doesn't pair them. Registered as the
python-uv-workspace scenario and added to the dependency-graph tests; like the
npm major upgrade, its routes are checked for crossings at rest and at each
step's hold.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
…t of graph.rs

graph.rs was over the repository's complexity limit (considered: 75, max 60).
Version ordering moves to version.rs and package identities to
graph/identity.rs, unchanged. Also fixes two clippy warnings (a redundant
closure, and a complex key type now named).

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
…ollarLint's schema fetch

The scenario's uv lockfiles are kept as uv.lock.fixture and copied in as
uv.lock by make-python.mjs: GitHub's dependency graph reads every uv.lock, and
the 2025 revision deliberately locks releases with since-published advisories
(anyio < 4.14.2), which failed dependency review and would raise Dependabot
alerts for packages nothing installs. The extractions are unchanged.

DollarLint excludes the fixture pyproject.toml files, as it does other
third-party formats the extractor tests read: SchemaStore's catalog points
pyproject.toml at raw.githubusercontent.com, outside the allowed domains.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
…and group names

- Relationship IDs stay unique when one dependency is declared under several
  markers that resolve to one package: identical declarations are one, and
  conditions on one target add their marker instead of overwriting each other.
- uv dependency entries' `source` selects the copy they mean, so two copies of
  one name and version from different sources aren't both targeted.
- A uv member's declared specifier is matched by the locked edge's marker, so a
  name required under several markers keeps each specifier.
- Requirements files keep every copy of a name pinned under exclusive markers,
  and `# via` names pull in every copy; inline `# via` annotations
  (`--annotation-style=line`) count.
- Poetry's `resolved_reference` and PDM's `revision` are part of a Git
  package's source, so moving to another commit is a change.
- PEP 735 `include-group` compares normalized group names.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

2 participants