From 0e655811355df96f21f25d079a5c768681f58659 Mon Sep 17 00:00:00 2001 From: agorischek <6295280+agorischek@users.noreply.github.com> Date: Fri, 4 Dec 2026 20:43:03 +0000 Subject: [PATCH 1/7] python-dependencies: a built-in extractor for Python projects 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> --- Cargo.lock | 11 + docs/builtins/README.md | 1 + .../builtins/extractors/cargo-dependencies.md | 7 +- .../builtins/extractors/nuget-dependencies.md | 7 +- .../extractors/python-dependencies.md | 161 +++ .../extractors/workspace-dependencies.md | 7 +- docs/builtins/renderers/graph.md | 7 +- docs/reference/extractors.md | 26 + packages/cli/src/explore.rs | 6 +- packages/cli/src/explore/python.rs | 131 +++ packages/cli/test/cli.test.mjs | 1 + packages/cli/tests/first_party.rs | 2 + packages/extractors/README.md | 1 + packages/extractors/catalog/Cargo.toml | 1 + packages/extractors/catalog/src/lib.rs | 1 + .../extractors/python-dependencies/Cargo.toml | 16 + .../extractors/python-dependencies/README.md | 173 +++ .../python-dependencies/src/graph.rs | 503 ++++++++ .../extractors/python-dependencies/src/lib.rs | 336 ++++++ .../python-dependencies/src/lockfile.rs | 26 + .../python-dependencies/src/lockfile/pdm.rs | 85 ++ .../src/lockfile/poetry.rs | 80 ++ .../src/lockfile/requirements.rs | 277 +++++ .../python-dependencies/src/lockfile/uv.rs | 165 +++ .../python-dependencies/src/model.rs | 71 ++ .../python-dependencies/src/pyproject.rs | 396 +++++++ .../python-dependencies/src/requirement.rs | 130 +++ .../tests/fixtures/lock.mjs | 84 ++ .../tests/fixtures/pdm.expected.json | 858 ++++++++++++++ .../tests/fixtures/pdm/pdm.lock | 374 ++++++ .../tests/fixtures/pdm/pyproject.toml | 17 + .../tests/fixtures/poetry.expected.json | 770 +++++++++++++ .../tests/fixtures/poetry/poetry.lock | 393 +++++++ .../tests/fixtures/poetry/pyproject.toml | 18 + .../tests/fixtures/requirements.expected.json | 833 ++++++++++++++ .../requirements/requirements-dev.txt | 5 + .../fixtures/requirements/requirements.in | 2 + .../fixtures/requirements/requirements.txt | 51 + .../tests/fixtures/uv-workspace.expected.json | 1018 +++++++++++++++++ .../uv-workspace/packages/api/pyproject.toml | 18 + .../packages/api/src/harbor_api/__init__.py | 0 .../uv-workspace/packages/core/pyproject.toml | 9 + .../packages/core/src/harbor_core/__init__.py | 0 .../packages/legacy/pyproject.toml | 4 + .../fixtures/uv-workspace/pyproject.toml | 20 + .../tests/fixtures/uv-workspace/uv.lock | 239 ++++ .../python-dependencies/tests/lockfiles.rs | 333 ++++++ packages/renderers/graph/README.md | 9 +- 48 files changed, 7666 insertions(+), 17 deletions(-) create mode 100644 docs/builtins/extractors/python-dependencies.md create mode 100644 packages/cli/src/explore/python.rs create mode 100644 packages/extractors/python-dependencies/Cargo.toml create mode 100644 packages/extractors/python-dependencies/README.md create mode 100644 packages/extractors/python-dependencies/src/graph.rs create mode 100644 packages/extractors/python-dependencies/src/lib.rs create mode 100644 packages/extractors/python-dependencies/src/lockfile.rs create mode 100644 packages/extractors/python-dependencies/src/lockfile/pdm.rs create mode 100644 packages/extractors/python-dependencies/src/lockfile/poetry.rs create mode 100644 packages/extractors/python-dependencies/src/lockfile/requirements.rs create mode 100644 packages/extractors/python-dependencies/src/lockfile/uv.rs create mode 100644 packages/extractors/python-dependencies/src/model.rs create mode 100644 packages/extractors/python-dependencies/src/pyproject.rs create mode 100644 packages/extractors/python-dependencies/src/requirement.rs create mode 100644 packages/extractors/python-dependencies/tests/fixtures/lock.mjs create mode 100644 packages/extractors/python-dependencies/tests/fixtures/pdm.expected.json create mode 100644 packages/extractors/python-dependencies/tests/fixtures/pdm/pdm.lock create mode 100644 packages/extractors/python-dependencies/tests/fixtures/pdm/pyproject.toml create mode 100644 packages/extractors/python-dependencies/tests/fixtures/poetry.expected.json create mode 100644 packages/extractors/python-dependencies/tests/fixtures/poetry/poetry.lock create mode 100644 packages/extractors/python-dependencies/tests/fixtures/poetry/pyproject.toml create mode 100644 packages/extractors/python-dependencies/tests/fixtures/requirements.expected.json create mode 100644 packages/extractors/python-dependencies/tests/fixtures/requirements/requirements-dev.txt create mode 100644 packages/extractors/python-dependencies/tests/fixtures/requirements/requirements.in create mode 100644 packages/extractors/python-dependencies/tests/fixtures/requirements/requirements.txt create mode 100644 packages/extractors/python-dependencies/tests/fixtures/uv-workspace.expected.json create mode 100644 packages/extractors/python-dependencies/tests/fixtures/uv-workspace/packages/api/pyproject.toml create mode 100644 packages/extractors/python-dependencies/tests/fixtures/uv-workspace/packages/api/src/harbor_api/__init__.py create mode 100644 packages/extractors/python-dependencies/tests/fixtures/uv-workspace/packages/core/pyproject.toml create mode 100644 packages/extractors/python-dependencies/tests/fixtures/uv-workspace/packages/core/src/harbor_core/__init__.py create mode 100644 packages/extractors/python-dependencies/tests/fixtures/uv-workspace/packages/legacy/pyproject.toml create mode 100644 packages/extractors/python-dependencies/tests/fixtures/uv-workspace/pyproject.toml create mode 100644 packages/extractors/python-dependencies/tests/fixtures/uv-workspace/uv.lock create mode 100644 packages/extractors/python-dependencies/tests/lockfiles.rs diff --git a/Cargo.lock b/Cargo.lock index c3f7d2be7..9292735db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1501,6 +1501,7 @@ dependencies = [ "projections-extractor-nuget-dependencies", "projections-extractor-openrewrite-data-tables", "projections-extractor-prisma-schema", + "projections-extractor-python-dependencies", "projections-extractor-rails-routes", "projections-extractor-rails-schema", "projections-extractor-renderer-scenarios", @@ -1669,6 +1670,16 @@ dependencies = [ "tempfile", ] +[[package]] +name = "projections-extractor-python-dependencies" +version = "0.3.2" +dependencies = [ + "anyhow", + "projections-extractor-sdk", + "serde_json", + "toml", +] + [[package]] name = "projections-extractor-rails-routes" version = "0.3.2" diff --git a/docs/builtins/README.md b/docs/builtins/README.md index 7178612b3..50e4abb50 100644 --- a/docs/builtins/README.md +++ b/docs/builtins/README.md @@ -25,6 +25,7 @@ The VS Code extension also opens these pages when you select a built-in part. | [`swift-package-dependencies`](extractors/swift-package-dependencies.md) | Swift package products, targets, target dependencies and package dependencies with Package.resolved versions. | `graph/v0` | [`dependencies`](renderers/graph.md) | | [`xcode-modules`](extractors/xcode-modules.md) | Xcode targets with their module names, target and package product dependencies, and the modules their Swift sources import. | `graph/v0` | [`dependencies`](renderers/graph.md) | | [`nuget-dependencies`](extractors/nuget-dependencies.md) | Resolved NuGet project.assets.json graph. | `graph/v0` | [`dependencies`](renderers/graph.md) | +| [`python-dependencies`](extractors/python-dependencies.md) | Python projects and the packages uv.lock, poetry.lock, pdm.lock or pinned requirements files resolve for them. | `graph/v0` | [`dependencies`](renderers/graph.md) | | [`terraform-infrastructure`](extractors/terraform-infrastructure.md) | Terraform resources, modules and references, with each resource's planned action. | `architecture/v0` | [`infrastructure`](renderers/graph.md) | | [`azure-what-if`](extractors/azure-what-if.md) | Azure resources, containment and references, with each resource's what-if change. | `architecture/v0` | [`infrastructure`](renderers/graph.md) | | [`github-actions-jobs`](extractors/github-actions-jobs.md) | Triggers, jobs, needs and matrices declared by a GitHub Actions workflow. | `dag/v0` | [`github-actions`](renderers/github-actions.md) | diff --git a/docs/builtins/extractors/cargo-dependencies.md b/docs/builtins/extractors/cargo-dependencies.md index 41ac1836c..480e2002b 100644 --- a/docs/builtins/extractors/cargo-dependencies.md +++ b/docs/builtins/extractors/cargo-dependencies.md @@ -141,9 +141,10 @@ each crate. - [`graph`](../renderers/graph.md) renders this extractor with its `dependencies` presentation. -- [`workspace-dependencies`](workspace-dependencies.md) and - [`nuget-dependencies`](nuget-dependencies.md) provide the same dependency - graph for Node and .NET. +- [`workspace-dependencies`](workspace-dependencies.md), + [`nuget-dependencies`](nuget-dependencies.md) and + [`python-dependencies`](python-dependencies.md) provide the same dependency + graph for Node, .NET and Python. - [`rust-public-api`](rust-public-api.md) tracks what a crate exports rather than what it depends on. - [The default comparator](../comparators/default.md) can order review steps by diff --git a/docs/builtins/extractors/nuget-dependencies.md b/docs/builtins/extractors/nuget-dependencies.md index ada8970b8..68f930def 100644 --- a/docs/builtins/extractors/nuget-dependencies.md +++ b/docs/builtins/extractors/nuget-dependencies.md @@ -133,9 +133,10 @@ each package. - [`graph`](../renderers/graph.md) renders this extractor with its `dependencies` presentation. -- [`workspace-dependencies`](workspace-dependencies.md) and - [`cargo-dependencies`](cargo-dependencies.md) provide the same dependency - graph for Node and Rust. +- [`workspace-dependencies`](workspace-dependencies.md), + [`cargo-dependencies`](cargo-dependencies.md) and + [`python-dependencies`](python-dependencies.md) provide the same dependency + graph for Node, Rust and Python. - [`dotnet-public-api`](dotnet-public-api.md) and [`dotnet-di`](dotnet-di.md) inspect what .NET projects export and wire up. - [The default comparator](../comparators/default.md) can order review steps by diff --git a/docs/builtins/extractors/python-dependencies.md b/docs/builtins/extractors/python-dependencies.md new file mode 100644 index 000000000..651b81b3a --- /dev/null +++ b/docs/builtins/extractors/python-dependencies.md @@ -0,0 +1,161 @@ +# Python dependencies + +This extractor maps a Python project (or a uv workspace of them) and the full +transitive dependency tree behind it: what each project declares, what its +lockfile resolves that to, and what those packages pull in. Compared across a +pull request, it shows which dependencies were added, removed, upgraded, or +downgraded—and what pulls them in. + + + +- ID: `python-dependencies` +- Extraction schema: [`graph/v0`](../../reference/schemas/graph.md) +- Drawn by default with: [`dependencies`](../renderers/graph.md) +- Needs `--trust`: No (`none`) +- Suggested when the repository has: `pyproject.toml`, `uv.lock`, `poetry.lock`, + `pdm.lock`, `requirements*.txt`, `requirements/*.txt`, `**/pyproject.toml`, + `**/uv.lock`, `**/poetry.lock`, `**/pdm.lock` + + + +## When to use it + +Use this extractor in any Python repository that locks its dependencies with uv, +Poetry or PDM, or pins them in requirements files, when you want to review +dependency changes as a graph instead of wading through a lockfile diff. A new +direct dependency and the transitive packages it brings, a major bump deep in +the tree, or a dependency group growing a new tool all stand out immediately. + +Because it only reads manifests and lockfiles, it runs safely on any pull +request without `--trust`, and needs no Python installation. + +It covers Python packages only. For Node use +[`workspace-dependencies`](workspace-dependencies.md), for Rust use +[`cargo-dependencies`](cargo-dependencies.md), and for .NET use +[`nuget-dependencies`](nuget-dependencies.md). + +## What it reads + +- The root `pyproject.toml`: PEP 621 `[project]` dependencies and + `optional-dependencies`, PEP 735 `[dependency-groups]`, Poetry's + `[tool.poetry]` dependencies, groups and extras, and PDM's and uv's + development dependencies. For a uv workspace, every member + `[tool.uv.workspace]` selects. +- One lockfile: `uv.lock` (version 1), `poetry.lock` (lock-version 1.x or 2.x) + or `pdm.lock` (lock_version 4.x). +- Without a lockfile, pinned requirements files: `requirements*.txt` and + `requirements/*.txt`, with the files they include. `# via` annotations written + by `pip-compile` or `uv pip compile` say what pulls each pin in. + +The manager is chosen from `inputs.manager`, then the lockfile present (or, with +several, the manager the root `pyproject.toml` configures), then requirements +files. Nothing is installed or executed. + +Each project becomes a `project` entity, and each package it reaches a `package` +with its `version`. Declared dependencies become typed edges—`dependencies`, an +extra's `optionalDependencies`, a group's `devDependencies`—recording the +declared specifier and the resolved version. Because entity IDs exclude +versions, an upgrade appears as a single modified package rather than a removal +and an addition. + +## Options + + + +| Input | Meaning | +| -------------- | --------------------------------------------------------------------------------------------------- | +| `manager` | uv, poetry, pdm or requirements; default from the lockfile present. | +| `requirements` | Array of requirements files relative to the root; default requirements*.txt and requirements/*.txt. | +| `root` | Repository-relative project or workspace root; default ".". | + + + +## What a comparison shows + +- **Added or removed packages** — a new dependency with everything it pulls in, + or a package that is no longer locked. +- **Upgrades and downgrades** shown as modified packages. The + [`dependencies`](../renderers/graph.md) renderer labels each by which version + component moved (`Major upgrade`, `Patch downgrade`), and the summary bar + groups them into clickable filters, plus how many direct dependencies changed. +- **Declaration changes**, such as moving a dependency into a dependency group, + adding an extra, or widening a specifier from `>=1.2` to `>=1.3`. + +Unchanged transitive dependencies collapse into summary cards ("12 more +packages") to keep the diff focused; toggle **All packages** to expand them. + +## Start from this definition + + + +```json +{ + "extractor": "python-dependencies", + "id": "python-dependencies", + "renderer": "dependencies", + "title": "Python dependencies" +} +``` + + + +## Limitations + +- Environment markers are recorded on each relationship but not evaluated: the + graph is the lockfile's resolution for every platform and Python version at + once. +- Every extra and dependency group a project declares is included; a package's + own extras are followed only where something in the graph requests them. +- Requirements files record no dependency graph: without `# via` annotations + every pin is a direct dependency, and lines that don't pin one version with + `==` (ranges, URLs, editable installs) are left out and listed in + `metadata.skipped`. +- `poetry.lock` and `pdm.lock` don't record which of several locked copies of a + name a dependency uses, so a dependency on such a name points at every copy. +- Poetry and PDM path dependencies are packages, not projects; only uv + workspaces have several projects. +- Because it reads lockfiles rather than querying an index, it doesn't include + vulnerability data, licenses, or package contents. + +## Related + +- [`graph`](../renderers/graph.md) — draws this graph using its `dependencies` + presentation. +- [`workspace-dependencies`](workspace-dependencies.md), + [`cargo-dependencies`](cargo-dependencies.md) and + [`nuget-dependencies`](nuget-dependencies.md) — the same dependency graph for + Node, Rust and .NET. +- [`django-schema`](django-schema.md) — a Django project's models. + +## How it works + +See the +[package README](../../../packages/extractors/python-dependencies/README.md) for +each lockfile's reading rules and the extraction model. + +## Build your own + +Consider writing a custom extractor when lockfiles don't capture what you need: + +- **Other tools or layouts**, such as Pipenv's `Pipfile.lock`, Conda + environments, or Pants and Bazel build graphs. +- **One environment**, evaluating markers for a single platform and Python + version. +- **Module-level granularity**, tracking imports between source files instead of + packages. + +Check the built-in options first: `root` points at a nested project, `manager` +picks one lockfile of several, and `requirements` selects requirements files. To +visualize the same graph differently, keep this extractor and write a custom +renderer. + +**With the CLI**, keep this graph's renderer: + +```sh +projections init --language python --renderer dependencies +``` + +[Write your first extractor](../../guides/first-extractor.md) walks through a +complete example, and +[Extraction schema](../../guides/schemas.md#extraction-schema) documents the +output format. diff --git a/docs/builtins/extractors/workspace-dependencies.md b/docs/builtins/extractors/workspace-dependencies.md index d2327a44a..94cfd2d12 100644 --- a/docs/builtins/extractors/workspace-dependencies.md +++ b/docs/builtins/extractors/workspace-dependencies.md @@ -114,9 +114,10 @@ packages") to keep the diff focused; toggle **All packages** to expand them. - [`graph`](../renderers/graph.md) — draws this graph using its `dependencies` presentation. -- [`cargo-dependencies`](cargo-dependencies.md) and - [`nuget-dependencies`](nuget-dependencies.md) — the same dependency graph for - Rust and .NET. +- [`cargo-dependencies`](cargo-dependencies.md), + [`nuget-dependencies`](nuget-dependencies.md) and + [`python-dependencies`](python-dependencies.md) — the same dependency graph + for Rust, .NET and Python. - [The default comparator](../comparators/default.md) — supports ordering steps by dependent count (`order.by: dependents`). diff --git a/docs/builtins/renderers/graph.md b/docs/builtins/renderers/graph.md index c6e9fb31f..047510d04 100644 --- a/docs/builtins/renderers/graph.md +++ b/docs/builtins/renderers/graph.md @@ -44,6 +44,7 @@ Built-in extractors that use it by default: | [`swift-package-dependencies`](../extractors/swift-package-dependencies.md) | `dependencies` | | [`xcode-modules`](../extractors/xcode-modules.md) | `dependencies` | | [`nuget-dependencies`](../extractors/nuget-dependencies.md) | `dependencies` | +| [`python-dependencies`](../extractors/python-dependencies.md) | `dependencies` | | [`terraform-infrastructure`](../extractors/terraform-infrastructure.md) | `infrastructure` | | [`azure-what-if`](../extractors/azure-what-if.md) | `infrastructure` | | [`openrewrite-data-tables`](../extractors/openrewrite-data-tables.md) | `architecture` | @@ -392,8 +393,10 @@ inside the `invoicing` module along with its new dependencies. - Default extractors: [`workspace-dependencies`](../extractors/workspace-dependencies.md), - [`cargo-dependencies`](../extractors/cargo-dependencies.md), and - [`nuget-dependencies`](../extractors/nuget-dependencies.md) (`dependencies`); + [`cargo-dependencies`](../extractors/cargo-dependencies.md), + [`nuget-dependencies`](../extractors/nuget-dependencies.md), and + [`python-dependencies`](../extractors/python-dependencies.md) + (`dependencies`); [`terraform-infrastructure`](../extractors/terraform-infrastructure.md) and [`azure-what-if`](../extractors/azure-what-if.md) (`infrastructure`); [`github-actions-jobs`](../extractors/github-actions-jobs.md) (`dag`); and diff --git a/docs/reference/extractors.md b/docs/reference/extractors.md index 059a148b7..d7a98faff 100644 --- a/docs/reference/extractors.md +++ b/docs/reference/extractors.md @@ -24,6 +24,7 @@ it was removed) isn't an error: the extractor describes that revision without it | [`swift-package-dependencies`](#swift-package-dependencies) | `graph/v0` | `dependencies` | When it runs ecosystem tools or repository code (`when-executing-tools`) | | [`xcode-modules`](#xcode-modules) | `graph/v0` | `dependencies` | No (`none`) | | [`nuget-dependencies`](#nuget-dependencies) | `graph/v0` | `dependencies` | When it runs ecosystem tools or repository code (`when-executing-tools`) | +| [`python-dependencies`](#python-dependencies) | `graph/v0` | `dependencies` | No (`none`) | | [`terraform-infrastructure`](#terraform-infrastructure) | `architecture/v0` | `infrastructure` | When it runs ecosystem tools or repository code (`when-executing-tools`) | | [`azure-what-if`](#azure-what-if) | `architecture/v0` | `infrastructure` | When it runs ecosystem tools or repository code (`when-executing-tools`) | | [`github-actions-jobs`](#github-actions-jobs) | `dag/v0` | `github-actions` | No (`none`) | @@ -343,6 +344,31 @@ A definition to start from: } ``` +## `python-dependencies` + +**Python dependencies.** Python projects and the packages uv.lock, poetry.lock, pdm.lock or pinned requirements files resolve for them. See [its page](../builtins/extractors/python-dependencies.md). + +- Schema: `graph/v0` +- Default renderer: `dependencies` +- Needs `--trust`: No (`none`) + +| Input | Meaning | +|---|---| +| `manager` | uv, poetry, pdm or requirements; default from the lockfile present. | +| `requirements` | Array of requirements files relative to the root; default requirements*.txt and requirements/*.txt. | +| `root` | Repository-relative project or workspace root; default ".". | + +A definition to start from: + +```json +{ + "extractor": "python-dependencies", + "id": "python-dependencies", + "renderer": "dependencies", + "title": "Python dependencies" +} +``` + ## `terraform-infrastructure` **Terraform infrastructure.** Terraform resources, modules and references, with each resource's planned action. See [its page](../builtins/extractors/terraform-infrastructure.md). diff --git a/packages/cli/src/explore.rs b/packages/cli/src/explore.rs index 4d5c84fc6..1d2154df5 100644 --- a/packages/cli/src/explore.rs +++ b/packages/cli/src/explore.rs @@ -15,6 +15,7 @@ mod django; mod dotnet; mod evidence; mod named; +mod python; mod rust; mod spring; mod tetragon; @@ -162,8 +163,9 @@ pub fn candidates(runner: &Runner, root: &Path) -> Result> { specific.extend(per_file(descriptor, input, &matched, &authored)); continue; } - if let Some(found) = - dotnet::candidates(descriptor, &matched, &files, &authored).or_else(|| rust::candidates(root, descriptor, &files, &authored)) + if let Some(found) = dotnet::candidates(descriptor, &matched, &files, &authored) + .or_else(|| rust::candidates(root, descriptor, &files, &authored)) + .or_else(|| python::candidates(descriptor, &matched, &authored)) { specific.extend(found); continue; diff --git a/packages/cli/src/explore/python.rs b/packages/cli/src/explore/python.rs new file mode 100644 index 000000000..6a72daf88 --- /dev/null +++ b/packages/cli/src/explore/python.rs @@ -0,0 +1,131 @@ +//! `python-dependencies` proposals. A project whose root holds a `pyproject.toml`, a lockfile or requirements files gets +//! the extractor's one proposal, which reads the root. Otherwise each top-most directory holding a `pyproject.toml` or a +//! lockfile (a workspace's members are under it) is proposed with `inputs.root`, at most [`MOST`] of them, by path. + +use serde_json::{Value, json}; + +use super::{candidate, slug}; + +pub(super) const EXTRACTOR: &str = "python-dependencies"; + +/// Nested Python projects proposed at most. +const MOST: usize = 8; + +/// Files that make their directory a Python project root. +const ROOTS: [&str; 4] = ["pyproject.toml", "uv.lock", "poetry.lock", "pdm.lock"]; + +/// The proposals from the detected files `matched` (pattern, file); `None` for another extractor, or when the root is a +/// Python project, which the extractor's own proposal reads. +pub(super) fn candidates(descriptor: &Value, matched: &[(&str, &String)], authored: &[&Value]) -> Option> { + if descriptor["id"] != EXTRACTOR + || matched + .iter() + .any(|(_, file)| !file.contains('/') || file.starts_with("requirements/")) + { + return None; + } + let mut directories: Vec<(&str, &str, &String)> = matched + .iter() + .filter_map(|(pattern, file)| { + let (directory, name) = file.rsplit_once('/')?; + ROOTS.contains(&name).then_some((directory, *pattern, *file)) + }) + .collect(); + directories.sort_by(|a, b| a.0.cmp(b.0)); + directories.dedup_by(|later, earlier| later.0 == earlier.0); + let top: Vec<(&str, &str, &String)> = directories + .iter() + .filter(|(directory, ..)| { + !directories + .iter() + .any(|(other, ..)| other != directory && directory.starts_with(&format!("{other}/"))) + }) + .copied() + .collect(); + let mut seen = std::collections::BTreeSet::new(); + Some( + top.iter() + .take(MOST) + .map(|(directory, pattern, file)| { + let id = [slug(directory)] + .into_iter() + .chain((2..).map(|number| format!("{}-{number}", slug(directory)))) + .map(|suffix| format!("{EXTRACTOR}-{suffix}")) + .find(|id| seen.insert(id.clone())) + .unwrap_or_default(); + let mut definition = descriptor["template"].clone(); + definition["id"] = json!(id); + definition["title"] = json!(format!("{}: {directory}", descriptor["title"].as_str().unwrap_or(EXTRACTOR))); + definition["inputs"] = json!({"root": directory}); + let adopted = authored + .iter() + .find(|item| item["id"] == id.as_str() || (item["extractor"] == EXTRACTOR && item["inputs"]["root"] == *directory)) + .and_then(|item| item["id"].as_str()); + let basis = json!({"pattern": pattern, "count": 1, "examples": [file], "file": file, "projects": top.len()}); + candidate(descriptor, &id, basis, adopted, definition) + }) + .collect(), + ) +} + +#[cfg(test)] +mod tests { + use super::*; + + fn descriptor() -> Value { + crate::extractors::catalog()["extractors"] + .as_array() + .unwrap() + .iter() + .find(|item| item["id"] == EXTRACTOR) + .unwrap() + .clone() + } + + fn matched(files: &[String]) -> Vec<(&'static str, &String)> { + files.iter().map(|file| ("**/pyproject.toml", file)).collect() + } + + #[test] + fn a_root_project_keeps_the_extractors_own_proposal() { + let files: Vec = ["pyproject.toml", "uv.lock", "packages/api/pyproject.toml"] + .map(str::to_owned) + .into(); + assert!(candidates(&descriptor(), &matched(&files), &[]).is_none()); + let files: Vec = ["requirements.txt"].map(str::to_owned).into(); + assert!(candidates(&descriptor(), &matched(&files), &[]).is_none()); + assert!(candidates(&json!({"id": "cargo-dependencies"}), &[], &[]).is_none()); + } + + #[test] + fn nested_projects_are_proposed_at_their_top_most_directories() { + let files: Vec = [ + "backend/pyproject.toml", + "backend/uv.lock", + "backend/packages/api/pyproject.toml", + "services/worker/poetry.lock", + "services/worker/pyproject.toml", + ] + .map(str::to_owned) + .into(); + let adopted = json!({"id": "worker-deps", "extractor": EXTRACTOR, "inputs": {"root": "services/worker"}}); + let found = candidates(&descriptor(), &matched(&files), &[&adopted]).unwrap(); + let summary: Vec<(&str, &Value, &Value)> = found + .iter() + .map(|c| (c["id"].as_str().unwrap(), &c["definition"]["inputs"]["root"], &c["adopted"])) + .collect(); + assert_eq!( + summary, + [ + ("python-dependencies-backend", &json!("backend"), &Value::Null), + ( + "python-dependencies-services-worker", + &json!("services/worker"), + &json!("worker-deps") + ), + ] + ); + assert_eq!(found[0]["definition"]["title"], "Python dependencies: backend"); + assert_eq!(found[0]["requiresTrust"], false); + } +} diff --git a/packages/cli/test/cli.test.mjs b/packages/cli/test/cli.test.mjs index 50ec17c35..adfc1710c 100644 --- a/packages/cli/test/cli.test.mjs +++ b/packages/cli/test/cli.test.mjs @@ -150,6 +150,7 @@ test('extractor list/init work without execution; invalid flags, duplicate outpu 'swift-package-dependencies', 'xcode-modules', 'nuget-dependencies', + 'python-dependencies', 'terraform-infrastructure', 'azure-what-if', 'github-actions-jobs', diff --git a/packages/cli/tests/first_party.rs b/packages/cli/tests/first_party.rs index 3fa3f2d51..767d3840f 100644 --- a/packages/cli/tests/first_party.rs +++ b/packages/cli/tests/first_party.rs @@ -73,6 +73,7 @@ fn cases(root: &Path) -> Vec<(&'static str, Value)> { &root.join("swift-api"), ); copy(&fixtures("nuget-dependencies"), &root.join("nuget")); + copy(&fixtures("python-dependencies").join("uv-workspace"), &root.join("python")); copy( &fixtures("terraform-infrastructure").join("aws/base.plan.json"), &root.join("terraform/plan.json"), @@ -130,6 +131,7 @@ fn cases(root: &Path) -> Vec<(&'static str, Value)> { ("openrewrite-data-tables", json!({"tables": "openrewrite"})), ("swift-public-api", json!({"symbolGraphPath": "swift-api", "modules": ["Ledger"]})), ("nuget-dependencies", json!({"assetsPaths": ["nuget/nuget/project.assets.json"]})), + ("python-dependencies", json!({"root": "python"})), ("terraform-infrastructure", json!({"planJsonPath": "terraform/plan.json"})), ( "azure-what-if", diff --git a/packages/extractors/README.md b/packages/extractors/README.md index 8fa265c25..6440e0b34 100644 --- a/packages/extractors/README.md +++ b/packages/extractors/README.md @@ -69,6 +69,7 @@ with an explicit error, never a fallback. | `spring-di` | A JDK 17+ with `javac` and the project's Gradle or Maven (wrapper or on PATH); Spring Boot 3.0+ ([Spring](spring-di/README.md)) | | `cargo-dependencies`, `nuget-dependencies`, `terraform-infrastructure`, `azure-what-if` | The ecosystem's tool when not importing a pre-exported model | | `swift-package-dependencies` | Nothing; a Swift toolchain only with `manifest: "dump-package"` ([Swift package dependencies](swift-package-dependencies/README.md)) | +| `python-dependencies` | Nothing: it reads `pyproject.toml` and the lockfile or requirements files, with no Python and no installs ([Python dependencies](python-dependencies/README.md)) | | `xcode-modules` | Nothing: it reads project files and sources without Xcode ([Xcode modules](xcode-modules/README.md)) | | `openrewrite-data-tables` | Nothing: it reads the CSV data tables an OpenRewrite or Moderne run exported, with no JVM and no downloads ([OpenRewrite data tables](openrewrite-data-tables/README.md)) | | `scip-file-references` | The project's own SCIP indexer (`scip-typescript`, `rust-analyzer`, `scip-go`, `scip-python`, …) when not reading an existing index ([SCIP](scip-file-references/README.md)) | diff --git a/packages/extractors/catalog/Cargo.toml b/packages/extractors/catalog/Cargo.toml index edb079537..484bdff46 100644 --- a/packages/extractors/catalog/Cargo.toml +++ b/packages/extractors/catalog/Cargo.toml @@ -24,6 +24,7 @@ projections-extractor-nestjs-di = { path = "../nestjs-di" } projections-extractor-nuget-dependencies = { path = "../nuget-dependencies" } projections-extractor-openrewrite-data-tables = { path = "../openrewrite-data-tables" } projections-extractor-prisma-schema = { path = "../prisma-schema" } +projections-extractor-python-dependencies = { path = "../python-dependencies" } projections-extractor-rails-routes = { path = "../rails-routes" } projections-extractor-rails-schema = { path = "../rails-schema" } projections-extractor-renderer-scenarios = { path = "../renderer-scenarios" } diff --git a/packages/extractors/catalog/src/lib.rs b/packages/extractors/catalog/src/lib.rs index 7370609f0..3b9a137f3 100644 --- a/packages/extractors/catalog/src/lib.rs +++ b/packages/extractors/catalog/src/lib.rs @@ -44,6 +44,7 @@ registry!( projections_extractor_swift_package_dependencies, projections_extractor_xcode_modules, projections_extractor_nuget_dependencies, + projections_extractor_python_dependencies, projections_extractor_terraform_infrastructure, projections_extractor_azure_what_if, projections_extractor_github_actions_jobs, diff --git a/packages/extractors/python-dependencies/Cargo.toml b/packages/extractors/python-dependencies/Cargo.toml new file mode 100644 index 000000000..f5c6186bf --- /dev/null +++ b/packages/extractors/python-dependencies/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "projections-extractor-python-dependencies" +publish = false +version.workspace = true +edition.workspace = true +license.workspace = true +rust-version.workspace = true + +[dependencies] +anyhow = "1" +projections-extractor-sdk = { path = "../sdk" } +serde_json = { version = "1", features = ["float_roundtrip"] } +toml = "0.9" + +[dev-dependencies] +projections-extractor-sdk = { path = "../sdk", features = ["testing"] } diff --git a/packages/extractors/python-dependencies/README.md b/packages/extractors/python-dependencies/README.md new file mode 100644 index 000000000..ebca89c4a --- /dev/null +++ b/packages/extractors/python-dependencies/README.md @@ -0,0 +1,173 @@ +--- +description: "Python projects and the packages their lockfile resolves (graph/v0)" +--- + +# Python dependencies — `graph/v0` + +Reads a Python project the way its package manager locked it: which projects +there are, what each declares, what the lockfile resolved each declaration to, +and what those packages depend on in turn, transitively. The result is the +dependency graph the `dependencies` renderer (part of the graph renderer) +presents, the same graph `workspace-dependencies`, `cargo-dependencies` and +`nuget-dependencies` draw for their ecosystems. + +It reads `uv.lock`, `poetry.lock`, `pdm.lock` and pinned requirements files +straight from the revision's files. It runs no Python, installs nothing and does +not require `--trust`. + +## Inputs + + +| Key | Meaning | +|---|---| +| `root` | Repository-relative project or workspace root. Default `"."`. The manifest, lockfile and requirements files are read relative to it. | +| `manager` | `uv`, `poetry`, `pdm` or `requirements`, overriding detection. | +| `requirements` | Requirements files (globs) relative to the root. Default every `requirements*.txt` in the root and `requirements/*.txt`. | + +A revision without a `pyproject.toml`, a lockfile or requirements files at the +root (before the project was added) has no packages. + +## Manager + +The files read are decided, in order, by `inputs.manager`; the one lockfile +present; of several, the one whose `[tool.uv]`, `[tool.poetry]` or `[tool.pdm]` +table the root `pyproject.toml` has (otherwise several lockfiles are an error +naming them); requirements files; and, with none of those, the manager the +manifest configures, without a lockfile. Requirements files are not read when a +lockfile is. + +| Manager | Lockfile | Projects and declarations | +| ------------ | --------------------------------------------- | ----------------------------------------------------------------------- | +| uv | `uv.lock` version 1 | The root and its `[tool.uv.workspace]` members; what uv locked for each | +| Poetry | `poetry.lock` lock-version 1.x and 2.x | The root's `pyproject.toml` | +| PDM | `pdm.lock` lock_version 4.x | The root's `pyproject.toml` | +| requirements | Pinned requirements files, and the `-r` files | The root's `pyproject.toml`, if any, and each file's pins | + +## Projects + +The root `pyproject.toml` names the project: `[project] name`, else +`[tool.poetry] name`. A uv workspace's members are the directories holding a +`pyproject.toml` that a `[tool.uv.workspace]` `members` glob matches and no +`exclude` glob does. A virtual workspace root (no name and nothing declared) is +not a project; requirements files without a `pyproject.toml` belong to an +unnamed root project. + +A project declares: + +- **`dependencies`**: PEP 621 `[project] dependencies`, else Poetry's + `[tool.poetry.dependencies]` (without its `python` constraint), as Poetry 2 + reads them. +- **`optionalDependencies`**, one per extra listing it: + `[project.optional-dependencies]`, or Poetry's optional dependencies and the + `[tool.poetry.extras]` naming them. +- **`devDependencies`**, one per dependency group: PEP 735 `[dependency-groups]` + (with `include-group` expanded), Poetry's + `[tool.poetry.group..dependencies]` and `[tool.poetry.dev-dependencies]` + (`dev`), PDM's `[tool.pdm.dev-dependencies]`, and uv's + `[tool.uv] dev-dependencies` (`dev`). + +uv locks each member's requirements itself, so a member's declarations come from +`uv.lock` (its `dependencies`, `optional-dependencies` and `dev-dependencies`, +labelled with the `requires-dist` and `requires-dev` specifiers), and a virtual +root's dependency groups from its `[manifest]`. Requirement strings that name no +package (PDM's `-e file:///…`) are left out. + +## Lockfiles + +Each lockfile is parsed, not resolved by running the manager: + +- **uv:** each `[[package]]` with its `dependencies` and + `optional-dependencies`. A dependency that names a `version` (uv forks the + resolution by Python version or platform) points at that copy. +- **Poetry:** each `[[package]]` with its `[package.dependencies]`; optional + ones are installed only for an extra of `[package.extras]` that names them. + Poetry doesn't record which of several locked copies of a name a dependency + uses, so a dependency on such a name points at every copy, and the limitation + says so. +- **PDM:** each `[[package]]` with its PEP 508 `dependencies`. PDM locks an + extra as its own entry with the extra's dependencies and the package itself; + those dependencies become the package's extra. +- **Requirements files:** each `name==version` (or `===`) line is a pinned + package and a direct dependency of the root project, with its extras and + marker; `-r` includes are read too, each file once. Requirements files record + no graph, except where `pip-compile` or `uv pip compile` annotated each pin + with what pulls it in (`# via httpx`): there a pin the annotation says another + pin pulls in is that pin's dependency, and only pins an input requires + (`# via -r requirements.in`, `# via app (pyproject.toml)`) or nothing + annotates are direct. Lines that don't pin one version (ranges, URLs, VCS + references and `-e` editable installs) are listed in `metadata.skipped`; + constraints (`-c`) and index options aren't requirements and are ignored. + +The packages in the graph are those a project reaches. A package's extras are +followed only where a dependency in the graph requests them (`httpx[http2]` adds +`h2`); a project's own extras and dependency groups are always included. +Environment markers (`python_version < "3.11"`, `sys_platform == "win32"`) are +recorded on relationships but not evaluated: the graph is the lockfile's +universal resolution, every platform and Python version at once. + +A declaration no lockfile entry resolves (a stale lockfile) points at a +`package:` without a version and is listed in `metadata.unresolved` +(`[, kind, group or file, name]`), as is a package's dependency the +lockfile doesn't have (`[, kind, extra, name]`). Without a lockfile, +declarations point at such packages and keep their declared ranges. A malformed +or unsupported lockfile is an error. + +## Model + + +| Entity | `id` | `kind` | `data` | +|---|---|---|---| +| Project | `project:` | `project` | `path`, `version` from its manifest | +| Project without a name (the root) | `project-root` | `project` | as above; labelled `(project root)` | +| Workspace member without a name | `project:./` | `project` | as above; labelled with its path | +| Package | `package:`; when several versions are locked at once, the copy most packages depend on keeps it (the lowest version of those tied) and each other copy is `package:@` (major version, or `0.`), or the full version if two share a line | `package` | `version`, and `source` (the registry URL, `git+`, or a local path) | + +Names are normalized as installers compare them (PEP 503: lowercase, runs of +`-`, `_` and `.` as one `-`), so `Typing_Extensions` and `typing-extensions` are +one package; labels keep the name as written. + +Each declaration is a relationship of its kind from the project, with ID +`dependency:["","",("",)""]` (the owner +is the project's normalized name, `.` for `project-root`, `./` for an +unnamed member), labelled with the declared specifier. Each reached package's +dependencies are `dependencies` relationships, and those its activated extras +add are `optionalDependencies`, with ID +`dependency:["","",("",)""]` and the lockfile as +evidence. Where one ID would name several relationships (a dependency on every +copy of a name, or one name listed twice for different environments), the one to +the copy with the plain ID keeps it and the others add their target's ID. + + +| `data` field | Meaning | +|---|---| +| `type` | The relationship kind. | +| `version` | The requested specifier, as written (`>=0.27,<1`, `^8.1`, `==2.32.3`); absent where the lockfile records none. | +| `resolved` | The locked version of the target, or the linked project's version (declarations only). | +| `extra` | The extra declaring it or adding it. | +| `group` | The dependency group declaring it. | +| `file` | The requirements file declaring it. | +| `extras` | Extras requested of the target (`["http2"]`). | +| `marker` | The environment marker, not evaluated. | + +Identities never contain versions, so an upgrade changes data rather than +identity and compares as a modification. + +`metadata` records the `manager`, the `lockfile` path and its `lockfileVersion`, +the `requirements` files read, `unresolved`, `skipped`, and `limitations`. +Entities and relationships are sorted by ID, so the same revision always +produces the same extraction. + +## Tests + +`tests/fixtures` holds a uv workspace (`uv-workspace`: a virtual root with a +dependency group that includes another, an excluded member, members depending on +each other and an extra requested of a dependency), a Poetry project (`poetry`: +an optional dependency behind an extra, a dependency group and an extra +requested of a dependency), a PDM project (`pdm`) and requirements files +(`requirements`: a `uv pip compile` output with `# via` annotations and a +hand-written file with an include, a range and an editable install). Their +lockfiles were written by uv, Poetry and PDM themselves with +`tests/fixtures/lock.mjs`, which also removes the index they resolved from. +`tests/lockfiles.rs` compares each with its golden `.expected.json`; +regenerate them with +`PROJECTIONS_UPDATE_GOLDEN=1 cargo test -p projections-extractor-python-dependencies`. diff --git a/packages/extractors/python-dependencies/src/graph.rs b/packages/extractors/python-dependencies/src/graph.rs new file mode 100644 index 000000000..126a5d8c8 --- /dev/null +++ b/packages/extractors/python-dependencies/src/graph.rs @@ -0,0 +1,503 @@ +//! The dependency graph: projects, the locked packages they reach (following +//! each package's extras only where something requests them), stable +//! identities that leave versions out, and the relationships between them. + +use crate::model::{DEV, Declaration, Dependency, Locked, Lockfile, OPTIONAL}; +use anyhow::{Result, bail}; +use serde_json::{Value, json}; +use std::cmp::Ordering; +use std::collections::{BTreeMap, BTreeSet}; + +/// A project: the root, or a uv workspace member. +pub(crate) struct Project { + /// The normalized name; `None` for a project without one (requirements files alone, or a virtual workspace root). + pub name: Option, + /// The name as written. + pub label: Option, + /// Its directory relative to the root; empty for the root. + pub directory: String, + /// Its `pyproject.toml`'s repository path. + pub manifest: Option, + pub version: Option, + pub declarations: Vec, +} + +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +enum Target { + Project(usize), + Package(usize), +} + +pub(crate) struct Graph { + pub entities: Vec, + pub relationships: Vec, + pub unresolved: Vec, +} + +struct Builder<'a> { + projects: &'a [Project], + packages: &'a [Locked], + /// Normalized project name to project. + named: BTreeMap<&'a str, usize>, + /// Normalized name to the locked packages that aren't projects. + by_name: BTreeMap<&'a str, Vec>, +} + +impl Builder<'_> { + /// What a dependency points at: the pinned package, a project of that name, + /// the locked copy of the version it names, else every locked copy of the name. + fn resolve(&self, dependency: &Dependency, pinned: Option) -> Vec { + if let Some(index) = pinned { + return vec![Target::Package(index)]; + } + if let Some(project) = self.named.get(dependency.name.as_str()) { + return vec![Target::Project(*project)]; + } + let Some(copies) = self.by_name.get(dependency.name.as_str()) else { + return vec![]; + }; + let exact: Vec = copies + .iter() + .filter(|i| Some(&self.packages[**i].version) == dependency.version.as_ref()) + .map(|i| Target::Package(*i)) + .collect(); + if exact.is_empty() { + copies.iter().map(|i| Target::Package(*i)).collect() + } else { + exact + } + } + + /// A package's dependencies with its activated extras' dependencies, each with the extra adding it. + fn active<'b>(&'b self, index: usize, extras: &'b BTreeSet) -> impl Iterator, &'b Dependency)> { + let package = &self.packages[index]; + let always = package.dependencies.iter().map(|d| (None, d)); + let added = extras.iter().flat_map(move |extra| { + package + .extras + .get(extra) + .into_iter() + .flatten() + .map(move |d| (Some(extra.as_str()), d)) + }); + always.chain(added) + } + + /// Every package the projects reach, with the extras something requests of it. + fn reached(&self) -> BTreeMap> { + let mut reached: BTreeMap> = BTreeMap::new(); + let mut queue: Vec<(usize, Vec)> = vec![]; + for declaration in self.projects.iter().flat_map(|p| &p.declarations) { + for target in self.resolve(&declaration.dependency, declaration.pinned) { + if let Target::Package(index) = target { + queue.push((index, declaration.dependency.extras.clone())); + } + } + } + while let Some((index, extras)) = queue.pop() { + let first = !reached.contains_key(&index); + let activated = reached.entry(index).or_default(); + let added: BTreeSet = extras.into_iter().filter(|e| activated.insert(e.clone())).collect(); + let package = &self.packages[index]; + let dependencies = package + .dependencies + .iter() + .filter(|_| first) + .chain(added.iter().flat_map(|extra| package.extras.get(extra).into_iter().flatten())); + for dependency in dependencies { + for target in self.resolve(dependency, None) { + if let Target::Package(next) = target { + queue.push((next, dependency.extras.clone())); + } + } + } + } + reached + } +} + +/// The graph of `projects` and what `lockfile` resolved for them. +pub(crate) fn build(projects: &[Project], lockfile: Option<&Lockfile>) -> Result { + let (project_ids, owners) = project_identities(projects)?; + let packages: &[Locked] = lockfile.map_or(&[], |l| &l.packages); + let named: BTreeMap<&str, usize> = projects + .iter() + .enumerate() + .filter_map(|(i, p)| p.name.as_deref().map(|name| (name, i))) + .collect(); + let mut by_name: BTreeMap<&str, Vec> = BTreeMap::new(); + for (index, package) in packages.iter().enumerate() { + if !named.contains_key(package.name.as_str()) { + by_name.entry(&package.name).or_default().push(index); + } + } + let builder = Builder { + projects, + packages, + named, + by_name, + }; + let reached = builder.reached(); + let package_ids = identities(&builder, &reached); + let target_id = |target: Target| match target { + Target::Project(i) => project_ids[i].clone(), + Target::Package(i) => package_ids[&i].clone(), + }; + let target_version = |target: Target| match target { + Target::Project(i) => projects[i].version.clone(), + Target::Package(i) => Some(packages[i].version.clone()).filter(|v| !v.is_empty()), + }; + + let mut entities = BTreeMap::new(); + for (index, project) in projects.iter().enumerate() { + let id = &project_ids[index]; + let label = match (&project.label, project.directory.as_str()) { + (Some(label), _) => label.clone(), + (None, "") => "(project root)".to_owned(), + (None, directory) => directory.to_owned(), + }; + let mut data = json!({"path":if project.directory.is_empty() {"."} else {&project.directory}}); + if let Some(version) = &project.version { + data["version"] = json!(version); + } + let mut entity = json!({"id":id,"kind":"project","label":label,"data":data,"confidence":"authoritative"}); + if let Some(manifest) = &project.manifest { + entity["evidence"] = json!([{"kind":"manifest","source":manifest}]); + } + entities.insert(id.clone(), entity); + } + let lockfile_evidence = json!([{"kind":"lockfile","source":lockfile.map(|l| &l.path)}]); + for index in reached.keys() { + let package = &packages[*index]; + let id = &package_ids[index]; + let mut data = json!({}); + if !package.version.is_empty() { + data["version"] = json!(package.version); + } + if let Some(source) = &package.source { + data["source"] = json!(source); + } + entities.insert( + id.clone(), + json!({"id":id,"kind":"package","label":package.label,"data":data,"confidence":"authoritative","evidence":lockfile_evidence}), + ); + } + + // Relationships by the ID their declaration gives them; several share one when a dependency points at several + // copies of a package, or a list names one package twice for different environments. + let mut grouped: BTreeMap, Value)>> = BTreeMap::new(); + let mut unresolved = vec![]; + let mut relate = |parts: Vec, from: &str, to: String, data: Value, label: Option<&String>, evidence: &Value| { + let mut relationship = + json!({"from":from,"to":to,"kind":data["type"],"data":data,"confidence":"authoritative","evidence":evidence}); + if let Some(label) = label { + relationship["label"] = json!(label); + } + grouped + .entry(format!("dependency:{}", json!(parts))) + .or_default() + .push((parts, relationship)); + }; + for (index, project) in projects.iter().enumerate() { + let from = &project_ids[index]; + for declaration in &project.declarations { + let dependency = &declaration.dependency; + let mut parts = vec![owners[index].clone(), declaration.kind.to_owned()]; + parts.extend(declaration.group.clone().or_else(|| declaration.file.clone())); + parts.push(dependency.name.clone()); + let mut targets = builder.resolve(dependency, declaration.pinned); + let mut data = data(declaration.kind, dependency); + match declaration.kind { + OPTIONAL => data["extra"] = json!(declaration.group), + DEV => data["group"] = json!(declaration.group), + _ => {} + } + if let Some(file) = &declaration.file { + data["file"] = json!(file); + } + if targets.is_empty() { + if lockfile.is_some() { + unresolved.push(json!(parts)); + } + let id = format!("package:{}", dependency.name); + entities + .entry(id.clone()) + .or_insert_with(|| json!({"id":id,"kind":"package","label":dependency.name,"data":{},"confidence":"authoritative"})); + relate(parts, from, id, data, dependency.specifier.as_ref(), &declaration.evidence); + continue; + } + targets.sort(); + for target in targets { + let mut data = data.clone(); + if let Some(version) = target_version(target) { + data["resolved"] = json!(version); + } + relate( + parts.clone(), + from, + target_id(target), + data, + dependency.specifier.as_ref(), + &declaration.evidence, + ); + } + } + } + for (index, extras) in &reached { + let from = &package_ids[index]; + for (extra, dependency) in builder.active(*index, extras) { + let kind = if extra.is_some() { OPTIONAL } else { crate::model::DEPENDENCIES }; + let mut parts = vec![from.clone(), kind.to_owned()]; + parts.extend(extra.map(str::to_owned)); + parts.push(dependency.name.clone()); + let targets = builder.resolve(dependency, None); + if targets.is_empty() { + unresolved.push(json!(parts)); + continue; + } + let mut data = data(kind, dependency); + if let Some(extra) = extra { + data["extra"] = json!(extra); + } + for target in targets { + relate( + parts.clone(), + from, + target_id(target), + data.clone(), + dependency.specifier.as_ref(), + &lockfile_evidence, + ); + } + } + } + // Of relationships sharing an ID, the one to the copy with the plain ID keeps it and the others add their target, so + // IDs don't depend on the order the lockfile lists copies in. + let mut relationships = BTreeMap::new(); + for (id, mut group) in grouped { + group.sort_by(|(_, a), (_, b)| { + let to = |r: &Value| r["to"].as_str().unwrap_or_default().to_owned(); + (to(a).len(), to(a)).cmp(&(to(b).len(), to(b))) + }); + for (position, (mut parts, mut relationship)) in group.into_iter().enumerate() { + let id = if position == 0 { + id.clone() + } else { + parts.push(relationship["to"].as_str().unwrap_or_default().to_owned()); + format!("dependency:{}", json!(parts)) + }; + relationship["id"] = json!(id); + relationships.insert(id, relationship); + } + } + Ok(Graph { + entities: entities.into_values().collect(), + relationships: relationships.into_values().collect(), + unresolved, + }) +} + +/// A relationship's data: its kind, the requested specifier, the extras it requests and its marker. +fn data(kind: &str, dependency: &Dependency) -> Value { + let mut data = json!({"type":kind}); + if let Some(specifier) = &dependency.specifier { + data["version"] = json!(specifier); + } + if !dependency.extras.is_empty() { + data["extras"] = json!(dependency.extras); + } + if let Some(marker) = &dependency.marker { + data["marker"] = json!(marker); + } + data +} + +/// Each project's ID and the owner its relationships' IDs name: `project:` +/// owned by its name; a root without a name is `project-root`, owned by `.`; +/// a member without one is `project:./`, owned by `./`. +fn project_identities(projects: &[Project]) -> Result<(Vec, Vec)> { + let mut seen: BTreeMap<&str, &Project> = BTreeMap::new(); + let (mut ids, mut owners) = (vec![], vec![]); + for project in projects { + let owner = match (&project.name, project.directory.as_str()) { + (Some(name), _) => { + if let Some(other) = seen.insert(name, project) { + bail!( + "Two Python projects are named {name}: {} and {}. Projects are identified by name, so each needs its own", + other.manifest.as_deref().unwrap_or("."), + project.manifest.as_deref().unwrap_or(".") + ); + } + name.clone() + } + (None, "") => { + ids.push("project-root".to_owned()); + owners.push(".".to_owned()); + continue; + } + (None, directory) => format!("./{directory}"), + }; + ids.push(format!("project:{owner}")); + owners.push(owner); + } + Ok((ids, owners)) +} + +/// Stable IDs for the reached packages that leave the version out, so an +/// upgrade is one modified package: `package:`. When a name is locked at +/// several versions at once (uv forks the resolution by Python version or +/// platform), the copy most packages depend on keeps `package:` (the +/// lowest version of those tied), so the copy already there keeps its ID when +/// another version appears beside it, and each other copy is +/// `package:@` by compatible line, or by full version if two share one. +fn identities(builder: &Builder, reached: &BTreeMap>) -> BTreeMap { + let mut dependents: BTreeMap = BTreeMap::new(); + let declared = builder + .projects + .iter() + .flat_map(|p| &p.declarations) + .flat_map(|d| builder.resolve(&d.dependency, d.pinned)); + let transitive = reached + .iter() + .flat_map(|(index, extras)| builder.active(*index, extras).map(|(_, d)| d).collect::>()) + .flat_map(|d| builder.resolve(d, None)); + for target in declared.chain(transitive) { + if let Target::Package(index) = target { + *dependents.entry(index).or_default() += 1; + } + } + let packages = builder.packages; + let mut by_name: BTreeMap<&str, Vec> = BTreeMap::new(); + for index in reached.keys() { + by_name.entry(&packages[*index].name).or_default().push(*index); + } + let mut ids = BTreeMap::new(); + for (name, indexes) in by_name { + let count = |index: &usize| dependents.get(index).copied().unwrap_or(0); + let primary = indexes + .iter() + .copied() + .min_by(|a, b| { + count(b) + .cmp(&count(a)) + .then_with(|| compare_versions(&packages[*a].version, &packages[*b].version)) + }) + .expect("a name has a package"); + ids.insert(primary, format!("package:{name}")); + let lines: BTreeSet = indexes.iter().map(|i| compatible_line(&packages[*i].version)).collect(); + for index in indexes.iter().copied().filter(|index| *index != primary) { + let version = &packages[index].version; + let suffix = if lines.len() == indexes.len() { + compatible_line(version) + } else { + version.clone() + }; + ids.insert(index, format!("package:{name}@{suffix}")); + } + } + ids +} + +/// The release line versions are told apart by: the major version, or `0.` before 1.0. +fn compatible_line(version: &str) -> String { + let release = version.split(['+', '!']).next_back().unwrap_or(version); + let parts: Vec<&str> = release + .split('.') + .map(|part| part.trim_end_matches(|c: char| !c.is_ascii_digit())) + .collect(); + match parts.as_slice() { + ["0", minor, ..] => format!("0.{minor}"), + [major, ..] if !major.is_empty() => (*major).to_owned(), + _ => version.to_owned(), + } +} + +/// A PEP 440 version's ordering key: epoch, release, then development releases +/// before pre-releases (`a`, `b`, `rc`) before the release before its post-releases. +fn version_key(version: &str) -> Option<(u64, Vec, (u8, u8, u64), Option, (bool, u64))> { + let version = version.trim().to_ascii_lowercase(); + let version = version.split('+').next().unwrap_or_default(); + let (epoch, version) = match version.split_once('!') { + Some((epoch, rest)) => (epoch.parse().ok()?, rest), + None => (0, version), + }; + let end = version.find(|c: char| !(c.is_ascii_digit() || c == '.')).unwrap_or(version.len()); + let mut release: Vec = version[..end] + .trim_end_matches('.') + .split('.') + .map(|part| part.parse().ok()) + .collect::>()?; + while release.len() > 1 && release.last() == Some(&0) { + release.pop(); + } + let rest = version[end..].trim_start_matches(['.', '-', '_']); + let number = |text: &str| text.trim_start_matches(['.', '-', '_']).parse::().unwrap_or(0); + let (mut pre, mut post, mut dev) = (None, None, None); + let mut remaining = rest; + while !remaining.is_empty() { + let letters = remaining + .find(|c: char| c.is_ascii_digit() || matches!(c, '.' | '-' | '_')) + .unwrap_or(remaining.len()); + let (word, tail) = remaining.split_at(letters); + let digits_end = tail + .trim_start_matches(['.', '-', '_']) + .find(|c: char| !c.is_ascii_digit()) + .map_or(tail.len(), |i| i + tail.len() - tail.trim_start_matches(['.', '-', '_']).len()); + let value = number(&tail[..digits_end]); + match word { + "a" | "alpha" => pre = Some((0, value)), + "b" | "beta" => pre = Some((1, value)), + "rc" | "c" | "pre" | "preview" => pre = Some((2, value)), + "post" | "rev" | "r" | "" => post = Some(value), + "dev" => dev = Some(value), + _ => return None, + } + remaining = tail[digits_end..].trim_start_matches(['.', '-', '_']); + } + let phase = match (pre, post, dev) { + (None, None, Some(_)) => (0, 0, 0), + (Some((rank, n)), _, _) => (1, rank, n), + _ => (2, 0, 0), + }; + Some((epoch, release, phase, post, (dev.is_none(), dev.unwrap_or(0)))) +} + +/// Two versions in PEP 440 order; versions that aren't PEP 440, and ties, by text. +fn compare_versions(a: &str, b: &str) -> Ordering { + match (version_key(a), version_key(b)) { + (Some(left), Some(right)) => left.cmp(&right), + _ => Ordering::Equal, + } + .then_with(|| a.cmp(b)) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn versions_follow_pep_440() { + for (lower, higher) in [ + ("1.0.dev1", "1.0a1"), + ("1.0a1", "1.0b2"), + ("1.0b2", "1.0rc1"), + ("1.0rc1", "1.0"), + ("1.0", "1.0.post1"), + ("1.0", "1.0.1"), + ("2.0", "10.0"), + ("1.0.post1.dev0", "1.0.post1"), + ("2024.10", "1!0.1"), + ] { + assert_eq!(compare_versions(lower, higher), Ordering::Less, "{lower} < {higher}"); + } + assert_eq!(version_key("1.0"), version_key("1.0.0")); + } + + #[test] + fn copies_are_told_apart_by_their_line() { + assert_eq!(compatible_line("2.1.3"), "2"); + assert_eq!(compatible_line("0.27.2"), "0.27"); + assert_eq!(compatible_line("2024.10.1"), "2024"); + assert_eq!(compatible_line("1!3.0"), "3"); + } +} diff --git a/packages/extractors/python-dependencies/src/lib.rs b/packages/extractors/python-dependencies/src/lib.rs new file mode 100644 index 000000000..186609950 --- /dev/null +++ b/packages/extractors/python-dependencies/src/lib.rs @@ -0,0 +1,336 @@ +//! Python projects and the packages their lockfile resolves: `uv.lock`, +//! `poetry.lock`, `pdm.lock` or pinned requirements files, read from the +//! revision's files without Python and without installing anything. + +mod graph; +mod lockfile; +mod model; +mod pyproject; +mod requirement; + +use anyhow::{Result, bail}; +use graph::Project; +use model::{Declaration, Lockfile}; +use projections_extractor_sdk::{Context, Descriptor, Trust, extraction, glob, input, repository_path, strings}; +use pyproject::Manifest; +use serde_json::{Value, json}; +use std::collections::BTreeSet; + +pub const ID: &str = "python-dependencies"; + +/// The lockfiles read, in the order a tie is reported. +const LOCKFILES: [&str; 3] = ["uv.lock", "poetry.lock", "pdm.lock"]; + +pub fn descriptor() -> Descriptor { + Descriptor { + id: ID, + title: "Python dependencies", + description: "Python projects and the packages uv.lock, poetry.lock, pdm.lock or pinned requirements files resolve for them", + schema: "graph/v0", + renderer: "dependencies", + trust: Trust::None, + access: projections_extractor_sdk::Access::Files, + determinism: projections_extractor_sdk::Determinism::Pure, + inputs: json!({ + "root":"Repository-relative project or workspace root; default \".\"", + "manager":"uv, poetry, pdm or requirements; default from the lockfile present", + "requirements":"Array of requirements files relative to the root; default requirements*.txt and requirements/*.txt" + }), + template_inputs: None, + template_execution: None, + detects: &[ + "pyproject.toml", + "uv.lock", + "poetry.lock", + "pdm.lock", + "requirements*.txt", + "requirements/*.txt", + "**/pyproject.toml", + "**/uv.lock", + "**/poetry.lock", + "**/pdm.lock", + ], + } +} + +pub fn requires_trust(_inputs: &Value) -> bool { + false +} + +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +enum Manager { + Uv, + Poetry, + Pdm, + Requirements, +} + +impl Manager { + const ALL: [Manager; 4] = [Manager::Uv, Manager::Poetry, Manager::Pdm, Manager::Requirements]; + + fn name(self) -> &'static str { + match self { + Manager::Uv => "uv", + Manager::Poetry => "poetry", + Manager::Pdm => "pdm", + Manager::Requirements => "requirements", + } + } + + fn lockfile(self) -> Option<&'static str> { + match self { + Manager::Uv => Some("uv.lock"), + Manager::Poetry => Some("poetry.lock"), + Manager::Pdm => Some("pdm.lock"), + Manager::Requirements => None, + } + } +} + +/// The manager whose files are read: `inputs.manager`; the one lockfile +/// present; of several, the one whose `[tool.]` table the root +/// manifest has; requirements files; else, without a lockfile, the manager the +/// manifest configures, if any. +fn manager(definition: &Value, manifest: Option<&Manifest>, lockfiles: &[&str], requirements: bool) -> Result> { + if definition["inputs"].get("manager").is_some() { + let name = input(definition, "manager", None)?; + return match Manager::ALL.into_iter().find(|m| m.name() == name) { + Some(manager) => Ok(Some(manager)), + None => bail!("inputs.manager must be uv, poetry, pdm or requirements, not {name}"), + }; + } + let configured = |manager: Manager| manifest.is_some_and(|m| m.document["tool"].get(manager.name()).is_some()); + let locked: Vec = Manager::ALL + .into_iter() + .filter(|m| m.lockfile().is_some_and(|file| lockfiles.contains(&file))) + .collect(); + match locked.as_slice() { + [one] => return Ok(Some(*one)), + [] => {} + several => { + let hinted: Vec = several.iter().copied().filter(|m| configured(*m)).collect(); + if let [one] = hinted.as_slice() { + return Ok(Some(*one)); + } + bail!( + "Several lockfiles ({}): set inputs.manager to the one to read", + lockfiles.join(", ") + ); + } + } + if requirements { + return Ok(Some(Manager::Requirements)); + } + Ok([Manager::Uv, Manager::Poetry, Manager::Pdm].into_iter().find(|m| configured(*m))) +} + +pub fn collect(cx: &Context) -> Result { + let (files, definition) = (cx.files()?, cx.definition()); + let prefix = repository_path(input(definition, "root", Some("."))?)?; + let base = if prefix.is_empty() { String::new() } else { format!("{prefix}/") }; + let present: BTreeSet<&str> = files.iter().map(String::as_str).collect(); + let read = |file: &str| -> Result> { + if present.contains(file) { + Ok(Some(cx.read_source(file)?)) + } else { + Ok(None) + } + }; + let manifest_path = format!("{base}pyproject.toml"); + let manifest = match read(&manifest_path)? { + Some(text) => Some(Manifest { + document: lockfile::toml(&text, &manifest_path)?, + path: manifest_path, + }), + None => None, + }; + let lockfiles: Vec<&str> = LOCKFILES + .into_iter() + .filter(|name| present.contains(format!("{base}{name}").as_str())) + .collect(); + let requirement_files = requirement_files(definition, files, &base)?; + // A revision without the project (before it was added) has no packages. + if manifest.is_none() && lockfiles.is_empty() && requirement_files.is_empty() { + return Ok(extraction("graph/v0", vec![], vec![], None)); + } + let manager = manager(definition, manifest.as_ref(), &lockfiles, !requirement_files.is_empty())?; + let mut projects = projects(cx, files, &base, manifest.as_ref())?; + let lockfile = match manager { + Some(Manager::Requirements) => Some(lockfile::requirements::parse(&requirement_files, &read)?), + Some(manager) => { + let name = manager.lockfile().unwrap_or_default(); + let path = format!("{base}{name}"); + match read(&path)? { + Some(text) => Some(match manager { + Manager::Uv => lockfile::uv::parse(&path, &text)?, + Manager::Poetry => lockfile::poetry::parse(&path, &text)?, + _ => lockfile::pdm::parse(&path, &text)?, + }), + None => None, + } + } + None => None, + }; + if let Some(lockfile) = &lockfile { + apply(&mut projects, lockfile); + } + let graph = graph::build(&projects, lockfile.as_ref())?; + + let mut metadata = json!({ + "manager": manager.map(Manager::name), + "lockfile": lockfile.as_ref().filter(|_| manager != Some(Manager::Requirements)).map(|l| &l.path), + "unresolved": graph.unresolved, + }); + if let Some(version) = lockfile.as_ref().and_then(|l| l.version.clone()) { + metadata["lockfileVersion"] = version; + } + let mut limitations: Vec<&str> = vec![]; + match (manager, &lockfile) { + (Some(Manager::Requirements), Some(lockfile)) => { + metadata["requirements"] = json!(requirement_files); + limitations.push( + "Requirements files record no dependency graph: each pinned requirement is a direct dependency of the project, unless `# via` annotations from pip-compile or uv pip compile say what pulls it in. Packages the files don't pin aren't in the graph.", + ); + if !lockfile.skipped.is_empty() { + metadata["skipped"] = json!(lockfile.skipped); + limitations.push( + "Requirement lines that don't pin one version with `==` (ranges, URLs, editable installs) aren't in the graph; metadata.skipped lists them.", + ); + } + } + (_, Some(lockfile)) => { + limitations.push( + "Every extra and dependency group a project declares is included; a package's extras are followed only where a dependency in the graph requests them.", + ); + if manager != Some(Manager::Uv) && locked_more_than_once(lockfile) { + limitations.push( + "The lockfile doesn't record which copy of a package locked at several versions each dependency uses, so a dependency on one points at every copy.", + ); + } + } + (_, None) => limitations.push( + "No lockfile was read, so dependencies show their declared ranges without resolved versions or the packages they pull in.", + ), + } + limitations.push( + "Environment markers are recorded on relationships as `marker` but not evaluated: the graph covers every platform and Python version at once.", + ); + metadata["limitations"] = json!(limitations); + Ok(extraction("graph/v0", graph.entities, graph.relationships, Some(metadata))) +} + +/// `inputs.requirements` (relative to the root), else the root's +/// `requirements*.txt` and `requirements/*.txt`, `requirements.txt` first. +fn requirement_files(definition: &Value, files: &[String], base: &str) -> Result> { + if let Some(value) = definition["inputs"].get("requirements") { + let mut selected = vec![]; + for name in strings(value, "inputs.requirements")? { + let pattern = glob(&format!("{base}{}", repository_path(&name)?))?; + selected.extend(files.iter().filter(|file| pattern.is_match(file)).cloned()); + } + selected.dedup(); + return Ok(selected); + } + let mut selected: Vec = files + .iter() + .filter(|file| { + let Some(relative) = file.strip_prefix(base) else { + return false; + }; + let in_directory = relative.strip_prefix("requirements/").is_some_and(|name| !name.contains('/')); + relative.ends_with(".txt") && (in_directory || (relative.starts_with("requirements") && !relative.contains('/'))) + }) + .cloned() + .collect(); + selected.sort_by_key(|file| (!file.ends_with("/requirements.txt") && file != "requirements.txt", file.clone())); + Ok(selected) +} + +/// The root project and, for a uv workspace, its members: each directory with a +/// `pyproject.toml` that a `members` glob matches and no `exclude` glob does. +/// The root is a project when it is named, declares dependencies, or has no members. +fn projects(cx: &Context, files: &[String], base: &str, manifest: Option<&Manifest>) -> Result> { + let Some(manifest) = manifest else { + return Ok(vec![Project { + name: None, + label: None, + directory: String::new(), + manifest: None, + version: None, + declarations: vec![], + }]); + }; + let mut projects = vec![project(manifest, "")?]; + if let Some((members, exclude)) = manifest.workspace() { + let members = members.iter().map(|g| glob(g.trim_end_matches('/'))).collect::>>()?; + let exclude = exclude.iter().map(|g| glob(g.trim_end_matches('/'))).collect::>>()?; + let mut directories: Vec<&str> = files + .iter() + .filter_map(|file| file.strip_prefix(base)?.strip_suffix("/pyproject.toml")) + .filter(|directory| members.iter().any(|g| g.is_match(directory)) && !exclude.iter().any(|g| g.is_match(directory))) + .collect(); + directories.sort(); + for directory in directories { + let path = format!("{base}{directory}/pyproject.toml"); + let member = Manifest { + document: lockfile::toml(&cx.read_source(&path)?, &path)?, + path, + }; + projects.push(project(&member, directory)?); + } + let root = &projects[0]; + if root.name.is_none() && root.declarations.is_empty() && projects.len() > 1 { + projects.remove(0); + } + } + Ok(projects) +} + +fn project(manifest: &Manifest, directory: &str) -> Result { + Ok(Project { + name: manifest.name().map(requirement::normalize), + label: manifest.name().map(str::to_owned), + directory: directory.to_owned(), + manifest: Some(manifest.path.clone()), + version: manifest.version().map(str::to_owned), + declarations: manifest.declarations()?, + }) +} + +/// What the lockfile records the projects declaring: a uv member's resolved +/// requirements replace its manifest's, and the root's (a virtual workspace's +/// dependency groups, requirements files' pins) are added to the root project. +fn apply(projects: &mut Vec, lockfile: &Lockfile) { + for project in projects.iter_mut() { + if let Some(declarations) = project.name.as_ref().and_then(|name| lockfile.projects.get(name)) { + project.declarations = declarations.clone(); + } + } + if lockfile.root.is_empty() { + return; + } + if projects.first().is_none_or(|p| !p.directory.is_empty()) { + projects.insert( + 0, + Project { + name: None, + label: None, + directory: String::new(), + manifest: None, + version: None, + declarations: vec![], + }, + ); + } + let root: &mut Vec = &mut projects[0].declarations; + // A uv lockfile records what a virtual root's manifest declares; requirements files add to it. + if lockfile.root.iter().all(|d| d.file.is_none()) { + root.clear(); + } + root.extend(lockfile.root.iter().cloned()); +} + +fn locked_more_than_once(lockfile: &Lockfile) -> bool { + let mut names = BTreeSet::new(); + lockfile.packages.iter().any(|p| !names.insert(p.name.as_str())) +} diff --git a/packages/extractors/python-dependencies/src/lockfile.rs b/packages/extractors/python-dependencies/src/lockfile.rs new file mode 100644 index 000000000..17f3c05f4 --- /dev/null +++ b/packages/extractors/python-dependencies/src/lockfile.rs @@ -0,0 +1,26 @@ +//! The lockfiles: uv's `uv.lock`, Poetry's `poetry.lock`, PDM's `pdm.lock`, +//! and pinned requirements files. + +pub(crate) mod pdm; +pub(crate) mod poetry; +pub(crate) mod requirements; +pub(crate) mod uv; + +use anyhow::{Context as _, Result}; +use serde_json::Value; + +/// A TOML document as JSON values. +pub(crate) fn toml(text: &str, file: &str) -> Result { + toml::from_str::(text).with_context(|| format!("{file} is not valid TOML")) +} + +/// The strings of an optional array. +pub(crate) fn strings(value: &Value) -> Vec { + value + .as_array() + .into_iter() + .flatten() + .filter_map(Value::as_str) + .map(str::to_owned) + .collect() +} diff --git a/packages/extractors/python-dependencies/src/lockfile/pdm.rs b/packages/extractors/python-dependencies/src/lockfile/pdm.rs new file mode 100644 index 000000000..e80c3b255 --- /dev/null +++ b/packages/extractors/python-dependencies/src/lockfile/pdm.rs @@ -0,0 +1,85 @@ +//! `pdm.lock`, lock versions 4.x: every locked package and its dependencies. +//! PDM locks an extra as its own entry (`name`, `version` and `extras`) whose +//! dependencies are the extra's and the package itself; those become the +//! package's extras. The project isn't locked: what it declares comes from +//! `pyproject.toml`. + +use super::toml; +use crate::model::{Dependency, Locked, Lockfile}; +use crate::requirement::{self, normalize}; +use anyhow::{Context as _, Result, ensure}; +use serde_json::Value; +use std::collections::BTreeMap; + +pub(crate) fn parse(path: &str, text: &str) -> Result { + let document = toml(text, path)?; + let version = &document["metadata"]["lock_version"]; + ensure!( + version.as_str().is_some_and(|v| v.starts_with("4.")), + "{path}: unsupported pdm.lock lock_version {version}; expected 4.x" + ); + let mut lockfile = Lockfile { + path: path.to_owned(), + version: Some(version.clone()), + ..Lockfile::default() + }; + // (name, version) to package index; extras entries wait for their package. + let mut index: BTreeMap<(String, String), usize> = BTreeMap::new(); + let mut variants = vec![]; + for package in document["package"].as_array().into_iter().flatten() { + let label = package["name"].as_str().with_context(|| format!("{path}: a package has no name"))?; + let version = package["version"].as_str().unwrap_or_default(); + let name = normalize(label); + let dependencies: Vec = super::strings(&package["dependencies"]) + .iter() + .filter_map(|text| requirement::parse(text)) + .map(|r| Dependency { + name: r.name, + version: None, + specifier: r.specifier.or(r.url), + extras: r.extras, + marker: r.marker, + }) + .collect(); + let extras = super::strings(&package["extras"]); + if !extras.is_empty() { + variants.push((name, version.to_owned(), label.to_owned(), extras, dependencies)); + continue; + } + index.insert((name.clone(), version.to_owned()), lockfile.packages.len()); + lockfile.packages.push(Locked { + name, + label: label.to_owned(), + version: version.to_owned(), + source: source(package), + dependencies, + extras: BTreeMap::new(), + }); + } + for (name, version, label, extras, dependencies) in variants { + let at = *index.entry((name.clone(), version.clone())).or_insert_with(|| { + lockfile.packages.push(Locked { + name: name.clone(), + label, + version, + ..Locked::default() + }); + lockfile.packages.len() - 1 + }); + // The extra's own entry depends on the package itself, which is no dependency. + let added: Vec = dependencies.into_iter().filter(|d| d.name != name).collect(); + for extra in extras { + lockfile.packages[at].extras.insert(normalize(&extra), added.clone()); + } + } + Ok(lockfile) +} + +/// Where a package comes from, when not a registry: `git+`, a URL, or `path `. +fn source(package: &Value) -> Option { + let text = |key: &str| package[key].as_str(); + text("git") + .map(|url| format!("git+{url}")) + .or_else(|| text("url").map(str::to_owned)) + .or_else(|| text("path").map(|path| format!("path {path}"))) +} diff --git a/packages/extractors/python-dependencies/src/lockfile/poetry.rs b/packages/extractors/python-dependencies/src/lockfile/poetry.rs new file mode 100644 index 000000000..7fbb89d1e --- /dev/null +++ b/packages/extractors/python-dependencies/src/lockfile/poetry.rs @@ -0,0 +1,80 @@ +//! `poetry.lock`, lock versions 1.x and 2.x: every locked package, its +//! dependencies (optional ones installed only for an extra) and its extras. +//! The project itself isn't locked: what it declares comes from `pyproject.toml`. + +use super::toml; +use crate::model::{Dependency, Locked, Lockfile}; +use crate::pyproject::poetry_dependency; +use crate::requirement::{self, normalize}; +use anyhow::{Context as _, Result, ensure}; +use serde_json::Value; +use std::collections::BTreeMap; + +pub(crate) fn parse(path: &str, text: &str) -> Result { + let document = toml(text, path)?; + let version = &document["metadata"]["lock-version"]; + ensure!( + version.as_str().is_some_and(|v| v.starts_with("1.") || v.starts_with("2.")), + "{path}: unsupported poetry.lock lock-version {version}; expected 1.x or 2.x" + ); + let mut lockfile = Lockfile { + path: path.to_owned(), + version: Some(version.clone()), + ..Lockfile::default() + }; + for package in document["package"].as_array().into_iter().flatten() { + let label = package["name"].as_str().with_context(|| format!("{path}: a package has no name"))?; + let version = package["version"] + .as_str() + .with_context(|| format!("{path}: package {label} has no version"))?; + let mut dependencies = vec![]; + let mut optional: BTreeMap = BTreeMap::new(); + for (name, value) in package["dependencies"].as_object().into_iter().flatten() { + let (dependency, is_optional) = poetry_dependency(name, value); + if is_optional { + optional.insert(dependency.name.clone(), dependency); + } else { + dependencies.push(dependency); + } + } + let mut extras = BTreeMap::new(); + for (extra, requirements) in package["extras"].as_object().into_iter().flatten() { + let mut list = vec![]; + for text in super::strings(requirements) { + let Some(named) = requirement::parse(&text) else { + continue; + }; + // The dependency table says what the extra's dependency requires; the extra only names it. + list.push(optional.get(&named.name).cloned().unwrap_or(Dependency { + name: named.name, + version: None, + specifier: named.specifier, + extras: named.extras, + marker: named.marker, + })); + } + extras.insert(normalize(extra), list); + } + lockfile.packages.push(Locked { + name: normalize(label), + label: label.to_owned(), + version: version.to_owned(), + source: source(&package["source"]), + dependencies, + extras, + }); + } + Ok(lockfile) +} + +/// `[package.source]`: `git+` for Git, ` ` for a local +/// directory or file, else the URL of a legacy repository or archive. +fn source(source: &Value) -> Option { + let kind = source["type"].as_str()?; + let url = source["url"].as_str().unwrap_or_default(); + Some(match kind { + "git" => format!("git+{url}"), + "directory" | "file" => format!("{kind} {url}"), + _ => url.to_owned(), + }) +} diff --git a/packages/extractors/python-dependencies/src/lockfile/requirements.rs b/packages/extractors/python-dependencies/src/lockfile/requirements.rs new file mode 100644 index 000000000..34dee1b23 --- /dev/null +++ b/packages/extractors/python-dependencies/src/lockfile/requirements.rs @@ -0,0 +1,277 @@ +//! Requirements files: each `name==version` line is a pinned package and a +//! direct dependency of the project. A requirements file records no graph, +//! except where `pip-compile` or `uv pip compile` annotated each pin with what +//! pulls it in (`# via httpx`); there, pins another pin pulls in are its +//! dependencies, and only pins the input requires are direct. + +use crate::model::{DEPENDENCIES, Declaration, Dependency, Locked, Lockfile}; +use crate::requirement; +use anyhow::Result; +use projections_extractor_sdk::parent; +use serde_json::json; +use std::collections::{BTreeMap, BTreeSet, VecDeque}; + +/// One pinned requirement line. +struct Pin { + name: String, + label: String, + version: String, + extras: Vec, + marker: Option, + line: usize, + /// Packages a `# via` annotation names. + via: Vec, + /// Whether the annotation names an input (`-r requirements.in`, `fastapi (pyproject.toml)`). + required: bool, +} + +/// Reads `files` (repository paths) and the files they include with `-r`, each +/// once, in order. `read` returns a file's text, or `None` when the revision +/// doesn't have it. +pub(crate) fn parse(files: &[String], read: &dyn Fn(&str) -> Result>) -> Result { + let mut lockfile = Lockfile { + path: files.first().cloned().unwrap_or_default(), + ..Lockfile::default() + }; + let mut queue: VecDeque = files.iter().cloned().collect(); + let mut seen = BTreeSet::new(); + let mut index: BTreeMap<(String, String), usize> = BTreeMap::new(); + while let Some(file) = queue.pop_front() { + if !seen.insert(file.clone()) { + continue; + } + let Some(text) = read(&file)? else { + lockfile.skipped.push(json!([file, "(not in this revision)"])); + continue; + }; + let (pins, includes, skipped) = lines(&file, &text); + queue.extend(includes); + lockfile.skipped.extend(skipped.into_iter().map(|line| json!([file, line]))); + let annotated = pins.iter().any(|pin| !pin.via.is_empty() || pin.required); + let mut here: BTreeMap = BTreeMap::new(); + for pin in &pins { + let at = *index.entry((pin.name.clone(), pin.version.clone())).or_insert_with(|| { + lockfile.packages.push(Locked { + name: pin.name.clone(), + label: pin.label.clone(), + version: pin.version.clone(), + ..Locked::default() + }); + lockfile.packages.len() - 1 + }); + here.insert(pin.name.clone(), at); + } + for pin in &pins { + let pulled_by: Vec = pin.via.iter().filter_map(|name| here.get(name).copied()).collect(); + let dependency = Dependency { + name: pin.name.clone(), + version: Some(pin.version.clone()), + specifier: Some(format!("=={}", pin.version)), + extras: pin.extras.clone(), + marker: pin.marker.clone(), + }; + for from in &pulled_by { + let dependencies = &mut lockfile.packages[*from].dependencies; + if !dependencies.iter().any(|d| d.name == pin.name) { + dependencies.push(dependency.clone()); + } + } + if !annotated || pin.required || pulled_by.is_empty() { + lockfile.root.push(Declaration { + kind: DEPENDENCIES, + group: None, + file: Some(file.clone()), + dependency, + pinned: Some(here[&pin.name]), + evidence: json!([{"kind":"requirements","source":file,"location":{"line":pin.line}}]), + }); + } + } + } + Ok(lockfile) +} + +/// A file's pins, the files it includes (`-r`), and the requirement lines it +/// has that aren't pins: ranges, URLs and editable installs. +fn lines(file: &str, text: &str) -> (Vec, Vec, Vec) { + let (mut pins, mut includes, mut skipped) = (Vec::::new(), vec![], vec![]); + // Whether comment lines continue the last pin's `# via` annotation. + let mut via = false; + let mut logical = String::new(); + let mut start = 0; + for (number, raw) in text.lines().enumerate() { + let trimmed = raw.trim(); + if logical.is_empty() { + start = number + 1; + } + if let Some(comment) = trimmed.strip_prefix('#') { + let comment = comment.trim(); + let Some(pin) = pins.last_mut() else { continue }; + let items = match comment.strip_prefix("via") { + Some(rest) if rest.is_empty() || rest.starts_with(' ') => { + via = true; + rest.trim() + } + _ if via => comment, + _ => continue, + }; + if items.is_empty() { + continue; + } + if items.starts_with("-r") || items.starts_with("--requirement") || items.contains('(') { + pin.required = true; + } else if !items.starts_with('-') { + pin.via.extend(items.split(',').map(|item| requirement::normalize(item))); + } + continue; + } + via = false; + if let Some(continued) = trimmed.strip_suffix('\\') { + logical.push_str(continued); + logical.push(' '); + continue; + } + logical.push_str(trimmed); + let line = std::mem::take(&mut logical); + // An inline comment starts with whitespace and `#`. + let line = line.split(" #").next().unwrap_or_default().trim(); + if line.is_empty() { + continue; + } + if let Some(option) = line.strip_prefix('-') { + let (flag, value) = option + .split_once([' ', '=']) + .map_or((option, ""), |(flag, value)| (flag, value.trim())); + match flag { + "r" | "-requirement" => includes.push(relative(file, value)), + _ if flag.starts_with('r') && value.is_empty() => includes.push(relative(file, &flag[1..])), + "e" | "-editable" => skipped.push(line.to_owned()), + // Constraints, indexes and other options aren't requirements. + _ => {} + } + continue; + } + // Per-requirement options (`--hash=…`) follow the requirement. + let requirement_text = line.split(" --").next().unwrap_or_default().trim(); + let pinned = requirement::parse(requirement_text).and_then(|r| { + let specifier = r.specifier.as_deref()?; + let version = specifier + .strip_prefix("===") + .or_else(|| specifier.strip_prefix("=="))? + .trim() + .to_owned(); + let exact = !version.is_empty() && !version.contains([',', '*', ' ']); + exact.then_some((version, r)) + }); + match pinned { + Some((version, r)) => { + let label = requirement_text + .split(|c: char| !(c.is_ascii_alphanumeric() || matches!(c, '-' | '_' | '.'))) + .next() + .unwrap_or_default() + .to_owned(); + pins.push(Pin { + name: r.name, + label, + version, + extras: r.extras, + marker: r.marker, + line: start, + via: vec![], + required: false, + }); + } + None => skipped.push(requirement_text.to_owned()), + } + } + (pins, includes, skipped) +} + +/// `include`, named relative to the file including it, as a repository path. +fn relative(file: &str, include: &str) -> String { + let directory = parent(file); + let mut parts: Vec<&str> = if directory == "." { vec![] } else { directory.split('/').collect() }; + for part in include.trim().split('/') { + match part { + "" | "." => {} + ".." => { + parts.pop(); + } + part => parts.push(part), + } + } + parts.join("/") +} + +#[cfg(test)] +mod tests { + use super::*; + + fn read(files: &'static [(&'static str, &'static str)]) -> impl Fn(&str) -> Result> { + move |name| Ok(files.iter().find(|(file, _)| *file == name).map(|(_, text)| (*text).to_owned())) + } + + fn direct(lockfile: &Lockfile) -> Vec { + lockfile + .root + .iter() + .map(|d| format!("{} {}", d.dependency.name, d.dependency.version.as_deref().unwrap_or("-"))) + .collect() + } + + #[test] + fn pins_are_direct_and_everything_else_is_skipped() { + let lockfile = parse( + &["requirements.txt".into()], + &read(&[ + ( + "requirements.txt", + "# A comment\n--index-url https://example.com/simple\nDjango==5.1.2 # the web framework\nrequests>=2\n-e .\nuvicorn[standard]==0.30.6 ; python_version >= \"3.9\" \\\n --hash=sha256:abc\n-r requirements/base.txt\ntool @ git+https://example.com/tool.git\n", + ), + ("requirements/base.txt", "attrs===24.2.0\n-c ../constraints.txt\n"), + ]), + ) + .unwrap(); + assert_eq!(direct(&lockfile), ["django 5.1.2", "uvicorn 0.30.6", "attrs 24.2.0"]); + assert_eq!(lockfile.packages[0].label, "Django"); + assert_eq!(lockfile.root[1].dependency.extras, ["standard"]); + assert_eq!(lockfile.root[1].dependency.marker.as_deref(), Some("python_version >= \"3.9\"")); + assert_eq!(lockfile.root[1].evidence[0]["location"]["line"], 6); + assert_eq!( + lockfile.skipped, + [ + json!(["requirements.txt", "requests>=2"]), + json!(["requirements.txt", "-e ."]), + json!(["requirements.txt", "tool @ git+https://example.com/tool.git"]) + ] + ); + } + + #[test] + fn via_annotations_say_what_pulls_each_pin_in() { + let lockfile = parse( + &["requirements.txt".into()], + &read(&[( + "requirements.txt", + "anyio==4.4.0\n # via\n # httpx\n # starlette\nfastapi==0.115.0\n # via -r requirements.in\nhttpx==0.27.0\n # via app (pyproject.toml)\nidna==3.8\n # via anyio\nstarlette==0.38.0\n # via fastapi\nsniffio==1.3.1\n", + )]), + ) + .unwrap(); + assert_eq!(direct(&lockfile), ["fastapi 0.115.0", "httpx 0.27.0", "sniffio 1.3.1"]); + let dependencies = |name: &str| -> Vec { + let package = lockfile.packages.iter().find(|p| p.name == name).unwrap(); + package.dependencies.iter().map(|d| d.name.clone()).collect() + }; + assert_eq!(dependencies("httpx"), ["anyio"]); + assert_eq!(dependencies("starlette"), ["anyio"]); + assert_eq!(dependencies("anyio"), ["idna"]); + assert_eq!(dependencies("fastapi"), ["starlette"]); + } + + #[test] + fn includes_are_relative_to_the_including_file() { + assert_eq!(relative("requirements/dev.txt", "base.txt"), "requirements/base.txt"); + assert_eq!(relative("requirements/dev.txt", "../requirements.txt"), "requirements.txt"); + assert_eq!(relative("requirements.txt", "./requirements/a.txt"), "requirements/a.txt"); + } +} diff --git a/packages/extractors/python-dependencies/src/lockfile/uv.rs b/packages/extractors/python-dependencies/src/lockfile/uv.rs new file mode 100644 index 000000000..a3babe99e --- /dev/null +++ b/packages/extractors/python-dependencies/src/lockfile/uv.rs @@ -0,0 +1,165 @@ +//! `uv.lock`, version 1: every package of the workspace's universal +//! resolution, the dependencies, extras and dependency groups uv resolved for +//! each, and the requirements the workspace members declared. + +use super::toml; +use crate::model::{DEPENDENCIES, DEV, Declaration, Dependency, Locked, Lockfile, OPTIONAL}; +use crate::requirement::{marker_extra, normalize}; +use anyhow::{Context as _, Result, ensure}; +use serde_json::{Value, json}; + +/// Sources of packages that are part of the workspace or the checkout rather than installed from elsewhere. +const LOCAL: [&str; 4] = ["editable", "virtual", "directory", "path"]; + +pub(crate) fn parse(path: &str, text: &str) -> Result { + let document = toml(text, path)?; + ensure!( + document["version"] == 1, + "{path}: unsupported uv.lock version {}; expected version 1", + document["version"] + ); + let evidence = json!([{"kind":"lockfile","source":path}]); + let mut lockfile = Lockfile { + path: path.to_owned(), + version: Some(document["version"].clone()), + ..Lockfile::default() + }; + for package in document["package"].as_array().into_iter().flatten() { + let label = package["name"].as_str().with_context(|| format!("{path}: a package has no name"))?; + let name = normalize(label); + let (source, local) = source(&package["source"]); + let dependencies = dependencies(&package["dependencies"], path)?; + let extras = groups(&package["optional-dependencies"], path)?; + if local { + let metadata = &package["metadata"]; + let mut declarations = vec![]; + let mut declare = |kind, group: Option<&String>, dependency: Dependency, declared: Option<&Value>| { + let mut dependency = dependency; + dependency.specifier = declared.and_then(|d| d["specifier"].as_str()).map(str::to_owned); + declarations.push(Declaration { + kind, + group: group.cloned(), + file: None, + dependency, + pinned: None, + evidence: evidence.clone(), + }); + }; + for dependency in &dependencies { + let declared = requirement(&metadata["requires-dist"], &dependency.name, |marker| { + marker_extra(marker).is_none() + }); + declare(DEPENDENCIES, None, dependency.clone(), declared); + } + for (extra, list) in &extras { + for dependency in list { + let declared = requirement(&metadata["requires-dist"], &dependency.name, |marker| { + marker_extra(marker).as_ref() == Some(extra) + }); + declare(OPTIONAL, Some(extra), dependency.clone(), declared); + } + } + for (group, list) in groups(&package["dev-dependencies"], path)? { + for dependency in list { + let declared = requirement(&metadata["requires-dev"][&group], &dependency.name, |_| true); + declare(DEV, Some(&group), dependency, declared); + } + } + lockfile.projects.insert(name.clone(), declarations); + } + lockfile.packages.push(Locked { + name, + label: label.to_owned(), + version: package["version"].as_str().unwrap_or_default().to_owned(), + source, + dependencies, + extras, + }); + } + // A virtual workspace root, which has no package of its own, records its requirements in the manifest. + let manifest = &document["manifest"]; + let mut root = |kind, group: Option, list: &Value| -> Result<()> { + for item in list.as_array().into_iter().flatten() { + let mut dependency = dependency(item, path)?; + dependency.specifier = item["specifier"].as_str().map(str::to_owned); + lockfile.root.push(Declaration { + kind, + group: group.clone(), + file: None, + dependency, + pinned: None, + evidence: evidence.clone(), + }); + } + Ok(()) + }; + root(DEPENDENCIES, None, &manifest["requirements"])?; + for (group, list) in manifest["dependency-groups"].as_object().into_iter().flatten() { + root(DEV, Some(normalize(group)), list)?; + } + Ok(lockfile) +} + +/// A package's source, and whether it is local: a registry's URL, `git+`, +/// a URL, or ` ` for a local one. +fn source(source: &Value) -> (Option, bool) { + let Some(table) = source.as_object() else { + return (None, false); + }; + for kind in LOCAL { + if let Some(path) = table.get(kind).and_then(Value::as_str) { + return (Some(format!("{kind} {path}")), true); + } + } + let text = |key: &str| table.get(key).and_then(Value::as_str); + let described = text("registry") + .map(str::to_owned) + .or_else(|| text("git").map(|url| format!("git+{url}"))) + .or_else(|| text("url").map(str::to_owned)); + (described, false) +} + +fn dependencies(list: &Value, path: &str) -> Result> { + list.as_array().into_iter().flatten().map(|item| dependency(item, path)).collect() +} + +/// A dependency entry: `{ name, version?, source?, extra?, marker? }`. +fn dependency(item: &Value, path: &str) -> Result { + let name = item["name"].as_str().with_context(|| format!("{path}: a dependency has no name"))?; + Ok(Dependency { + name: normalize(name), + version: item["version"].as_str().map(str::to_owned), + specifier: None, + extras: super::strings(if item["extra"].is_null() { &item["extras"] } else { &item["extra"] }) + .iter() + .map(|extra| normalize(extra)) + .collect(), + marker: item["marker"].as_str().map(str::to_owned), + }) +} + +/// `optional-dependencies` or `dev-dependencies`: each extra or group's dependencies. +fn groups(table: &Value, path: &str) -> Result>> { + table + .as_object() + .into_iter() + .flatten() + .map(|(group, list)| Ok((normalize(group), dependencies(list, path)?))) + .collect() +} + +/// The declared requirement for `name` in a member's `requires-dist` or a +/// `requires-dev` group whose marker `selects`, else any for `name`. +fn requirement<'a>(list: &'a Value, name: &str, selects: impl Fn(&str) -> bool) -> Option<&'a Value> { + let named: Vec<&Value> = list + .as_array() + .into_iter() + .flatten() + .filter(|item| item["name"].as_str().is_some_and(|n| normalize(n) == name)) + .collect(); + named + .iter() + .find(|item| selects(item["marker"].as_str().unwrap_or_default())) + .or(named.first()) + .copied() +} diff --git a/packages/extractors/python-dependencies/src/model.rs b/packages/extractors/python-dependencies/src/model.rs new file mode 100644 index 000000000..8d6a11ee7 --- /dev/null +++ b/packages/extractors/python-dependencies/src/model.rs @@ -0,0 +1,71 @@ +//! What the manifests and lockfiles say, read into one shape for every +//! manager: locked packages, and the dependencies projects declare. + +use serde_json::Value; +use std::collections::BTreeMap; + +/// One dependency as a manifest or lockfile records it. +#[derive(Clone, Debug, Default)] +pub(crate) struct Dependency { + /// The normalized package name. + pub name: String, + /// The exact version, when the lockfile names which of several locked copies it means (uv). + pub version: Option, + /// The requested version specifier as written (`>=1.2,<2`, Poetry's `^1.2`). + pub specifier: Option, + /// Extras requested of the target (`httpx[http2]`). + pub extras: Vec, + /// The environment marker, recorded but not evaluated. + pub marker: Option, +} + +/// One locked (or, for requirements files, pinned) package. +#[derive(Debug, Default)] +pub(crate) struct Locked { + /// The normalized name. + pub name: String, + /// The name as the lockfile writes it. + pub label: String, + pub version: String, + /// Where it comes from: a registry URL, `git+…`, or a local path. + pub source: Option, + /// Its own dependencies, installed whenever it is. + pub dependencies: Vec, + /// The dependencies each of its extras adds. + pub extras: BTreeMap>, +} + +/// `dependencies`, an extra's `optionalDependencies`, or a dependency group's `devDependencies`. +pub(crate) const DEPENDENCIES: &str = "dependencies"; +pub(crate) const OPTIONAL: &str = "optionalDependencies"; +pub(crate) const DEV: &str = "devDependencies"; + +/// A dependency a project declares. +#[derive(Clone, Debug)] +pub(crate) struct Declaration { + pub kind: &'static str, + /// The extra (`optionalDependencies`) or dependency group (`devDependencies`) declaring it. + pub group: Option, + /// The requirements file declaring it. + pub file: Option, + pub dependency: Dependency, + /// The pinned package a requirements file names, as an index into the lockfile's packages. + pub pinned: Option, + pub evidence: Value, +} + +/// A lockfile, or the requirements files standing in for one. +#[derive(Default)] +pub(crate) struct Lockfile { + /// The lockfile's path, or the first requirements file's. + pub path: String, + pub version: Option, + pub packages: Vec, + /// What the lockfile records each project it locks declaring (uv), by normalized project name. + pub projects: BTreeMap>, + /// What the lockfile records the root declaring when the root has no name: a virtual uv workspace + /// root's dependency groups, or a requirements file's direct requirements. + pub root: Vec, + /// Requirement lines that aren't in the graph, `[file, line]`. + pub skipped: Vec, +} diff --git a/packages/extractors/python-dependencies/src/pyproject.rs b/packages/extractors/python-dependencies/src/pyproject.rs new file mode 100644 index 000000000..ac62b5f6d --- /dev/null +++ b/packages/extractors/python-dependencies/src/pyproject.rs @@ -0,0 +1,396 @@ +//! Projects and what they declare, read from `pyproject.toml`: PEP 621 +//! `[project]`, PEP 735 `[dependency-groups]`, Poetry's `[tool.poetry]`, PDM's +//! and uv's development dependencies, and uv workspace members. + +use crate::model::{DEPENDENCIES, DEV, Declaration, Dependency, OPTIONAL}; +use crate::requirement::{self, normalize}; +use anyhow::{Context as _, Result, bail}; +use serde_json::{Value, json}; +use std::collections::{BTreeMap, BTreeSet}; + +/// A parsed `pyproject.toml`. +pub(crate) struct Manifest { + /// Its repository path. + pub path: String, + pub document: Value, +} + +impl Manifest { + /// The name as written: `[project] name`, else `[tool.poetry] name`. + pub fn name(&self) -> Option<&str> { + self.document["project"]["name"] + .as_str() + .or_else(|| self.document["tool"]["poetry"]["name"].as_str()) + } + + pub fn version(&self) -> Option<&str> { + self.document["project"]["version"] + .as_str() + .or_else(|| self.document["tool"]["poetry"]["version"].as_str()) + } + + /// uv workspace `members` and `exclude` globs, when the manifest is a uv workspace root. + pub fn workspace(&self) -> Option<(Vec, Vec)> { + let workspace = self.document["tool"]["uv"].get("workspace")?; + let strings = |key: &str| -> Vec { + workspace[key] + .as_array() + .into_iter() + .flatten() + .filter_map(Value::as_str) + .map(str::to_owned) + .collect() + }; + Some((strings("members"), strings("exclude"))) + } + + fn evidence(&self) -> Value { + json!([{"kind":"manifest","source":self.path}]) + } + + /// Every dependency the manifest declares: the project's dependencies and + /// extras (PEP 621, else Poetry's), and its dependency groups (PEP 735, + /// Poetry's groups, PDM's and uv's development dependencies). + pub fn declarations(&self) -> Result> { + let mut declarations = vec![]; + let project = &self.document["project"]; + let poetry = &self.document["tool"]["poetry"]; + let declare = |declarations: &mut Vec, kind, group: Option<&str>, dependency| { + declarations.push(Declaration { + kind, + group: group.map(str::to_owned), + file: None, + dependency, + pinned: None, + evidence: self.evidence(), + }) + }; + // Poetry 2 reads PEP 621 dependencies when they're declared, and its own table otherwise. + if project.get("dependencies").is_some() { + for dependency in self.requirements(&project["dependencies"], "project.dependencies")? { + declare(&mut declarations, DEPENDENCIES, None, dependency); + } + } else if let Some(table) = poetry.get("dependencies") { + let extras = poetry_extras(poetry); + for (name, value) in self.table(table, "tool.poetry.dependencies")? { + // Poetry's `python` constraint is the interpreter, not a package. + if name == "python" { + continue; + } + let (dependency, optional) = poetry_dependency(name, value); + match extras.get(&dependency.name) { + Some(groups) if optional => { + for extra in groups { + declare(&mut declarations, OPTIONAL, Some(extra), dependency.clone()); + } + } + _ => declare(&mut declarations, DEPENDENCIES, None, dependency), + } + } + } + if let Some(extras) = project.get("optional-dependencies") { + for (extra, list) in self.table(extras, "project.optional-dependencies")? { + for dependency in self.requirements(list, &format!("project.optional-dependencies.{extra}"))? { + declare(&mut declarations, OPTIONAL, Some(&normalize(extra)), dependency); + } + } + } + for (group, dependencies) in self.groups()? { + for dependency in dependencies { + declare(&mut declarations, DEV, Some(&group), dependency); + } + } + Ok(declarations) + } + + /// Each dependency group and what it declares, groups of every source merged by name. + fn groups(&self) -> Result>> { + let mut groups: BTreeMap> = BTreeMap::new(); + if let Some(table) = self.document.get("dependency-groups") { + let table = self.table(table, "dependency-groups")?; + for group in table.keys() { + let mut seen = BTreeSet::new(); + let dependencies = self.group(table, group, &mut seen)?; + groups.entry(normalize(group)).or_default().extend(dependencies); + } + } + let tool = &self.document["tool"]; + if let Some(list) = tool["uv"].get("dev-dependencies") { + groups + .entry("dev".into()) + .or_default() + .extend(self.requirements(list, "tool.uv.dev-dependencies")?); + } + if let Some(table) = tool["pdm"].get("dev-dependencies") { + for (group, list) in self.table(table, "tool.pdm.dev-dependencies")? { + let dependencies = self.requirements(list, &format!("tool.pdm.dev-dependencies.{group}"))?; + groups.entry(normalize(group)).or_default().extend(dependencies); + } + } + let poetry = &tool["poetry"]; + if let Some(table) = poetry.get("dev-dependencies") { + let dependencies = self.poetry_table(table, "tool.poetry.dev-dependencies")?; + groups.entry("dev".into()).or_default().extend(dependencies); + } + if let Some(table) = poetry.get("group") { + for (group, value) in self.table(table, "tool.poetry.group")? { + let Some(dependencies) = value.get("dependencies") else { + continue; + }; + let dependencies = self.poetry_table(dependencies, &format!("tool.poetry.group.{group}.dependencies"))?; + groups.entry(normalize(group)).or_default().extend(dependencies); + } + } + Ok(groups) + } + + /// A PEP 735 group's requirements, with the groups it includes. + fn group(&self, table: &serde_json::Map, group: &str, seen: &mut BTreeSet) -> Result> { + if !seen.insert(group.to_owned()) { + bail!("{}: dependency group {group} includes itself", self.path); + } + let mut dependencies = vec![]; + let list = table + .get(group) + .with_context(|| format!("{}: no dependency group is named {group}", self.path))?; + for item in list + .as_array() + .with_context(|| format!("{}: dependency-groups.{group} must be an array", self.path))? + { + match item { + Value::String(text) => dependencies.extend(dependency(text)), + Value::Object(include) => { + let name = include + .get("include-group") + .and_then(Value::as_str) + .with_context(|| format!("{}: dependency-groups.{group} has a table without include-group", self.path))?; + dependencies.extend(self.group(table, name, seen)?); + } + _ => bail!("{}: dependency-groups.{group} items must be strings or tables", self.path), + } + } + seen.remove(group); + Ok(dependencies) + } + + fn table<'a>(&self, value: &'a Value, label: &str) -> Result<&'a serde_json::Map> { + value.as_object().with_context(|| format!("{}: {label} must be a table", self.path)) + } + + /// An array of PEP 508 requirement strings. Entries that don't name a + /// package (PDM's `-e file:///…` editable installs) are left out. + fn requirements(&self, value: &Value, label: &str) -> Result> { + let list = value + .as_array() + .with_context(|| format!("{}: {label} must be an array", self.path))?; + let mut dependencies = vec![]; + for item in list { + let text = item + .as_str() + .with_context(|| format!("{}: {label} items must be strings", self.path))?; + dependencies.extend(dependency(text)); + } + Ok(dependencies) + } + + /// A Poetry dependency table, its `python` constraint left out. + fn poetry_table(&self, value: &Value, label: &str) -> Result> { + Ok(self + .table(value, label)? + .iter() + .filter(|(name, _)| *name != "python") + .map(|(name, value)| poetry_dependency(name, value).0) + .collect()) + } +} + +/// One requirement string's dependency. +fn dependency(text: &str) -> Option { + let requirement = requirement::parse(text).filter(|_| !text.trim_start().starts_with('-'))?; + Some(Dependency { + name: requirement.name, + version: None, + specifier: requirement.specifier.or(requirement.url), + extras: requirement.extras, + marker: requirement.marker, + }) +} + +/// Poetry's extras: each optional dependency's normalized name, and the extras listing it. +fn poetry_extras(poetry: &Value) -> BTreeMap> { + let mut extras: BTreeMap> = BTreeMap::new(); + for (extra, names) in poetry["extras"].as_object().into_iter().flatten() { + for name in names.as_array().into_iter().flatten().filter_map(Value::as_str) { + if let Some(requirement) = requirement::parse(name) { + extras.entry(requirement.name).or_default().push(normalize(extra)); + } + } + } + extras +} + +/// A Poetry dependency: a constraint string, a table (`version`, `extras`, +/// `markers`, `optional`, or a `path`, `git` or `url` source) or an array of +/// tables for several environments, whose constraints are joined with `||` and +/// markers with `or`. Also whether it is optional, installed only for an extra. +pub(crate) fn poetry_dependency(name: &str, value: &Value) -> (Dependency, bool) { + let entries: Vec<&Value> = match value { + Value::Array(entries) => entries.iter().collect(), + other => vec![other], + }; + let mut specifiers = vec![]; + let mut markers = vec![]; + let mut unconditional = false; + let mut extras = BTreeSet::new(); + let mut optional = !entries.is_empty(); + for entry in &entries { + match entry { + Value::String(constraint) => { + specifiers.push(constraint.clone()); + unconditional = true; + optional = false; + } + Value::Object(table) => { + let constraint = ["version", "path", "git", "url", "file"] + .into_iter() + .find_map(|key| table.get(key).and_then(Value::as_str)); + specifiers.extend(constraint.map(str::to_owned)); + match table.get("markers").and_then(Value::as_str) { + Some(marker) => markers.push(marker.to_owned()), + None => unconditional = true, + } + extras.extend( + table + .get("extras") + .and_then(Value::as_array) + .into_iter() + .flatten() + .filter_map(Value::as_str) + .map(normalize), + ); + optional &= table.get("optional").and_then(Value::as_bool) == Some(true); + } + _ => optional = false, + } + } + specifiers.dedup(); + let marker = match markers.as_slice() { + _ if unconditional => None, + [] => None, + [one] => Some(one.clone()), + several => Some(several.iter().map(|m| format!("({m})")).collect::>().join(" or ")), + }; + let dependency = Dependency { + name: normalize(name), + version: None, + specifier: Some(specifiers.join(" || ")).filter(|s| !s.is_empty()), + extras: extras.into_iter().collect(), + marker, + }; + (dependency, optional) +} + +#[cfg(test)] +mod tests { + use super::*; + + fn manifest(text: &str) -> Manifest { + Manifest { + path: "pyproject.toml".into(), + document: toml::from_str(text).unwrap(), + } + } + + fn summary(declarations: &[Declaration]) -> Vec { + declarations + .iter() + .map(|d| { + format!( + "{} {} {} {} [{}]", + d.kind, + d.group.as_deref().unwrap_or("-"), + d.dependency.name, + d.dependency.specifier.as_deref().unwrap_or("-"), + d.dependency.extras.join(",") + ) + }) + .collect() + } + + #[test] + fn pep_621_projects_declare_dependencies_extras_and_groups() { + let m = manifest( + r#" +[project] +name = "Acme_API" +dependencies = ["httpx[http2]>=0.27", "Pydantic>=2"] +[project.optional-dependencies] +Postgres = ["psycopg>=3"] +[dependency-groups] +test = ["pytest>=8"] +dev = [{include-group = "test"}, "ruff"] +[tool.uv] +dev-dependencies = ["mypy"] +"#, + ); + assert_eq!(m.name(), Some("Acme_API")); + assert_eq!( + summary(&m.declarations().unwrap()), + [ + "dependencies - httpx >=0.27 [http2]", + "dependencies - pydantic >=2 []", + "optionalDependencies postgres psycopg >=3 []", + "devDependencies dev pytest >=8 []", + "devDependencies dev ruff - []", + "devDependencies dev mypy - []", + "devDependencies test pytest >=8 []", + ] + ); + } + + #[test] + fn poetry_projects_declare_dependencies_extras_and_groups() { + let m = manifest( + r#" +[tool.poetry] +name = "service" +version = "1.0.0" +[tool.poetry.dependencies] +python = "^3.11" +fastapi = "^0.115" +uvicorn = {version = "^0.30", extras = ["standard"]} +psycopg = {version = "^3.2", optional = true} +tomli = [{version = "^2", markers = "python_version < '3.11'"}, {version = "^1", markers = "python_version < '3.8'"}] +[tool.poetry.extras] +postgres = ["psycopg"] +[tool.poetry.group.test.dependencies] +pytest = "^8" +[tool.poetry.dev-dependencies] +black = "*" +"#, + ); + assert_eq!((m.name(), m.version()), (Some("service"), Some("1.0.0"))); + let declarations = m.declarations().unwrap(); + assert_eq!( + summary(&declarations), + [ + "dependencies - fastapi ^0.115 []", + "optionalDependencies postgres psycopg ^3.2 []", + "dependencies - tomli ^2 || ^1 []", + "dependencies - uvicorn ^0.30 [standard]", + "devDependencies dev black * []", + "devDependencies test pytest ^8 []", + ] + ); + assert_eq!( + declarations[2].dependency.marker.as_deref(), + Some("(python_version < '3.11') or (python_version < '3.8')") + ); + } + + #[test] + fn a_group_that_includes_itself_is_an_error() { + let m = manifest("[dependency-groups]\na = [{include-group = \"b\"}]\nb = [{include-group = \"a\"}]\n"); + assert!(format!("{:#}", m.declarations().unwrap_err()).contains("includes itself")); + } +} diff --git a/packages/extractors/python-dependencies/src/requirement.rs b/packages/extractors/python-dependencies/src/requirement.rs new file mode 100644 index 000000000..b8a80915b --- /dev/null +++ b/packages/extractors/python-dependencies/src/requirement.rs @@ -0,0 +1,130 @@ +//! Python package names and PEP 508 requirement strings, read far enough to +//! know what a requirement names: its package, extras, version specifier and +//! environment marker. + +/// A package name normalized as PyPI and every installer compare them (PEP 503): +/// lowercase, with each run of `-`, `_` and `.` one `-`. +pub(crate) fn normalize(name: &str) -> String { + let mut normalized = String::with_capacity(name.len()); + let mut separator = false; + for character in name.trim().chars() { + if matches!(character, '-' | '_' | '.') { + separator = true; + continue; + } + if separator && !normalized.is_empty() { + normalized.push('-'); + } + separator = false; + normalized.extend(character.to_lowercase()); + } + normalized +} + +/// One requirement: `name[extra,…] specifier ; marker`, or `name @ url`. +#[derive(Debug, Default, PartialEq)] +pub(crate) struct Requirement { + /// The normalized name. + pub name: String, + pub extras: Vec, + /// The version specifier as written (`>=1.2,<2`), without Poetry's parentheses. + pub specifier: Option, + /// A direct reference's URL (`name @ https://…`). + pub url: Option, + pub marker: Option, +} + +/// Reads a PEP 508 requirement, and the `name (specifier)` form Poetry writes +/// in lockfile extras. `None` when it doesn't start with a package name. +pub(crate) fn parse(text: &str) -> Option { + let text = text.trim(); + let (body, marker) = match text.split_once(';') { + Some((body, marker)) => (body.trim(), Some(marker.trim()).filter(|m| !m.is_empty())), + None => (text, None), + }; + let end = body + .find(|c: char| !(c.is_ascii_alphanumeric() || matches!(c, '-' | '_' | '.'))) + .unwrap_or(body.len()); + if end == 0 || !body.starts_with(|c: char| c.is_ascii_alphanumeric()) { + return None; + } + let name = normalize(&body[..end]); + let mut rest = body[end..].trim_start(); + let mut extras = vec![]; + if let Some(inner) = rest.strip_prefix('[') { + let close = inner.find(']')?; + extras = inner[..close].split(',').map(normalize).filter(|extra| !extra.is_empty()).collect(); + rest = inner[close + 1..].trim_start(); + } + let mut requirement = Requirement { + name, + extras, + marker: marker.map(str::to_owned), + ..Requirement::default() + }; + if let Some(url) = rest.strip_prefix('@') { + requirement.url = Some(url.trim().to_owned()).filter(|url| !url.is_empty()); + } else { + let specifier = rest.trim().trim_start_matches('(').trim_end_matches(')').trim(); + requirement.specifier = Some(specifier.to_owned()).filter(|s| !s.is_empty()); + } + Some(requirement) +} + +/// The extra a marker selects (`extra == 'socks'`), when it selects one. +pub(crate) fn marker_extra(marker: &str) -> Option { + let at = marker.find("extra")?; + let rest = marker[at + "extra".len()..].trim_start().strip_prefix("==")?.trim_start(); + let quote = rest.chars().next().filter(|c| *c == '\'' || *c == '"')?; + let value = &rest[1..]; + value.find(quote).map(|end| normalize(&value[..end])) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn names_compare_as_installers_compare_them() { + assert_eq!(normalize("Typing_Extensions"), "typing-extensions"); + assert_eq!(normalize("zope.interface"), "zope-interface"); + assert_eq!(normalize("a-_.b"), "a-b"); + assert_eq!(normalize("Django"), "django"); + } + + #[test] + fn requirements_name_their_package_extras_specifier_and_marker() { + assert_eq!( + parse("httpx[http2, Socks]>=0.27,<1 ; python_version < \"3.11\"").unwrap(), + Requirement { + name: "httpx".into(), + extras: vec!["http2".into(), "socks".into()], + specifier: Some(">=0.27,<1".into()), + url: None, + marker: Some("python_version < \"3.11\"".into()), + } + ); + assert_eq!( + parse("socksio (>=1.0.0,<2.0.0)").unwrap().specifier.as_deref(), + Some(">=1.0.0,<2.0.0") + ); + assert_eq!( + parse("tool @ git+https://example.com/tool.git").unwrap().url.as_deref(), + Some("git+https://example.com/tool.git") + ); + let bare = parse("Flask").unwrap(); + assert_eq!((bare.name.as_str(), bare.specifier, bare.marker), ("flask", None, None)); + assert!(parse("-e .").is_none()); + assert!(parse("").is_none()); + } + + #[test] + fn markers_name_the_extra_they_select() { + assert_eq!(marker_extra("extra == 'standard'").as_deref(), Some("standard")); + assert_eq!( + marker_extra("python_version >= \"3.9\" and extra == \"Dev_Tools\"").as_deref(), + Some("dev-tools") + ); + assert_eq!(marker_extra("sys_platform == 'win32'"), None); + } +} diff --git a/packages/extractors/python-dependencies/tests/fixtures/lock.mjs b/packages/extractors/python-dependencies/tests/fixtures/lock.mjs new file mode 100644 index 000000000..9c69493b3 --- /dev/null +++ b/packages/extractors/python-dependencies/tests/fixtures/lock.mjs @@ -0,0 +1,84 @@ +// Regenerates the lockfiles beside this script with the package managers themselves, then removes what names the index +// they resolved from: uv.lock's registry becomes https://pypi.org/simple and its sdist and wheel entries, which the +// extractor doesn't read, are dropped; Poetry's [package.source] tables for the index are dropped. The resolution itself +// is left as the manager wrote it. +// +// node packages/extractors/python-dependencies/tests/fixtures/lock.mjs [index URL] +// +// Without an index URL, PIP_INDEX_URL or https://pypi.org/simple is used. Requires uv; uvx runs Poetry and PDM. +import { execFileSync } from "node:child_process"; +import { readFileSync, rmSync, writeFileSync } from "node:fs"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; + +const here = path.dirname(fileURLToPath(import.meta.url)); +const index = + process.argv[2] ?? process.env.PIP_INDEX_URL ?? "https://pypi.org/simple"; +const environment = { + ...process.env, + UV_INDEX_URL: index, + PDM_PYPI_URL: index, +}; +const run = (directory, command, ...args) => + execFileSync(command, args, { + cwd: path.join(here, directory), + env: environment, + stdio: "inherit", + }); +const rewrite = (file, change) => + writeFileSync( + path.join(here, file), + change(readFileSync(path.join(here, file), "utf8")), + ); + +for (const directory of ["uv-workspace"]) { + run(directory, "uv", "lock", "--index-url", index); + rewrite(`${directory}/uv.lock`, (text) => + text + .replaceAll( + `registry = "${index}"`, + 'registry = "https://pypi.org/simple"', + ) + .replace(/^sdist = .*\n/gmu, "") + .replace(/^wheels = \[\n(?: {4}.*\n)*\]\n/gmu, ""), + ); +} + +// Poetry reads its index from the project, so it is added while locking, and a lockfile naming another index is replaced. +rmSync(path.join(here, "poetry/poetry.lock"), { force: true }); +const manifest = readFileSync(path.join(here, "poetry/pyproject.toml"), "utf8"); +try { + writeFileSync( + path.join(here, "poetry/pyproject.toml"), + `${manifest}\n[[tool.poetry.source]]\nname = "index"\nurl = "${index}"\npriority = "primary"\n`, + ); + run("poetry", "uvx", "--python", "3.12", "poetry", "lock"); +} finally { + writeFileSync(path.join(here, "poetry/pyproject.toml"), manifest); +} +rewrite("poetry/poetry.lock", (text) => + text.replace( + /\n\[package\.source\]\ntype = "legacy"\n(?:.*\n)*?(?=\n|$)/gu, + "\n", + ), +); + +run("pdm", "uvx", "--python", "3.12", "pdm", "lock", "-G", ":all"); +rmSync(path.join(here, "pdm/.venv"), { recursive: true, force: true }); +rmSync(path.join(here, "pdm/.pdm-python"), { force: true }); + +run( + "requirements", + "uv", + "pip", + "compile", + "requirements.in", + "--index-url", + index, + "--python-version", + "3.10", + "--custom-compile-command", + "uv pip compile requirements.in -o requirements.txt", + "-o", + "requirements.txt", +); diff --git a/packages/extractors/python-dependencies/tests/fixtures/pdm.expected.json b/packages/extractors/python-dependencies/tests/fixtures/pdm.expected.json new file mode 100644 index 000000000..0a11d8bb4 --- /dev/null +++ b/packages/extractors/python-dependencies/tests/fixtures/pdm.expected.json @@ -0,0 +1,858 @@ +{ + "entities": [ + { + "confidence": "authoritative", + "data": { + "version": "4.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "id": "package:anyio", + "kind": "package", + "label": "anyio" + }, + { + "confidence": "authoritative", + "data": { + "version": "26.1.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "id": "package:attrs", + "kind": "package", + "label": "attrs" + }, + { + "confidence": "authoritative", + "data": { + "version": "2026.11.20" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "id": "package:certifi", + "kind": "package", + "label": "certifi" + }, + { + "confidence": "authoritative", + "data": { + "version": "0.4.6" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "id": "package:colorama", + "kind": "package", + "label": "colorama" + }, + { + "confidence": "authoritative", + "data": { + "version": "1.3.2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "id": "package:exceptiongroup", + "kind": "package", + "label": "exceptiongroup" + }, + { + "confidence": "authoritative", + "data": { + "version": "0.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "id": "package:h11", + "kind": "package", + "label": "h11" + }, + { + "confidence": "authoritative", + "data": { + "version": "4.4.1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "id": "package:h2", + "kind": "package", + "label": "h2" + }, + { + "confidence": "authoritative", + "data": { + "version": "4.2.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "id": "package:hpack", + "kind": "package", + "label": "hpack" + }, + { + "confidence": "authoritative", + "data": { + "version": "1.0.9" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "id": "package:httpcore", + "kind": "package", + "label": "httpcore" + }, + { + "confidence": "authoritative", + "data": { + "version": "0.29.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "id": "package:httpx", + "kind": "package", + "label": "httpx" + }, + { + "confidence": "authoritative", + "data": { + "version": "6.1.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "id": "package:hyperframe", + "kind": "package", + "label": "hyperframe" + }, + { + "confidence": "authoritative", + "data": { + "version": "3.20" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "id": "package:idna", + "kind": "package", + "label": "idna" + }, + { + "confidence": "authoritative", + "data": { + "version": "2.3.1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "id": "package:iniconfig", + "kind": "package", + "label": "iniconfig" + }, + { + "confidence": "authoritative", + "data": { + "version": "4.3.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "id": "package:markdown-it-py", + "kind": "package", + "label": "markdown-it-py" + }, + { + "confidence": "authoritative", + "data": { + "version": "0.1.2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "id": "package:mdurl", + "kind": "package", + "label": "mdurl" + }, + { + "confidence": "authoritative", + "data": { + "version": "26.4" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "id": "package:packaging", + "kind": "package", + "label": "packaging" + }, + { + "confidence": "authoritative", + "data": { + "version": "1.7.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "id": "package:pluggy", + "kind": "package", + "label": "pluggy" + }, + { + "confidence": "authoritative", + "data": { + "version": "2.21.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "id": "package:pygments", + "kind": "package", + "label": "pygments" + }, + { + "confidence": "authoritative", + "data": { + "version": "9.2.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "id": "package:pytest", + "kind": "package", + "label": "pytest" + }, + { + "confidence": "authoritative", + "data": { + "version": "15.0.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "id": "package:rich", + "kind": "package", + "label": "rich" + }, + { + "confidence": "authoritative", + "data": { + "version": "2.5.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "id": "package:tomli", + "kind": "package", + "label": "tomli" + }, + { + "confidence": "authoritative", + "data": { + "version": "4.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "id": "package:typing-extensions", + "kind": "package", + "label": "typing-extensions" + }, + { + "confidence": "authoritative", + "data": { + "path": ".", + "version": "0.9.0" + }, + "evidence": [ + { + "kind": "manifest", + "source": "pyproject.toml" + } + ], + "id": "project:beacon", + "kind": "project", + "label": "beacon" + } + ], + "metadata": { + "limitations": [ + "Every extra and dependency group a project declares is included; a package's extras are followed only where a dependency in the graph requests them.", + "Environment markers are recorded on relationships as `marker` but not evaluated: the graph covers every platform and Python version at once." + ], + "lockfile": "pdm.lock", + "lockfileVersion": "4.5.1", + "manager": "pdm", + "unresolved": [] + }, + "protocolVersion": 0, + "relationships": [ + { + "confidence": "authoritative", + "data": { + "resolved": "26.1.0", + "type": "dependencies", + "version": ">=24" + }, + "evidence": [ + { + "kind": "manifest", + "source": "pyproject.toml" + } + ], + "from": "project:beacon", + "id": "dependency:[\"beacon\",\"dependencies\",\"attrs\"]", + "kind": "dependencies", + "label": ">=24", + "to": "package:attrs" + }, + { + "confidence": "authoritative", + "data": { + "extras": [ + "http2" + ], + "resolved": "0.29.0", + "type": "dependencies", + "version": ">=0.27" + }, + "evidence": [ + { + "kind": "manifest", + "source": "pyproject.toml" + } + ], + "from": "project:beacon", + "id": "dependency:[\"beacon\",\"dependencies\",\"httpx\"]", + "kind": "dependencies", + "label": ">=0.27", + "to": "package:httpx" + }, + { + "confidence": "authoritative", + "data": { + "group": "test", + "resolved": "9.2.0", + "type": "devDependencies", + "version": ">=8" + }, + "evidence": [ + { + "kind": "manifest", + "source": "pyproject.toml" + } + ], + "from": "project:beacon", + "id": "dependency:[\"beacon\",\"devDependencies\",\"test\",\"pytest\"]", + "kind": "devDependencies", + "label": ">=8", + "to": "package:pytest" + }, + { + "confidence": "authoritative", + "data": { + "extra": "cli", + "resolved": "15.0.0", + "type": "optionalDependencies", + "version": ">=13" + }, + "evidence": [ + { + "kind": "manifest", + "source": "pyproject.toml" + } + ], + "from": "project:beacon", + "id": "dependency:[\"beacon\",\"optionalDependencies\",\"cli\",\"rich\"]", + "kind": "optionalDependencies", + "label": ">=13", + "to": "package:rich" + }, + { + "confidence": "authoritative", + "data": { + "marker": "python_version < \"3.11\"", + "type": "dependencies", + "version": ">=1.0.2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "from": "package:anyio", + "id": "dependency:[\"package:anyio\",\"dependencies\",\"exceptiongroup\"]", + "kind": "dependencies", + "label": ">=1.0.2", + "to": "package:exceptiongroup" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": ">=2.8" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "from": "package:anyio", + "id": "dependency:[\"package:anyio\",\"dependencies\",\"idna\"]", + "kind": "dependencies", + "label": ">=2.8", + "to": "package:idna" + }, + { + "confidence": "authoritative", + "data": { + "marker": "python_version < \"3.15\"", + "type": "dependencies", + "version": ">=4.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "from": "package:anyio", + "id": "dependency:[\"package:anyio\",\"dependencies\",\"typing-extensions\"]", + "kind": "dependencies", + "label": ">=4.16.0", + "to": "package:typing-extensions" + }, + { + "confidence": "authoritative", + "data": { + "marker": "python_version < \"3.13\"", + "type": "dependencies", + "version": ">=4.6.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "from": "package:exceptiongroup", + "id": "dependency:[\"package:exceptiongroup\",\"dependencies\",\"typing-extensions\"]", + "kind": "dependencies", + "label": ">=4.6.0", + "to": "package:typing-extensions" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "<5,>=4.2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "from": "package:h2", + "id": "dependency:[\"package:h2\",\"dependencies\",\"hpack\"]", + "kind": "dependencies", + "label": "<5,>=4.2", + "to": "package:hpack" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "<7,>=6.1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "from": "package:h2", + "id": "dependency:[\"package:h2\",\"dependencies\",\"hyperframe\"]", + "kind": "dependencies", + "label": "<7,>=6.1", + "to": "package:hyperframe" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "from": "package:httpcore", + "id": "dependency:[\"package:httpcore\",\"dependencies\",\"certifi\"]", + "kind": "dependencies", + "to": "package:certifi" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": ">=0.16" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "from": "package:httpcore", + "id": "dependency:[\"package:httpcore\",\"dependencies\",\"h11\"]", + "kind": "dependencies", + "label": ">=0.16", + "to": "package:h11" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"dependencies\",\"anyio\"]", + "kind": "dependencies", + "to": "package:anyio" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"dependencies\",\"certifi\"]", + "kind": "dependencies", + "to": "package:certifi" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==1.*" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"dependencies\",\"httpcore\"]", + "kind": "dependencies", + "label": "==1.*", + "to": "package:httpcore" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"dependencies\",\"idna\"]", + "kind": "dependencies", + "to": "package:idna" + }, + { + "confidence": "authoritative", + "data": { + "extra": "http2", + "type": "optionalDependencies", + "version": "<5,>=3" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"optionalDependencies\",\"http2\",\"h2\"]", + "kind": "optionalDependencies", + "label": "<5,>=3", + "to": "package:h2" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "~=0.1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "from": "package:markdown-it-py", + "id": "dependency:[\"package:markdown-it-py\",\"dependencies\",\"mdurl\"]", + "kind": "dependencies", + "label": "~=0.1", + "to": "package:mdurl" + }, + { + "confidence": "authoritative", + "data": { + "marker": "sys_platform == \"win32\"", + "type": "dependencies", + "version": ">=0.4" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"colorama\"]", + "kind": "dependencies", + "label": ">=0.4", + "to": "package:colorama" + }, + { + "confidence": "authoritative", + "data": { + "marker": "python_version < \"3.11\"", + "type": "dependencies", + "version": ">=1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"exceptiongroup\"]", + "kind": "dependencies", + "label": ">=1", + "to": "package:exceptiongroup" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": ">=2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"iniconfig\"]", + "kind": "dependencies", + "label": ">=2", + "to": "package:iniconfig" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": ">=24" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"packaging\"]", + "kind": "dependencies", + "label": ">=24", + "to": "package:packaging" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "<2,>=1.6" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"pluggy\"]", + "kind": "dependencies", + "label": "<2,>=1.6", + "to": "package:pluggy" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": ">=2.15" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"pygments\"]", + "kind": "dependencies", + "label": ">=2.15", + "to": "package:pygments" + }, + { + "confidence": "authoritative", + "data": { + "marker": "python_version < \"3.11\"", + "type": "dependencies", + "version": ">=2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"tomli\"]", + "kind": "dependencies", + "label": ">=2", + "to": "package:tomli" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": ">=2.2.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "from": "package:rich", + "id": "dependency:[\"package:rich\",\"dependencies\",\"markdown-it-py\"]", + "kind": "dependencies", + "label": ">=2.2.0", + "to": "package:markdown-it-py" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "<3.0.0,>=2.13.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "pdm.lock" + } + ], + "from": "package:rich", + "id": "dependency:[\"package:rich\",\"dependencies\",\"pygments\"]", + "kind": "dependencies", + "label": "<3.0.0,>=2.13.0", + "to": "package:pygments" + } + ], + "schema": "graph/v0" +} diff --git a/packages/extractors/python-dependencies/tests/fixtures/pdm/pdm.lock b/packages/extractors/python-dependencies/tests/fixtures/pdm/pdm.lock new file mode 100644 index 000000000..5605a63ad --- /dev/null +++ b/packages/extractors/python-dependencies/tests/fixtures/pdm/pdm.lock @@ -0,0 +1,374 @@ +# This file is @generated by PDM. +# It is not intended for manual editing. + +[metadata] +groups = ["default", "cli", "test"] +strategy = ["inherit_metadata"] +lock_version = "4.5.1" +content_hash = "sha256:3ef847c8a1d0d5b12fb29229777e38d7911575781f8c80f4aa264784ba4f185f" + +[[metadata.targets]] +requires_python = ">=3.10" + +[[package]] +name = "anyio" +version = "4.16.0" +requires_python = ">=3.10" +summary = "High-level concurrency and networking framework on top of asyncio or Trio" +groups = ["default"] +dependencies = [ + "exceptiongroup>=1.0.2; python_version < \"3.11\"", + "idna>=2.8", + "typing-extensions>=4.16.0; python_version < \"3.15\"", +] +files = [ + {file = "anyio-4.16.0-py3-none-any.whl", hash = "sha256:c66ae634e0b8228396b801741beb3294326d4b6102f7bba4041c0dfb58c29026"}, + {file = "anyio-4.16.0.tar.gz", hash = "sha256:59bb03251907983d1603d27c3087ddb1e93299ea2163adcdba37899a4fb12ffb"}, +] + +[[package]] +name = "attrs" +version = "26.1.0" +requires_python = ">=3.9" +summary = "Classes Without Boilerplate" +groups = ["default"] +files = [ + {file = "attrs-26.1.0-py3-none-any.whl", hash = "sha256:c647aa4a12dfbad9333ca4e71fe62ddc36f4e63b2d260a37a8b83d2f043ac309"}, + {file = "attrs-26.1.0.tar.gz", hash = "sha256:d03ceb89cb322a8fd706d4fb91940737b6642aa36998fe130a9bc96c985eff32"}, +] + +[[package]] +name = "certifi" +version = "2026.11.20" +requires_python = ">=3.7" +summary = "Python package for providing Mozilla's CA Bundle." +groups = ["default"] +files = [ + {file = "certifi-2026.11.20-py3-none-any.whl", hash = "sha256:7422df25243767b9877031a2248cb14d09ddac9beee846f4cef3d5c9191d488f"}, + {file = "certifi-2026.11.20.tar.gz", hash = "sha256:af1cb240a8133f105aa52684a3a3258339d7f2fd0bd4e2812698ff5cf5588c4e"}, +] + +[[package]] +name = "colorama" +version = "0.4.6" +requires_python = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" +summary = "Cross-platform colored terminal text." +groups = ["test"] +marker = "sys_platform == \"win32\"" +files = [ + {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, + {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, +] + +[[package]] +name = "exceptiongroup" +version = "1.3.2" +requires_python = ">=3.7" +summary = "Backport of PEP 654 (exception groups)" +groups = ["default", "test"] +marker = "python_version < \"3.11\"" +dependencies = [ + "typing-extensions>=4.6.0; python_version < \"3.13\"", +] +files = [ + {file = "exceptiongroup-1.3.2-py3-none-any.whl", hash = "sha256:41c6a70dfec22050d3d8b43386b059a4dc0bca3f3d40a40971cb206fff1785af"}, + {file = "exceptiongroup-1.3.2.tar.gz", hash = "sha256:ca82e69f0cb535fbde934885744b67669a3efddd50fe7bc00d3398839fcaddec"}, +] + +[[package]] +name = "h11" +version = "0.16.0" +requires_python = ">=3.8" +summary = "A pure-Python, bring-your-own-I/O implementation of HTTP/1.1" +groups = ["default"] +files = [ + {file = "h11-0.16.0-py3-none-any.whl", hash = "sha256:63cf8bbe7522de3bf65932fda1d9c2772064ffb3dae62d55932da54b31cb6c86"}, + {file = "h11-0.16.0.tar.gz", hash = "sha256:4e35b956cf45792e4caa5885e69fba00bdbc6ffafbfa020300e549b208ee5ff1"}, +] + +[[package]] +name = "h2" +version = "4.4.1" +requires_python = ">=3.10" +summary = "Pure-Python HTTP/2 protocol implementation" +groups = ["default"] +dependencies = [ + "hpack<5,>=4.2", + "hyperframe<7,>=6.1", +] +files = [ + {file = "h2-4.4.1-py3-none-any.whl", hash = "sha256:0e25f1462b23c9cb82d9eb02e28bc706dac2a68cb457c6a0d74d63c8a2a5d0e6"}, + {file = "h2-4.4.1.tar.gz", hash = "sha256:4e866ffb1a869ae14dd9b5e6beb5c24a13da0495ad72b65925ded182521c1516"}, +] + +[[package]] +name = "hpack" +version = "4.2.0" +requires_python = ">=3.10" +summary = "Pure-Python HPACK header encoding" +groups = ["default"] +files = [ + {file = "hpack-4.2.0-py3-none-any.whl", hash = "sha256:858ac0b02280fa582b5080d68db0899c62a80375e0e5413a74970c5e518b6986"}, + {file = "hpack-4.2.0.tar.gz", hash = "sha256:0895cfa3b5531fc65fe439c05eb65144f123bf7a394fcaa56aa423548d8e45c0"}, +] + +[[package]] +name = "httpcore" +version = "1.0.9" +requires_python = ">=3.8" +summary = "A minimal low-level HTTP client." +groups = ["default"] +dependencies = [ + "certifi", + "h11>=0.16", +] +files = [ + {file = "httpcore-1.0.9-py3-none-any.whl", hash = "sha256:2d400746a40668fc9dec9810239072b40b4484b640a8c38fd654a024c7a1bf55"}, + {file = "httpcore-1.0.9.tar.gz", hash = "sha256:6e34463af53fd2ab5d807f399a9b45ea31c3dfa2276f15a2c3f00afff6e176e8"}, +] + +[[package]] +name = "httpx" +version = "0.29.0" +requires_python = ">=3.10" +summary = "The next generation HTTP client." +groups = ["default"] +dependencies = [ + "anyio", + "certifi", + "httpcore==1.*", + "idna", +] +files = [ + {file = "httpx-0.29.0-py3-none-any.whl", hash = "sha256:6734dcf742ced6e8018e45d3f9f7728975b6b3e1085a24f3e2c056069d858bd1"}, + {file = "httpx-0.29.0.tar.gz", hash = "sha256:700928ee6c1f4213795e67c47eba8f8553639069fea89199f71d654e38edc593"}, +] + +[[package]] +name = "httpx" +version = "0.29.0" +extras = ["http2"] +requires_python = ">=3.10" +summary = "The next generation HTTP client." +groups = ["default"] +dependencies = [ + "h2<5,>=3", + "httpx==0.29.0", +] +files = [ + {file = "httpx-0.29.0-py3-none-any.whl", hash = "sha256:6734dcf742ced6e8018e45d3f9f7728975b6b3e1085a24f3e2c056069d858bd1"}, + {file = "httpx-0.29.0.tar.gz", hash = "sha256:700928ee6c1f4213795e67c47eba8f8553639069fea89199f71d654e38edc593"}, +] + +[[package]] +name = "hyperframe" +version = "6.1.0" +requires_python = ">=3.9" +summary = "Pure-Python HTTP/2 framing" +groups = ["default"] +files = [ + {file = "hyperframe-6.1.0-py3-none-any.whl", hash = "sha256:b03380493a519fce58ea5af42e4a42317bf9bd425596f7a0835ffce80f1a42e5"}, + {file = "hyperframe-6.1.0.tar.gz", hash = "sha256:f630908a00854a7adeabd6382b43923a4c4cd4b821fcb527e6ab9e15382a3b08"}, +] + +[[package]] +name = "idna" +version = "3.20" +requires_python = ">=3.9" +summary = "Internationalized Domain Names in Applications (IDNA)" +groups = ["default"] +files = [ + {file = "idna-3.20-py3-none-any.whl", hash = "sha256:ab7ae7122974553370f0bdb919e1a960b2cd1bc1ef0276416d896db81c14582c"}, + {file = "idna-3.20.tar.gz", hash = "sha256:a7db850025b95ded1eae8a46181a1a6c56c92c96f0e2b005d9ff8dc0210cab44"}, +] + +[[package]] +name = "iniconfig" +version = "2.3.1" +requires_python = ">=3.10" +summary = "brain-dead simple config-ini parsing" +groups = ["test"] +files = [ + {file = "iniconfig-2.3.1-py3-none-any.whl", hash = "sha256:9121e2c1fdb355232495be3194c8dfe87ccc2d5dee45947b78e68f499790d7a7"}, + {file = "iniconfig-2.3.1.tar.gz", hash = "sha256:67f4b9c50da0dedf52af349e7749a80a9057a5031199791b906c3bb3ae878960"}, +] + +[[package]] +name = "markdown-it-py" +version = "4.3.0" +requires_python = ">=3.10" +summary = "Python port of markdown-it. Markdown parsing, done right!" +groups = ["cli"] +dependencies = [ + "mdurl~=0.1", +] +files = [ + {file = "markdown_it_py-4.3.0-py3-none-any.whl", hash = "sha256:7aa1511a46c39138de78d9eba92ce47e63124d8003fc98b3a351909e04239efa"}, + {file = "markdown_it_py-4.3.0.tar.gz", hash = "sha256:91a58fa5b72c71a40cf7177250fd767480d7a2bb3ac426ccfb76fb90305fdaaa"}, +] + +[[package]] +name = "mdurl" +version = "0.1.2" +requires_python = ">=3.7" +summary = "Markdown URL utilities" +groups = ["cli"] +files = [ + {file = "mdurl-0.1.2-py3-none-any.whl", hash = "sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8"}, + {file = "mdurl-0.1.2.tar.gz", hash = "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba"}, +] + +[[package]] +name = "packaging" +version = "26.4" +requires_python = ">=3.10" +summary = "Core utilities for Python packages" +groups = ["test"] +files = [ + {file = "packaging-26.4-py3-none-any.whl", hash = "sha256:81383611a09c1bc0b08b76e0fd5829d7c6824c65b27a6aee339da133f4233ea2"}, + {file = "packaging-26.4.tar.gz", hash = "sha256:c4b671c41ddb9bf26e543c37723610d28fb6bf7affc4da17cf048d419d2c062a"}, +] + +[[package]] +name = "pluggy" +version = "1.7.0" +requires_python = ">=3.10" +summary = "plugin and hook calling mechanisms for python" +groups = ["test"] +files = [ + {file = "pluggy-1.7.0-py3-none-any.whl", hash = "sha256:7dd7b0d8832ba3cb632c306926ded123429211b83641b35dc5c41ad2d34f9bec"}, + {file = "pluggy-1.7.0.tar.gz", hash = "sha256:d1eaa46ebb595891b860ab086b4d09c8588af65ebd4361b8e8f4bb8920b90ba8"}, +] + +[[package]] +name = "pygments" +version = "2.21.0" +requires_python = ">=3.9" +summary = "Pygments is a syntax highlighting package written in Python." +groups = ["cli", "test"] +files = [ + {file = "pygments-2.21.0-py3-none-any.whl", hash = "sha256:2363c69b61c4a97c838da3b130dcd6468f4848992b21a82f2a63ec34377137d9"}, + {file = "pygments-2.21.0.tar.gz", hash = "sha256:610ca751c9bc2492b38eb9a38a7fbc93edbbb2d7182edaf34e66ae493dee5c8c"}, +] + +[[package]] +name = "pytest" +version = "9.2.0" +requires_python = ">=3.10" +summary = "pytest: simple powerful testing with Python" +groups = ["test"] +dependencies = [ + "colorama>=0.4; sys_platform == \"win32\"", + "exceptiongroup>=1; python_version < \"3.11\"", + "iniconfig>=2", + "packaging>=24", + "pluggy<2,>=1.6", + "pygments>=2.15", + "tomli>=2; python_version < \"3.11\"", +] +files = [ + {file = "pytest-9.2.0-py3-none-any.whl", hash = "sha256:07acdcf88ec174f907dc01af70bf52d49b014bbab03faeeade31c96b18c2e588"}, + {file = "pytest-9.2.0.tar.gz", hash = "sha256:97c4f3b1f3c7414aa36465e09b8220f1d03627993bd51b1282e193753c80557b"}, +] + +[[package]] +name = "rich" +version = "15.0.0" +requires_python = ">=3.9.0" +summary = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal" +groups = ["cli"] +dependencies = [ + "markdown-it-py>=2.2.0", + "pygments<3.0.0,>=2.13.0", +] +files = [ + {file = "rich-15.0.0-py3-none-any.whl", hash = "sha256:33bd4ef74232fb73fe9279a257718407f169c09b78a87ad3d296f548e27de0bb"}, + {file = "rich-15.0.0.tar.gz", hash = "sha256:edd07a4824c6b40189fb7ac9bc4c52536e9780fbbfbddf6f1e2502c31b068c36"}, +] + +[[package]] +name = "tomli" +version = "2.5.0" +requires_python = ">=3.8" +summary = "A lil' TOML parser" +groups = ["test"] +marker = "python_version < \"3.11\"" +files = [ + {file = "tomli-2.5.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:c4dc1c1781f2f716de763d1e9a7b34c6a894e167e291c7c5d16c72f7a9538545"}, + {file = "tomli-2.5.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:eff8babca5a7999bc137acbc7482a8b7e17ffca5075ab41f5d770ab408c7bfef"}, + {file = "tomli-2.5.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:86665cee9c4835b7a7f1e8ec2c719b5258d4dc782887aded5a8ae7352a96843b"}, + {file = "tomli-2.5.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:d7e369fd63331746182360977b1892bfc215476a30d61612d732425311639f56"}, + {file = "tomli-2.5.0-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:7ad1ea345759240d6463efa0ed1c704402752e49aa21476620738d74d72d8aa1"}, + {file = "tomli-2.5.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:96243987194634bd411066ce40c952e108f86af04db533ecd8ac3ff2a85b1885"}, + {file = "tomli-2.5.0-cp311-cp311-win32.whl", hash = "sha256:610b27d99f28ec5f191c7064a48f3ddb179a1fe6ca73d571483ae859f57b605e"}, + {file = "tomli-2.5.0-cp311-cp311-win_amd64.whl", hash = "sha256:c804ae44fe7b4bab5da295e4f980a1ff04670bca9d23fe0a4e887e08ebd741a8"}, + {file = "tomli-2.5.0-cp311-cp311-win_arm64.whl", hash = "sha256:cfac177ebd6236003846ea339981f71457cb6eb748f23381eb257e45092e3980"}, + {file = "tomli-2.5.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:1f4a40d03fb9f63424f0979855bdeaf44dd7696b8d59501822c10ed30ba532df"}, + {file = "tomli-2.5.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:9ebf8d19b17bd0daeb7b7dec81a946a439b753942fd0210d6e96c532249eea6b"}, + {file = "tomli-2.5.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:bf0b5e8e0f68ebb494356e577c06c139161efd8d3b9050f93b39b7c26cc54ff0"}, + {file = "tomli-2.5.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:6cf74416bdc94ae458b14e37286c1073081850ac8459a00d0c5efef5d44294c6"}, + {file = "tomli-2.5.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:61ea1ebe1e55a34ea8199cc8dbff398d35027b82271c8ac4802fd3a1fd5b1bcc"}, + {file = "tomli-2.5.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:ed53f7e89bb04f6d9e8e7799112360b0c4d5cbff067de0814c98c37c39b920f7"}, + {file = "tomli-2.5.0-cp312-cp312-win32.whl", hash = "sha256:e7ad033e27a516a233bea839cdb77b80146facb3b4f40bf02cd0cac165cdd5c2"}, + {file = "tomli-2.5.0-cp312-cp312-win_amd64.whl", hash = "sha256:bd05de8c1698f8413dd7d869492693a0bf2211543b787ac78cd5e7536af1a6d7"}, + {file = "tomli-2.5.0-cp312-cp312-win_arm64.whl", hash = "sha256:069435bd5480429b98c5e5afb02ab21c219b6f0064680671c6dc0d46817346ea"}, + {file = "tomli-2.5.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:943276cf269e0071948d9ff697159c1735e623c1151d88abb09b74659ef0cbea"}, + {file = "tomli-2.5.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:463b16086865b97facd8d0b3fb4cb7c544e3f58d2a69dc3113d6db9653fdb043"}, + {file = "tomli-2.5.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:1245a6638fc4bb0a60af38a7d45413db34a13842027c77597c712c998c62fdf0"}, + {file = "tomli-2.5.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:5d8bac3d603c97e6854424e5b2b5b741bdbde387e09f162fb0446812b4a8362b"}, + {file = "tomli-2.5.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:21e4cae4114aba25aa0d4f85cdf486d290fb35c0954d7bba536248da64d43066"}, + {file = "tomli-2.5.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:bbaefc84548d754be821bba7c4141c4787dda182f9e77f2f87b71213529efa7b"}, + {file = "tomli-2.5.0-cp313-cp313-win32.whl", hash = "sha256:abdbf6313b8d9efe157edeb7ab6eae4de064b1300ad31abf73755154b30abe68"}, + {file = "tomli-2.5.0-cp313-cp313-win_amd64.whl", hash = "sha256:fd4dc129784e0c5335bd4e61dfcc4487499a013419e655cf2da1d091b7e0efdc"}, + {file = "tomli-2.5.0-cp313-cp313-win_arm64.whl", hash = "sha256:69491c143d2fe063046e0301e62a810bed338fa4d1ce0fd870c27dc1e09b0d84"}, + {file = "tomli-2.5.0-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:d3182ee2d887e507bd67319a0a61105d1dd33facc111329559a233b772c1a105"}, + {file = "tomli-2.5.0-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:521345fd1f19d45b8df87657aaa38b6f2ca3800059fadf428e7ebf479a383646"}, + {file = "tomli-2.5.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:6e95c7614e705bfe2b04b27aa124adec59752d15813df37e2156747cab3a006b"}, + {file = "tomli-2.5.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:7ac2027d37c3afbdf4bdd377f2676f6f1d2122a5be1f1137b49dced590b37e75"}, + {file = "tomli-2.5.0-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:c414be4ed9d3cac80c42e348fa5a956117d1a48227f48026e31f59cb4a7671eb"}, + {file = "tomli-2.5.0-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:9b03d7dc168353b4132965bde20feceabaa470e570c6f59660dfae59b1f9eeb3"}, + {file = "tomli-2.5.0-cp314-cp314-win32.whl", hash = "sha256:6f041843c4d3a37245c0c056fd955b186bf8b1fb85690cbe40b81230891dc34b"}, + {file = "tomli-2.5.0-cp314-cp314-win_amd64.whl", hash = "sha256:f4b653094e18f9031102d3a1da5c729c8f222d85225b18037dac621695e46e1a"}, + {file = "tomli-2.5.0-cp314-cp314-win_arm64.whl", hash = "sha256:3f89d10c1ff6a38d992c27fc8a4816af71a909e08a40ec66934240b1e74347c3"}, + {file = "tomli-2.5.0-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:e9e15b4a6c7dd6b85b5fbab29488a73f1f70de516942308daa266bf0e0aeb0d4"}, + {file = "tomli-2.5.0-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:e12bbcd32897272fb05929110362ae9ff4c1b9bb26bd9e971e71dcd3275b4c3d"}, + {file = "tomli-2.5.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:20aa36de8f2cf87237143bc1fa1aae8d6612c09118f4da21c6a684db5dd1f6f9"}, + {file = "tomli-2.5.0-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:22185fad8a1e622f064e78008018a0dd3323550dcb479cb7a1d296888d74024f"}, + {file = "tomli-2.5.0-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:984012f71908165449a951de2050d52f276bfe3aa5d5f570f63ddad814370374"}, + {file = "tomli-2.5.0-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:f79203b3965b4000e91808aaa7c040206093f2b8bf86f455982f2274c9ccf442"}, + {file = "tomli-2.5.0-cp314-cp314t-win32.whl", hash = "sha256:91294a9fb94a75542f6e46e4a2ae709bd8d9b51134098cae5cf3bea5478b6d03"}, + {file = "tomli-2.5.0-cp314-cp314t-win_amd64.whl", hash = "sha256:f15e3e0b835a6d68b10c86bf80a3149780498d6911c93c3ffd1861d19f9200f1"}, + {file = "tomli-2.5.0-cp314-cp314t-win_arm64.whl", hash = "sha256:6664b7ae7af7294256c53960a6103077f4914cec8ff98479c352f622c6f6b2f0"}, + {file = "tomli-2.5.0-cp315-cp315-macosx_10_15_x86_64.whl", hash = "sha256:a525685c2f97da40762b8695eb7aa0af4c8344ca1905c73e4e29cb04d34607dc"}, + {file = "tomli-2.5.0-cp315-cp315-macosx_11_0_arm64.whl", hash = "sha256:9dbb18c1cfb2f6517942fc9314437f66aa06d94436ffb1f06102ef3572f35276"}, + {file = "tomli-2.5.0-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:752e8b1aa6a4367ef8bf6a1a1e005540f7ed055ba36d7193796812ca5404eb52"}, + {file = "tomli-2.5.0-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:c47300f9bf791808f77d82747691c4bb09cb14bdf3060cca99b42cdc4361d5a7"}, + {file = "tomli-2.5.0-cp315-cp315-musllinux_1_2_aarch64.whl", hash = "sha256:19b0dd8749f4ea2f112c5fcfb3c5248390c899d7e2e173f1d91abee1fa0ff391"}, + {file = "tomli-2.5.0-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:57b1c3b01fab802e2899bc3d168dca320e14165e2fd9fd584760fb4ca5826859"}, + {file = "tomli-2.5.0-cp315-cp315-win32.whl", hash = "sha256:667e521b37a6c5ccaa044202c235b530f90177ffe2cd4a64ecc213c7dd535feb"}, + {file = "tomli-2.5.0-cp315-cp315-win_amd64.whl", hash = "sha256:d747252933c8a65ef6bd8da0fbb7ce28a90eb6119d8cd00772cd528aa07b68d5"}, + {file = "tomli-2.5.0-cp315-cp315-win_arm64.whl", hash = "sha256:75dbcde8751b0a960aa3de173aa5e894d590755c6d7758b7e774c06f1dc3cbdd"}, + {file = "tomli-2.5.0-cp315-cp315t-macosx_10_15_x86_64.whl", hash = "sha256:2419c2a189551987b59d80e63ec355671283336f41c6b9b89462df679c7d0c57"}, + {file = "tomli-2.5.0-cp315-cp315t-macosx_11_0_arm64.whl", hash = "sha256:0dc598040da8d42cf20f0be588ed7004f46db12a0ac6c32e03a59dccedaaadcd"}, + {file = "tomli-2.5.0-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:49096930c8d886c9bbdab62d2d0d17ce823ddeea522309a190b36245d5b49e01"}, + {file = "tomli-2.5.0-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:b8ade5023067f99fe72b88accd30d0ea05a158e9e32a11f124e731ea9695313f"}, + {file = "tomli-2.5.0-cp315-cp315t-musllinux_1_2_aarch64.whl", hash = "sha256:b69564772b5c8f22ea5f498dff08cfa825045b4d4c4400529000bdf818aa3b2a"}, + {file = "tomli-2.5.0-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:8ff3a2ca028c7eee0c777f9a092038d0a594a9fa04e215f929a22c329e2cb142"}, + {file = "tomli-2.5.0-cp315-cp315t-win32.whl", hash = "sha256:62fc1bc8eb03e3a9cadfca713d65614ed8e09d974a283295ffe3a831976b4dc5"}, + {file = "tomli-2.5.0-cp315-cp315t-win_amd64.whl", hash = "sha256:f3fcbc57b1791fa6cbe5d8434179d51de12be1a4811469529f47f6e7487a2571"}, + {file = "tomli-2.5.0-cp315-cp315t-win_arm64.whl", hash = "sha256:d2ba24db8a9376921b5e87b4762b9adb0f3f1deaea68f2b8b0bb2c11efb9c3e7"}, + {file = "tomli-2.5.0-py3-none-any.whl", hash = "sha256:32a7b79ac57a2e83670ce329ccf675798bc5a2094783a63676866b70503f2e2b"}, + {file = "tomli-2.5.0.tar.gz", hash = "sha256:264507556cd8b8c8e7c6ee037cdf443a463f03f4c958e57195e3d369711b8ff6"}, +] + +[[package]] +name = "typing-extensions" +version = "4.16.0" +requires_python = ">=3.9" +summary = "Backported and Experimental Type Hints for Python 3.9+" +groups = ["default", "test"] +marker = "python_version < \"3.15\"" +files = [ + {file = "typing_extensions-4.16.0-py3-none-any.whl", hash = "sha256:481caa481374e813c1b176ada14e97f1f67a4539ce9cfeb3f350d78d6370c2e8"}, + {file = "typing_extensions-4.16.0.tar.gz", hash = "sha256:dc983d19a509c94dba722ee6abd33940f7c05a89e243c47e907eb4db6f1a43e5"}, +] diff --git a/packages/extractors/python-dependencies/tests/fixtures/pdm/pyproject.toml b/packages/extractors/python-dependencies/tests/fixtures/pdm/pyproject.toml new file mode 100644 index 000000000..02a4943a5 --- /dev/null +++ b/packages/extractors/python-dependencies/tests/fixtures/pdm/pyproject.toml @@ -0,0 +1,17 @@ +[project] +name = "beacon" +version = "0.9.0" +requires-python = ">=3.10" +dependencies = [ + "httpx[http2]>=0.27", + "attrs>=24", +] + +[project.optional-dependencies] +cli = ["rich>=13"] + +[dependency-groups] +test = ["pytest>=8"] + +[tool.pdm] +distribution = false diff --git a/packages/extractors/python-dependencies/tests/fixtures/poetry.expected.json b/packages/extractors/python-dependencies/tests/fixtures/poetry.expected.json new file mode 100644 index 000000000..766dc988f --- /dev/null +++ b/packages/extractors/python-dependencies/tests/fixtures/poetry.expected.json @@ -0,0 +1,770 @@ +{ + "entities": [ + { + "confidence": "authoritative", + "data": { + "version": "4.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "id": "package:anyio", + "kind": "package", + "label": "anyio" + }, + { + "confidence": "authoritative", + "data": { + "version": "2026.11.20" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "id": "package:certifi", + "kind": "package", + "label": "certifi" + }, + { + "confidence": "authoritative", + "data": { + "version": "8.5.1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "id": "package:click", + "kind": "package", + "label": "click" + }, + { + "confidence": "authoritative", + "data": { + "version": "0.4.6" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "id": "package:colorama", + "kind": "package", + "label": "colorama" + }, + { + "confidence": "authoritative", + "data": { + "version": "1.3.2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "id": "package:exceptiongroup", + "kind": "package", + "label": "exceptiongroup" + }, + { + "confidence": "authoritative", + "data": { + "version": "0.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "id": "package:h11", + "kind": "package", + "label": "h11" + }, + { + "confidence": "authoritative", + "data": { + "version": "1.0.9" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "id": "package:httpcore", + "kind": "package", + "label": "httpcore" + }, + { + "confidence": "authoritative", + "data": { + "version": "0.29.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "id": "package:httpx", + "kind": "package", + "label": "httpx" + }, + { + "confidence": "authoritative", + "data": { + "version": "3.20" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "id": "package:idna", + "kind": "package", + "label": "idna" + }, + { + "confidence": "authoritative", + "data": { + "version": "2.3.1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "id": "package:iniconfig", + "kind": "package", + "label": "iniconfig" + }, + { + "confidence": "authoritative", + "data": { + "version": "26.4" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "id": "package:packaging", + "kind": "package", + "label": "packaging" + }, + { + "confidence": "authoritative", + "data": { + "version": "1.7.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "id": "package:pluggy", + "kind": "package", + "label": "pluggy" + }, + { + "confidence": "authoritative", + "data": { + "version": "3.3.9" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "id": "package:psycopg", + "kind": "package", + "label": "psycopg" + }, + { + "confidence": "authoritative", + "data": { + "version": "2.21.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "id": "package:pygments", + "kind": "package", + "label": "pygments" + }, + { + "confidence": "authoritative", + "data": { + "version": "8.4.2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "id": "package:pytest", + "kind": "package", + "label": "pytest" + }, + { + "confidence": "authoritative", + "data": { + "version": "1.0.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "id": "package:socksio", + "kind": "package", + "label": "socksio" + }, + { + "confidence": "authoritative", + "data": { + "version": "2.5.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "id": "package:tomli", + "kind": "package", + "label": "tomli" + }, + { + "confidence": "authoritative", + "data": { + "version": "4.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "id": "package:typing-extensions", + "kind": "package", + "label": "typing-extensions" + }, + { + "confidence": "authoritative", + "data": { + "version": "2026.6" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "id": "package:tzdata", + "kind": "package", + "label": "tzdata" + }, + { + "confidence": "authoritative", + "data": { + "path": ".", + "version": "2.1.0" + }, + "evidence": [ + { + "kind": "manifest", + "source": "pyproject.toml" + } + ], + "id": "project:ledger", + "kind": "project", + "label": "ledger" + } + ], + "metadata": { + "limitations": [ + "Every extra and dependency group a project declares is included; a package's extras are followed only where a dependency in the graph requests them.", + "Environment markers are recorded on relationships as `marker` but not evaluated: the graph covers every platform and Python version at once." + ], + "lockfile": "poetry.lock", + "lockfileVersion": "2.1", + "manager": "poetry", + "unresolved": [] + }, + "protocolVersion": 0, + "relationships": [ + { + "confidence": "authoritative", + "data": { + "resolved": "8.5.1", + "type": "dependencies", + "version": "^8.1" + }, + "evidence": [ + { + "kind": "manifest", + "source": "pyproject.toml" + } + ], + "from": "project:ledger", + "id": "dependency:[\"ledger\",\"dependencies\",\"click\"]", + "kind": "dependencies", + "label": "^8.1", + "to": "package:click" + }, + { + "confidence": "authoritative", + "data": { + "extras": [ + "socks" + ], + "resolved": "0.29.0", + "type": "dependencies", + "version": ">=0.27" + }, + "evidence": [ + { + "kind": "manifest", + "source": "pyproject.toml" + } + ], + "from": "project:ledger", + "id": "dependency:[\"ledger\",\"dependencies\",\"httpx\"]", + "kind": "dependencies", + "label": ">=0.27", + "to": "package:httpx" + }, + { + "confidence": "authoritative", + "data": { + "group": "test", + "resolved": "8.4.2", + "type": "devDependencies", + "version": "^8" + }, + "evidence": [ + { + "kind": "manifest", + "source": "pyproject.toml" + } + ], + "from": "project:ledger", + "id": "dependency:[\"ledger\",\"devDependencies\",\"test\",\"pytest\"]", + "kind": "devDependencies", + "label": "^8", + "to": "package:pytest" + }, + { + "confidence": "authoritative", + "data": { + "extra": "postgres", + "resolved": "3.3.9", + "type": "optionalDependencies", + "version": "^3.2" + }, + "evidence": [ + { + "kind": "manifest", + "source": "pyproject.toml" + } + ], + "from": "project:ledger", + "id": "dependency:[\"ledger\",\"optionalDependencies\",\"postgres\",\"psycopg\"]", + "kind": "optionalDependencies", + "label": "^3.2", + "to": "package:psycopg" + }, + { + "confidence": "authoritative", + "data": { + "marker": "python_version < \"3.11\"", + "type": "dependencies", + "version": ">=1.0.2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "from": "package:anyio", + "id": "dependency:[\"package:anyio\",\"dependencies\",\"exceptiongroup\"]", + "kind": "dependencies", + "label": ">=1.0.2", + "to": "package:exceptiongroup" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": ">=2.8" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "from": "package:anyio", + "id": "dependency:[\"package:anyio\",\"dependencies\",\"idna\"]", + "kind": "dependencies", + "label": ">=2.8", + "to": "package:idna" + }, + { + "confidence": "authoritative", + "data": { + "marker": "python_version < \"3.15\"", + "type": "dependencies", + "version": ">=4.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "from": "package:anyio", + "id": "dependency:[\"package:anyio\",\"dependencies\",\"typing-extensions\"]", + "kind": "dependencies", + "label": ">=4.16.0", + "to": "package:typing-extensions" + }, + { + "confidence": "authoritative", + "data": { + "marker": "python_version < \"3.13\"", + "type": "dependencies", + "version": ">=4.6.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "from": "package:exceptiongroup", + "id": "dependency:[\"package:exceptiongroup\",\"dependencies\",\"typing-extensions\"]", + "kind": "dependencies", + "label": ">=4.6.0", + "to": "package:typing-extensions" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "*" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "from": "package:httpcore", + "id": "dependency:[\"package:httpcore\",\"dependencies\",\"certifi\"]", + "kind": "dependencies", + "label": "*", + "to": "package:certifi" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": ">=0.16" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "from": "package:httpcore", + "id": "dependency:[\"package:httpcore\",\"dependencies\",\"h11\"]", + "kind": "dependencies", + "label": ">=0.16", + "to": "package:h11" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "*" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"dependencies\",\"anyio\"]", + "kind": "dependencies", + "label": "*", + "to": "package:anyio" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "*" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"dependencies\",\"certifi\"]", + "kind": "dependencies", + "label": "*", + "to": "package:certifi" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==1.*" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"dependencies\",\"httpcore\"]", + "kind": "dependencies", + "label": "==1.*", + "to": "package:httpcore" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "*" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"dependencies\",\"idna\"]", + "kind": "dependencies", + "label": "*", + "to": "package:idna" + }, + { + "confidence": "authoritative", + "data": { + "extra": "socks", + "marker": "extra == \"socks\"", + "type": "optionalDependencies", + "version": "==1.*" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"optionalDependencies\",\"socks\",\"socksio\"]", + "kind": "optionalDependencies", + "label": "==1.*", + "to": "package:socksio" + }, + { + "confidence": "authoritative", + "data": { + "marker": "python_version < \"3.13\"", + "type": "dependencies", + "version": ">=4.6" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "from": "package:psycopg", + "id": "dependency:[\"package:psycopg\",\"dependencies\",\"typing-extensions\"]", + "kind": "dependencies", + "label": ">=4.6", + "to": "package:typing-extensions" + }, + { + "confidence": "authoritative", + "data": { + "marker": "sys_platform == \"win32\"", + "type": "dependencies", + "version": "*" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "from": "package:psycopg", + "id": "dependency:[\"package:psycopg\",\"dependencies\",\"tzdata\"]", + "kind": "dependencies", + "label": "*", + "to": "package:tzdata" + }, + { + "confidence": "authoritative", + "data": { + "marker": "sys_platform == \"win32\"", + "type": "dependencies", + "version": ">=0.4" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"colorama\"]", + "kind": "dependencies", + "label": ">=0.4", + "to": "package:colorama" + }, + { + "confidence": "authoritative", + "data": { + "marker": "python_version < \"3.11\"", + "type": "dependencies", + "version": ">=1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"exceptiongroup\"]", + "kind": "dependencies", + "label": ">=1", + "to": "package:exceptiongroup" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": ">=1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"iniconfig\"]", + "kind": "dependencies", + "label": ">=1", + "to": "package:iniconfig" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": ">=20" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"packaging\"]", + "kind": "dependencies", + "label": ">=20", + "to": "package:packaging" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": ">=1.5,<2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"pluggy\"]", + "kind": "dependencies", + "label": ">=1.5,<2", + "to": "package:pluggy" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": ">=2.7.2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"pygments\"]", + "kind": "dependencies", + "label": ">=2.7.2", + "to": "package:pygments" + }, + { + "confidence": "authoritative", + "data": { + "marker": "python_version < \"3.11\"", + "type": "dependencies", + "version": ">=1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "poetry.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"tomli\"]", + "kind": "dependencies", + "label": ">=1", + "to": "package:tomli" + } + ], + "schema": "graph/v0" +} diff --git a/packages/extractors/python-dependencies/tests/fixtures/poetry/poetry.lock b/packages/extractors/python-dependencies/tests/fixtures/poetry/poetry.lock new file mode 100644 index 000000000..ca068f894 --- /dev/null +++ b/packages/extractors/python-dependencies/tests/fixtures/poetry/poetry.lock @@ -0,0 +1,393 @@ +# This file is automatically @generated by Poetry 2.5.2 and should not be changed by hand. + +[[package]] +name = "anyio" +version = "4.16.0" +description = "High-level concurrency and networking framework on top of asyncio or Trio" +optional = false +python-versions = ">=3.10" +groups = ["main"] +files = [ + {file = "anyio-4.16.0-py3-none-any.whl", hash = "sha256:c66ae634e0b8228396b801741beb3294326d4b6102f7bba4041c0dfb58c29026"}, + {file = "anyio-4.16.0.tar.gz", hash = "sha256:59bb03251907983d1603d27c3087ddb1e93299ea2163adcdba37899a4fb12ffb"}, +] + +[package.dependencies] +exceptiongroup = {version = ">=1.0.2", markers = "python_version < \"3.11\""} +idna = ">=2.8" +typing_extensions = {version = ">=4.16.0", markers = "python_version < \"3.15\""} + +[package.extras] +trio = ["trio (>=0.32.0)"] + + +[[package]] +name = "certifi" +version = "2026.11.20" +description = "Python package for providing Mozilla's CA Bundle." +optional = false +python-versions = ">=3.7" +groups = ["main"] +files = [ + {file = "certifi-2026.11.20-py3-none-any.whl", hash = "sha256:7422df25243767b9877031a2248cb14d09ddac9beee846f4cef3d5c9191d488f"}, + {file = "certifi-2026.11.20.tar.gz", hash = "sha256:af1cb240a8133f105aa52684a3a3258339d7f2fd0bd4e2812698ff5cf5588c4e"}, +] + + +[[package]] +name = "click" +version = "8.5.1" +description = "Composable command line interface toolkit" +optional = false +python-versions = ">=3.10" +groups = ["main"] +files = [ + {file = "click-8.5.1-py3-none-any.whl", hash = "sha256:8bb5376d2006950386f8c6427613334a2acadc5f559cb80e638d00b4df957e37"}, + {file = "click-8.5.1.tar.gz", hash = "sha256:9bbfada76703fd1d784b83eea012e3e8c6a001a876543ef104fa56aaaeb072b4"}, +] + + +[[package]] +name = "colorama" +version = "0.4.6" +description = "Cross-platform colored terminal text." +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" +groups = ["test"] +markers = "sys_platform == \"win32\"" +files = [ + {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, + {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, +] + + +[[package]] +name = "exceptiongroup" +version = "1.3.2" +description = "Backport of PEP 654 (exception groups)" +optional = false +python-versions = ">=3.7" +groups = ["main", "test"] +markers = "python_version == \"3.10\"" +files = [ + {file = "exceptiongroup-1.3.2-py3-none-any.whl", hash = "sha256:41c6a70dfec22050d3d8b43386b059a4dc0bca3f3d40a40971cb206fff1785af"}, + {file = "exceptiongroup-1.3.2.tar.gz", hash = "sha256:ca82e69f0cb535fbde934885744b67669a3efddd50fe7bc00d3398839fcaddec"}, +] + +[package.dependencies] +typing-extensions = {version = ">=4.6.0", markers = "python_version < \"3.13\""} + +[package.extras] +test = ["pytest (>=6)"] + + +[[package]] +name = "h11" +version = "0.16.0" +description = "A pure-Python, bring-your-own-I/O implementation of HTTP/1.1" +optional = false +python-versions = ">=3.8" +groups = ["main"] +files = [ + {file = "h11-0.16.0-py3-none-any.whl", hash = "sha256:63cf8bbe7522de3bf65932fda1d9c2772064ffb3dae62d55932da54b31cb6c86"}, + {file = "h11-0.16.0.tar.gz", hash = "sha256:4e35b956cf45792e4caa5885e69fba00bdbc6ffafbfa020300e549b208ee5ff1"}, +] + + +[[package]] +name = "httpcore" +version = "1.0.9" +description = "A minimal low-level HTTP client." +optional = false +python-versions = ">=3.8" +groups = ["main"] +files = [ + {file = "httpcore-1.0.9-py3-none-any.whl", hash = "sha256:2d400746a40668fc9dec9810239072b40b4484b640a8c38fd654a024c7a1bf55"}, + {file = "httpcore-1.0.9.tar.gz", hash = "sha256:6e34463af53fd2ab5d807f399a9b45ea31c3dfa2276f15a2c3f00afff6e176e8"}, +] + +[package.dependencies] +certifi = "*" +h11 = ">=0.16" + +[package.extras] +asyncio = ["anyio (>=4.0,<5.0)"] +http2 = ["h2 (>=3,<5)"] +socks = ["socksio (==1.*)"] +trio = ["trio (>=0.22.0,<1.0)"] + + +[[package]] +name = "httpx" +version = "0.29.0" +description = "The next generation HTTP client." +optional = false +python-versions = ">=3.10" +groups = ["main"] +files = [ + {file = "httpx-0.29.0-py3-none-any.whl", hash = "sha256:6734dcf742ced6e8018e45d3f9f7728975b6b3e1085a24f3e2c056069d858bd1"}, + {file = "httpx-0.29.0.tar.gz", hash = "sha256:700928ee6c1f4213795e67c47eba8f8553639069fea89199f71d654e38edc593"}, +] + +[package.dependencies] +anyio = "*" +certifi = "*" +httpcore = "==1.*" +idna = "*" +socksio = {version = "==1.*", optional = true, markers = "extra == \"socks\""} + +[package.extras] +brotli = ["brotli ; platform_python_implementation == \"CPython\"", "brotlicffi ; platform_python_implementation != \"CPython\""] +cli = ["click (==8.*)", "pygments (==2.*)", "rich (>=10,<15)"] +http2 = ["h2 (>=3,<5)"] +socks = ["socksio (==1.*)"] +zstd = ["zstandard (>=0.18.0)"] + + +[[package]] +name = "idna" +version = "3.20" +description = "Internationalized Domain Names in Applications (IDNA)" +optional = false +python-versions = ">=3.9" +groups = ["main"] +files = [ + {file = "idna-3.20-py3-none-any.whl", hash = "sha256:ab7ae7122974553370f0bdb919e1a960b2cd1bc1ef0276416d896db81c14582c"}, + {file = "idna-3.20.tar.gz", hash = "sha256:a7db850025b95ded1eae8a46181a1a6c56c92c96f0e2b005d9ff8dc0210cab44"}, +] + +[package.extras] +all = ["coverage (>=7.10.0)", "hypothesis (>=6.141.1)", "mypy (>=1.11.2)", "pytest (>=8.3.2)", "ruff (>=0.16.0)", "ty (>=0.0.37)"] + + +[[package]] +name = "iniconfig" +version = "2.3.1" +description = "brain-dead simple config-ini parsing" +optional = false +python-versions = ">=3.10" +groups = ["test"] +files = [ + {file = "iniconfig-2.3.1-py3-none-any.whl", hash = "sha256:9121e2c1fdb355232495be3194c8dfe87ccc2d5dee45947b78e68f499790d7a7"}, + {file = "iniconfig-2.3.1.tar.gz", hash = "sha256:67f4b9c50da0dedf52af349e7749a80a9057a5031199791b906c3bb3ae878960"}, +] + + +[[package]] +name = "packaging" +version = "26.4" +description = "Core utilities for Python packages" +optional = false +python-versions = ">=3.10" +groups = ["test"] +files = [ + {file = "packaging-26.4-py3-none-any.whl", hash = "sha256:81383611a09c1bc0b08b76e0fd5829d7c6824c65b27a6aee339da133f4233ea2"}, + {file = "packaging-26.4.tar.gz", hash = "sha256:c4b671c41ddb9bf26e543c37723610d28fb6bf7affc4da17cf048d419d2c062a"}, +] + + +[[package]] +name = "pluggy" +version = "1.7.0" +description = "plugin and hook calling mechanisms for python" +optional = false +python-versions = ">=3.10" +groups = ["test"] +files = [ + {file = "pluggy-1.7.0-py3-none-any.whl", hash = "sha256:7dd7b0d8832ba3cb632c306926ded123429211b83641b35dc5c41ad2d34f9bec"}, + {file = "pluggy-1.7.0.tar.gz", hash = "sha256:d1eaa46ebb595891b860ab086b4d09c8588af65ebd4361b8e8f4bb8920b90ba8"}, +] + + +[[package]] +name = "psycopg" +version = "3.3.9" +description = "PostgreSQL database adapter for Python" +optional = true +python-versions = ">=3.10" +groups = ["main"] +markers = "extra == \"postgres\"" +files = [ + {file = "psycopg-3.3.9-py3-none-any.whl", hash = "sha256:d2d7d04a1ce6dab4f5b27316bea3b52585cafa2f2d631e5b09dd69823f5c26f6"}, + {file = "psycopg-3.3.9.tar.gz", hash = "sha256:87c1d85c3e0e88e811d3c0b3808f947bd967c6faf34af6cd86fd021f77793d6c"}, +] + +[package.dependencies] +typing-extensions = {version = ">=4.6", markers = "python_version < \"3.13\""} +tzdata = {version = "*", markers = "sys_platform == \"win32\""} + +[package.extras] +binary = ["psycopg-binary (==3.3.9) ; implementation_name != \"pypy\""] +c = ["psycopg-c (==3.3.9) ; implementation_name != \"pypy\""] +dev = ["ast-comments (>=1.1.2)", "black (>=26.1.0)", "codespell (>=2.2)", "cython-lint (>=0.21)", "dnspython (>=2.1)", "flake8 (>=4.0)", "isort-psycopg (>=0.0.3)", "isort[colors] (>=6.0)", "mypy (>=2.1.0)", "pre-commit (>=4.0.1)", "types-setuptools (>=57.4)", "types-shapely (>=2.0)", "wheel (>=0.37)"] +docs = ["Sphinx (>=9.1)", "furo (==2025.12.19)", "sphinx-autobuild (>=2025.8.25)", "sphinx-autodoc-typehints (>=3.10.2)"] +pool = ["psycopg-pool"] +test = ["anyio (>=4.0)", "mypy (>=2.1.0) ; implementation_name != \"pypy\"", "pproxy (>=2.7)", "pytest (>=6.2.5)", "pytest-cov (>=3.0)", "pytest-randomly (>=3.5)"] + + +[[package]] +name = "pygments" +version = "2.21.0" +description = "Pygments is a syntax highlighting package written in Python." +optional = false +python-versions = ">=3.9" +groups = ["test"] +files = [ + {file = "pygments-2.21.0-py3-none-any.whl", hash = "sha256:2363c69b61c4a97c838da3b130dcd6468f4848992b21a82f2a63ec34377137d9"}, + {file = "pygments-2.21.0.tar.gz", hash = "sha256:610ca751c9bc2492b38eb9a38a7fbc93edbbb2d7182edaf34e66ae493dee5c8c"}, +] + +[package.extras] +windows-terminal = ["colorama (>=0.4.6)"] + + +[[package]] +name = "pytest" +version = "8.4.2" +description = "pytest: simple powerful testing with Python" +optional = false +python-versions = ">=3.9" +groups = ["test"] +files = [ + {file = "pytest-8.4.2-py3-none-any.whl", hash = "sha256:872f880de3fc3a5bdc88a11b39c9710c3497a547cfa9320bc3c5e62fbf272e79"}, + {file = "pytest-8.4.2.tar.gz", hash = "sha256:86c0d0b93306b961d58d62a4db4879f27fe25513d4b969df351abdddb3c30e01"}, +] + +[package.dependencies] +colorama = {version = ">=0.4", markers = "sys_platform == \"win32\""} +exceptiongroup = {version = ">=1", markers = "python_version < \"3.11\""} +iniconfig = ">=1" +packaging = ">=20" +pluggy = ">=1.5,<2" +pygments = ">=2.7.2" +tomli = {version = ">=1", markers = "python_version < \"3.11\""} + +[package.extras] +dev = ["argcomplete", "attrs (>=19.2)", "hypothesis (>=3.56)", "mock", "requests", "setuptools", "xmlschema"] + + +[[package]] +name = "socksio" +version = "1.0.0" +description = "Sans-I/O implementation of SOCKS4, SOCKS4A, and SOCKS5." +optional = false +python-versions = ">=3.6" +groups = ["main"] +files = [ + {file = "socksio-1.0.0-py3-none-any.whl", hash = "sha256:95dc1f15f9b34e8d7b16f06d74b8ccf48f609af32ab33c608d08761c5dcbb1f3"}, + {file = "socksio-1.0.0.tar.gz", hash = "sha256:f88beb3da5b5c38b9890469de67d0cb0f9d494b78b106ca1845f96c10b91c4ac"}, +] + + +[[package]] +name = "tomli" +version = "2.5.0" +description = "A lil' TOML parser" +optional = false +python-versions = ">=3.8" +groups = ["test"] +markers = "python_version == \"3.10\"" +files = [ + {file = "tomli-2.5.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:c4dc1c1781f2f716de763d1e9a7b34c6a894e167e291c7c5d16c72f7a9538545"}, + {file = "tomli-2.5.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:eff8babca5a7999bc137acbc7482a8b7e17ffca5075ab41f5d770ab408c7bfef"}, + {file = "tomli-2.5.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:86665cee9c4835b7a7f1e8ec2c719b5258d4dc782887aded5a8ae7352a96843b"}, + {file = "tomli-2.5.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:d7e369fd63331746182360977b1892bfc215476a30d61612d732425311639f56"}, + {file = "tomli-2.5.0-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:7ad1ea345759240d6463efa0ed1c704402752e49aa21476620738d74d72d8aa1"}, + {file = "tomli-2.5.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:96243987194634bd411066ce40c952e108f86af04db533ecd8ac3ff2a85b1885"}, + {file = "tomli-2.5.0-cp311-cp311-win32.whl", hash = "sha256:610b27d99f28ec5f191c7064a48f3ddb179a1fe6ca73d571483ae859f57b605e"}, + {file = "tomli-2.5.0-cp311-cp311-win_amd64.whl", hash = "sha256:c804ae44fe7b4bab5da295e4f980a1ff04670bca9d23fe0a4e887e08ebd741a8"}, + {file = "tomli-2.5.0-cp311-cp311-win_arm64.whl", hash = "sha256:cfac177ebd6236003846ea339981f71457cb6eb748f23381eb257e45092e3980"}, + {file = "tomli-2.5.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:1f4a40d03fb9f63424f0979855bdeaf44dd7696b8d59501822c10ed30ba532df"}, + {file = "tomli-2.5.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:9ebf8d19b17bd0daeb7b7dec81a946a439b753942fd0210d6e96c532249eea6b"}, + {file = "tomli-2.5.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:bf0b5e8e0f68ebb494356e577c06c139161efd8d3b9050f93b39b7c26cc54ff0"}, + {file = "tomli-2.5.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:6cf74416bdc94ae458b14e37286c1073081850ac8459a00d0c5efef5d44294c6"}, + {file = "tomli-2.5.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:61ea1ebe1e55a34ea8199cc8dbff398d35027b82271c8ac4802fd3a1fd5b1bcc"}, + {file = "tomli-2.5.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:ed53f7e89bb04f6d9e8e7799112360b0c4d5cbff067de0814c98c37c39b920f7"}, + {file = "tomli-2.5.0-cp312-cp312-win32.whl", hash = "sha256:e7ad033e27a516a233bea839cdb77b80146facb3b4f40bf02cd0cac165cdd5c2"}, + {file = "tomli-2.5.0-cp312-cp312-win_amd64.whl", hash = "sha256:bd05de8c1698f8413dd7d869492693a0bf2211543b787ac78cd5e7536af1a6d7"}, + {file = "tomli-2.5.0-cp312-cp312-win_arm64.whl", hash = "sha256:069435bd5480429b98c5e5afb02ab21c219b6f0064680671c6dc0d46817346ea"}, + {file = "tomli-2.5.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:943276cf269e0071948d9ff697159c1735e623c1151d88abb09b74659ef0cbea"}, + {file = "tomli-2.5.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:463b16086865b97facd8d0b3fb4cb7c544e3f58d2a69dc3113d6db9653fdb043"}, + {file = "tomli-2.5.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:1245a6638fc4bb0a60af38a7d45413db34a13842027c77597c712c998c62fdf0"}, + {file = "tomli-2.5.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:5d8bac3d603c97e6854424e5b2b5b741bdbde387e09f162fb0446812b4a8362b"}, + {file = "tomli-2.5.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:21e4cae4114aba25aa0d4f85cdf486d290fb35c0954d7bba536248da64d43066"}, + {file = "tomli-2.5.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:bbaefc84548d754be821bba7c4141c4787dda182f9e77f2f87b71213529efa7b"}, + {file = "tomli-2.5.0-cp313-cp313-win32.whl", hash = "sha256:abdbf6313b8d9efe157edeb7ab6eae4de064b1300ad31abf73755154b30abe68"}, + {file = "tomli-2.5.0-cp313-cp313-win_amd64.whl", hash = "sha256:fd4dc129784e0c5335bd4e61dfcc4487499a013419e655cf2da1d091b7e0efdc"}, + {file = "tomli-2.5.0-cp313-cp313-win_arm64.whl", hash = "sha256:69491c143d2fe063046e0301e62a810bed338fa4d1ce0fd870c27dc1e09b0d84"}, + {file = "tomli-2.5.0-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:d3182ee2d887e507bd67319a0a61105d1dd33facc111329559a233b772c1a105"}, + {file = "tomli-2.5.0-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:521345fd1f19d45b8df87657aaa38b6f2ca3800059fadf428e7ebf479a383646"}, + {file = "tomli-2.5.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:6e95c7614e705bfe2b04b27aa124adec59752d15813df37e2156747cab3a006b"}, + {file = "tomli-2.5.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:7ac2027d37c3afbdf4bdd377f2676f6f1d2122a5be1f1137b49dced590b37e75"}, + {file = "tomli-2.5.0-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:c414be4ed9d3cac80c42e348fa5a956117d1a48227f48026e31f59cb4a7671eb"}, + {file = "tomli-2.5.0-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:9b03d7dc168353b4132965bde20feceabaa470e570c6f59660dfae59b1f9eeb3"}, + {file = "tomli-2.5.0-cp314-cp314-win32.whl", hash = "sha256:6f041843c4d3a37245c0c056fd955b186bf8b1fb85690cbe40b81230891dc34b"}, + {file = "tomli-2.5.0-cp314-cp314-win_amd64.whl", hash = "sha256:f4b653094e18f9031102d3a1da5c729c8f222d85225b18037dac621695e46e1a"}, + {file = "tomli-2.5.0-cp314-cp314-win_arm64.whl", hash = "sha256:3f89d10c1ff6a38d992c27fc8a4816af71a909e08a40ec66934240b1e74347c3"}, + {file = "tomli-2.5.0-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:e9e15b4a6c7dd6b85b5fbab29488a73f1f70de516942308daa266bf0e0aeb0d4"}, + {file = "tomli-2.5.0-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:e12bbcd32897272fb05929110362ae9ff4c1b9bb26bd9e971e71dcd3275b4c3d"}, + {file = "tomli-2.5.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:20aa36de8f2cf87237143bc1fa1aae8d6612c09118f4da21c6a684db5dd1f6f9"}, + {file = "tomli-2.5.0-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:22185fad8a1e622f064e78008018a0dd3323550dcb479cb7a1d296888d74024f"}, + {file = "tomli-2.5.0-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:984012f71908165449a951de2050d52f276bfe3aa5d5f570f63ddad814370374"}, + {file = "tomli-2.5.0-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:f79203b3965b4000e91808aaa7c040206093f2b8bf86f455982f2274c9ccf442"}, + {file = "tomli-2.5.0-cp314-cp314t-win32.whl", hash = "sha256:91294a9fb94a75542f6e46e4a2ae709bd8d9b51134098cae5cf3bea5478b6d03"}, + {file = "tomli-2.5.0-cp314-cp314t-win_amd64.whl", hash = "sha256:f15e3e0b835a6d68b10c86bf80a3149780498d6911c93c3ffd1861d19f9200f1"}, + {file = "tomli-2.5.0-cp314-cp314t-win_arm64.whl", hash = "sha256:6664b7ae7af7294256c53960a6103077f4914cec8ff98479c352f622c6f6b2f0"}, + {file = "tomli-2.5.0-cp315-cp315-macosx_10_15_x86_64.whl", hash = "sha256:a525685c2f97da40762b8695eb7aa0af4c8344ca1905c73e4e29cb04d34607dc"}, + {file = "tomli-2.5.0-cp315-cp315-macosx_11_0_arm64.whl", hash = "sha256:9dbb18c1cfb2f6517942fc9314437f66aa06d94436ffb1f06102ef3572f35276"}, + {file = "tomli-2.5.0-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:752e8b1aa6a4367ef8bf6a1a1e005540f7ed055ba36d7193796812ca5404eb52"}, + {file = "tomli-2.5.0-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:c47300f9bf791808f77d82747691c4bb09cb14bdf3060cca99b42cdc4361d5a7"}, + {file = "tomli-2.5.0-cp315-cp315-musllinux_1_2_aarch64.whl", hash = "sha256:19b0dd8749f4ea2f112c5fcfb3c5248390c899d7e2e173f1d91abee1fa0ff391"}, + {file = "tomli-2.5.0-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:57b1c3b01fab802e2899bc3d168dca320e14165e2fd9fd584760fb4ca5826859"}, + {file = "tomli-2.5.0-cp315-cp315-win32.whl", hash = "sha256:667e521b37a6c5ccaa044202c235b530f90177ffe2cd4a64ecc213c7dd535feb"}, + {file = "tomli-2.5.0-cp315-cp315-win_amd64.whl", hash = "sha256:d747252933c8a65ef6bd8da0fbb7ce28a90eb6119d8cd00772cd528aa07b68d5"}, + {file = "tomli-2.5.0-cp315-cp315-win_arm64.whl", hash = "sha256:75dbcde8751b0a960aa3de173aa5e894d590755c6d7758b7e774c06f1dc3cbdd"}, + {file = "tomli-2.5.0-cp315-cp315t-macosx_10_15_x86_64.whl", hash = "sha256:2419c2a189551987b59d80e63ec355671283336f41c6b9b89462df679c7d0c57"}, + {file = "tomli-2.5.0-cp315-cp315t-macosx_11_0_arm64.whl", hash = "sha256:0dc598040da8d42cf20f0be588ed7004f46db12a0ac6c32e03a59dccedaaadcd"}, + {file = "tomli-2.5.0-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:49096930c8d886c9bbdab62d2d0d17ce823ddeea522309a190b36245d5b49e01"}, + {file = "tomli-2.5.0-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:b8ade5023067f99fe72b88accd30d0ea05a158e9e32a11f124e731ea9695313f"}, + {file = "tomli-2.5.0-cp315-cp315t-musllinux_1_2_aarch64.whl", hash = "sha256:b69564772b5c8f22ea5f498dff08cfa825045b4d4c4400529000bdf818aa3b2a"}, + {file = "tomli-2.5.0-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:8ff3a2ca028c7eee0c777f9a092038d0a594a9fa04e215f929a22c329e2cb142"}, + {file = "tomli-2.5.0-cp315-cp315t-win32.whl", hash = "sha256:62fc1bc8eb03e3a9cadfca713d65614ed8e09d974a283295ffe3a831976b4dc5"}, + {file = "tomli-2.5.0-cp315-cp315t-win_amd64.whl", hash = "sha256:f3fcbc57b1791fa6cbe5d8434179d51de12be1a4811469529f47f6e7487a2571"}, + {file = "tomli-2.5.0-cp315-cp315t-win_arm64.whl", hash = "sha256:d2ba24db8a9376921b5e87b4762b9adb0f3f1deaea68f2b8b0bb2c11efb9c3e7"}, + {file = "tomli-2.5.0-py3-none-any.whl", hash = "sha256:32a7b79ac57a2e83670ce329ccf675798bc5a2094783a63676866b70503f2e2b"}, + {file = "tomli-2.5.0.tar.gz", hash = "sha256:264507556cd8b8c8e7c6ee037cdf443a463f03f4c958e57195e3d369711b8ff6"}, +] + + +[[package]] +name = "typing-extensions" +version = "4.16.0" +description = "Backported and Experimental Type Hints for Python 3.9+" +optional = false +python-versions = ">=3.9" +groups = ["main", "test"] +files = [ + {file = "typing_extensions-4.16.0-py3-none-any.whl", hash = "sha256:481caa481374e813c1b176ada14e97f1f67a4539ce9cfeb3f350d78d6370c2e8"}, + {file = "typing_extensions-4.16.0.tar.gz", hash = "sha256:dc983d19a509c94dba722ee6abd33940f7c05a89e243c47e907eb4db6f1a43e5"}, +] +markers = {main = "python_version < \"3.15\"", test = "python_version == \"3.10\""} + + +[[package]] +name = "tzdata" +version = "2026.6" +description = "Provider of IANA time zone data" +optional = true +python-versions = ">=2" +groups = ["main"] +markers = "extra == \"postgres\" and sys_platform == \"win32\"" +files = [ + {file = "tzdata-2026.6-py2.py3-none-any.whl", hash = "sha256:0a10eec6e13ef16b627fabed9a5f2ba61a62b1c67f327305f4e7e412a70b4aec"}, + {file = "tzdata-2026.6.tar.gz", hash = "sha256:85d2cd9c09f81f0bb29db27759fc83af4f1e620efb814f8c5bf8b4cc4feece6d"}, +] + + +[extras] +postgres = ["psycopg"] + +[metadata] +lock-version = "2.1" +python-versions = "^3.10" +content-hash = "86ce7479196c1b3e2fb94e9d811b6c0327bc6f3d5853d6af27403472c581bdcc" diff --git a/packages/extractors/python-dependencies/tests/fixtures/poetry/pyproject.toml b/packages/extractors/python-dependencies/tests/fixtures/poetry/pyproject.toml new file mode 100644 index 000000000..35f787c83 --- /dev/null +++ b/packages/extractors/python-dependencies/tests/fixtures/poetry/pyproject.toml @@ -0,0 +1,18 @@ +[tool.poetry] +name = "ledger" +version = "2.1.0" +description = "A synthetic Poetry project" +authors = ["Fixtures "] +package-mode = false + +[tool.poetry.dependencies] +python = "^3.10" +httpx = { version = ">=0.27", extras = ["socks"] } +click = "^8.1" +psycopg = { version = "^3.2", optional = true } + +[tool.poetry.extras] +postgres = ["psycopg"] + +[tool.poetry.group.test.dependencies] +pytest = "^8" diff --git a/packages/extractors/python-dependencies/tests/fixtures/requirements.expected.json b/packages/extractors/python-dependencies/tests/fixtures/requirements.expected.json new file mode 100644 index 000000000..4bc4cc5e4 --- /dev/null +++ b/packages/extractors/python-dependencies/tests/fixtures/requirements.expected.json @@ -0,0 +1,833 @@ +{ + "entities": [ + { + "confidence": "authoritative", + "data": { + "version": "0.0.6" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "id": "package:annotated-doc", + "kind": "package", + "label": "annotated-doc" + }, + { + "confidence": "authoritative", + "data": { + "version": "0.8.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "id": "package:annotated-types", + "kind": "package", + "label": "annotated-types" + }, + { + "confidence": "authoritative", + "data": { + "version": "4.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "id": "package:anyio", + "kind": "package", + "label": "anyio" + }, + { + "confidence": "authoritative", + "data": { + "version": "2026.11.20" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "id": "package:certifi", + "kind": "package", + "label": "certifi" + }, + { + "confidence": "authoritative", + "data": { + "version": "1.3.2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "id": "package:exceptiongroup", + "kind": "package", + "label": "exceptiongroup" + }, + { + "confidence": "authoritative", + "data": { + "version": "0.162.5" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "id": "package:fastapi", + "kind": "package", + "label": "fastapi" + }, + { + "confidence": "authoritative", + "data": { + "version": "0.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "id": "package:h11", + "kind": "package", + "label": "h11" + }, + { + "confidence": "authoritative", + "data": { + "version": "1.0.9" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "id": "package:httpcore", + "kind": "package", + "label": "httpcore" + }, + { + "confidence": "authoritative", + "data": { + "version": "0.29.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "id": "package:httpx", + "kind": "package", + "label": "httpx" + }, + { + "confidence": "authoritative", + "data": { + "version": "3.20" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "id": "package:idna", + "kind": "package", + "label": "idna" + }, + { + "confidence": "authoritative", + "data": { + "version": "1.45.2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "id": "package:opentelemetry-api", + "kind": "package", + "label": "opentelemetry-api" + }, + { + "confidence": "authoritative", + "data": { + "version": "2.14.4" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "id": "package:pydantic", + "kind": "package", + "label": "pydantic" + }, + { + "confidence": "authoritative", + "data": { + "version": "2.50.5" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "id": "package:pydantic-core", + "kind": "package", + "label": "pydantic-core" + }, + { + "confidence": "authoritative", + "data": { + "version": "8.3.3" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "id": "package:pytest", + "kind": "package", + "label": "pytest" + }, + { + "confidence": "authoritative", + "data": { + "version": "1.7.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "id": "package:starlette", + "kind": "package", + "label": "starlette" + }, + { + "confidence": "authoritative", + "data": { + "version": "4.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "id": "package:typing-extensions", + "kind": "package", + "label": "typing-extensions" + }, + { + "confidence": "authoritative", + "data": { + "version": "0.4.5" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "id": "package:typing-inspection", + "kind": "package", + "label": "typing-inspection" + }, + { + "confidence": "authoritative", + "data": { + "path": "." + }, + "id": "project-root", + "kind": "project", + "label": "(project root)" + } + ], + "metadata": { + "limitations": [ + "Requirements files record no dependency graph: each pinned requirement is a direct dependency of the project, unless `# via` annotations from pip-compile or uv pip compile say what pulls it in. Packages the files don't pin aren't in the graph.", + "Requirement lines that don't pin one version with `==` (ranges, URLs, editable installs) aren't in the graph; metadata.skipped lists them.", + "Environment markers are recorded on relationships as `marker` but not evaluated: the graph covers every platform and Python version at once." + ], + "lockfile": null, + "manager": "requirements", + "requirements": [ + "requirements.txt", + "requirements-dev.txt" + ], + "skipped": [ + [ + "requirements-dev.txt", + "ruff>=0.6" + ], + [ + "requirements-dev.txt", + "-e ." + ] + ], + "unresolved": [] + }, + "protocolVersion": 0, + "relationships": [ + { + "confidence": "authoritative", + "data": { + "file": "requirements-dev.txt", + "resolved": "8.3.3", + "type": "dependencies", + "version": "==8.3.3" + }, + "evidence": [ + { + "kind": "requirements", + "location": { + "line": 3 + }, + "source": "requirements-dev.txt" + } + ], + "from": "project-root", + "id": "dependency:[\".\",\"dependencies\",\"requirements-dev.txt\",\"pytest\"]", + "kind": "dependencies", + "label": "==8.3.3", + "to": "package:pytest" + }, + { + "confidence": "authoritative", + "data": { + "file": "requirements.txt", + "resolved": "0.162.5", + "type": "dependencies", + "version": "==0.162.5" + }, + "evidence": [ + { + "kind": "requirements", + "location": { + "line": 18 + }, + "source": "requirements.txt" + } + ], + "from": "project-root", + "id": "dependency:[\".\",\"dependencies\",\"requirements.txt\",\"fastapi\"]", + "kind": "dependencies", + "label": "==0.162.5", + "to": "package:fastapi" + }, + { + "confidence": "authoritative", + "data": { + "file": "requirements.txt", + "resolved": "0.29.0", + "type": "dependencies", + "version": "==0.29.0" + }, + "evidence": [ + { + "kind": "requirements", + "location": { + "line": 24 + }, + "source": "requirements.txt" + } + ], + "from": "project-root", + "id": "dependency:[\".\",\"dependencies\",\"requirements.txt\",\"httpx\"]", + "kind": "dependencies", + "label": "==0.29.0", + "to": "package:httpx" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==1.3.2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "from": "package:anyio", + "id": "dependency:[\"package:anyio\",\"dependencies\",\"exceptiongroup\"]", + "kind": "dependencies", + "label": "==1.3.2", + "to": "package:exceptiongroup" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==3.20" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "from": "package:anyio", + "id": "dependency:[\"package:anyio\",\"dependencies\",\"idna\"]", + "kind": "dependencies", + "label": "==3.20", + "to": "package:idna" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==4.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "from": "package:anyio", + "id": "dependency:[\"package:anyio\",\"dependencies\",\"typing-extensions\"]", + "kind": "dependencies", + "label": "==4.16.0", + "to": "package:typing-extensions" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==4.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "from": "package:exceptiongroup", + "id": "dependency:[\"package:exceptiongroup\",\"dependencies\",\"typing-extensions\"]", + "kind": "dependencies", + "label": "==4.16.0", + "to": "package:typing-extensions" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==0.0.6" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "from": "package:fastapi", + "id": "dependency:[\"package:fastapi\",\"dependencies\",\"annotated-doc\"]", + "kind": "dependencies", + "label": "==0.0.6", + "to": "package:annotated-doc" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==4.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "from": "package:fastapi", + "id": "dependency:[\"package:fastapi\",\"dependencies\",\"anyio\"]", + "kind": "dependencies", + "label": "==4.16.0", + "to": "package:anyio" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==1.45.2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "from": "package:fastapi", + "id": "dependency:[\"package:fastapi\",\"dependencies\",\"opentelemetry-api\"]", + "kind": "dependencies", + "label": "==1.45.2", + "to": "package:opentelemetry-api" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==2.14.4" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "from": "package:fastapi", + "id": "dependency:[\"package:fastapi\",\"dependencies\",\"pydantic\"]", + "kind": "dependencies", + "label": "==2.14.4", + "to": "package:pydantic" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==1.7.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "from": "package:fastapi", + "id": "dependency:[\"package:fastapi\",\"dependencies\",\"starlette\"]", + "kind": "dependencies", + "label": "==1.7.0", + "to": "package:starlette" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==4.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "from": "package:fastapi", + "id": "dependency:[\"package:fastapi\",\"dependencies\",\"typing-extensions\"]", + "kind": "dependencies", + "label": "==4.16.0", + "to": "package:typing-extensions" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==0.4.5" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "from": "package:fastapi", + "id": "dependency:[\"package:fastapi\",\"dependencies\",\"typing-inspection\"]", + "kind": "dependencies", + "label": "==0.4.5", + "to": "package:typing-inspection" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==2026.11.20" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "from": "package:httpcore", + "id": "dependency:[\"package:httpcore\",\"dependencies\",\"certifi\"]", + "kind": "dependencies", + "label": "==2026.11.20", + "to": "package:certifi" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==0.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "from": "package:httpcore", + "id": "dependency:[\"package:httpcore\",\"dependencies\",\"h11\"]", + "kind": "dependencies", + "label": "==0.16.0", + "to": "package:h11" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==4.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"dependencies\",\"anyio\"]", + "kind": "dependencies", + "label": "==4.16.0", + "to": "package:anyio" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==2026.11.20" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"dependencies\",\"certifi\"]", + "kind": "dependencies", + "label": "==2026.11.20", + "to": "package:certifi" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==1.0.9" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"dependencies\",\"httpcore\"]", + "kind": "dependencies", + "label": "==1.0.9", + "to": "package:httpcore" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==3.20" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"dependencies\",\"idna\"]", + "kind": "dependencies", + "label": "==3.20", + "to": "package:idna" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==4.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "from": "package:opentelemetry-api", + "id": "dependency:[\"package:opentelemetry-api\",\"dependencies\",\"typing-extensions\"]", + "kind": "dependencies", + "label": "==4.16.0", + "to": "package:typing-extensions" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==0.8.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "from": "package:pydantic", + "id": "dependency:[\"package:pydantic\",\"dependencies\",\"annotated-types\"]", + "kind": "dependencies", + "label": "==0.8.0", + "to": "package:annotated-types" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==2.50.5" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "from": "package:pydantic", + "id": "dependency:[\"package:pydantic\",\"dependencies\",\"pydantic-core\"]", + "kind": "dependencies", + "label": "==2.50.5", + "to": "package:pydantic-core" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==4.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "from": "package:pydantic", + "id": "dependency:[\"package:pydantic\",\"dependencies\",\"typing-extensions\"]", + "kind": "dependencies", + "label": "==4.16.0", + "to": "package:typing-extensions" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==0.4.5" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "from": "package:pydantic", + "id": "dependency:[\"package:pydantic\",\"dependencies\",\"typing-inspection\"]", + "kind": "dependencies", + "label": "==0.4.5", + "to": "package:typing-inspection" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==4.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "from": "package:pydantic-core", + "id": "dependency:[\"package:pydantic-core\",\"dependencies\",\"typing-extensions\"]", + "kind": "dependencies", + "label": "==4.16.0", + "to": "package:typing-extensions" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==4.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "from": "package:starlette", + "id": "dependency:[\"package:starlette\",\"dependencies\",\"anyio\"]", + "kind": "dependencies", + "label": "==4.16.0", + "to": "package:anyio" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==4.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "from": "package:starlette", + "id": "dependency:[\"package:starlette\",\"dependencies\",\"typing-extensions\"]", + "kind": "dependencies", + "label": "==4.16.0", + "to": "package:typing-extensions" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies", + "version": "==4.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "requirements.txt" + } + ], + "from": "package:typing-inspection", + "id": "dependency:[\"package:typing-inspection\",\"dependencies\",\"typing-extensions\"]", + "kind": "dependencies", + "label": "==4.16.0", + "to": "package:typing-extensions" + } + ], + "schema": "graph/v0" +} diff --git a/packages/extractors/python-dependencies/tests/fixtures/requirements/requirements-dev.txt b/packages/extractors/python-dependencies/tests/fixtures/requirements/requirements-dev.txt new file mode 100644 index 000000000..b518813a7 --- /dev/null +++ b/packages/extractors/python-dependencies/tests/fixtures/requirements/requirements-dev.txt @@ -0,0 +1,5 @@ +# Development tools, pinned by hand. +-r requirements.txt +pytest==8.3.3 +ruff>=0.6 +-e . diff --git a/packages/extractors/python-dependencies/tests/fixtures/requirements/requirements.in b/packages/extractors/python-dependencies/tests/fixtures/requirements/requirements.in new file mode 100644 index 000000000..ac0b39d27 --- /dev/null +++ b/packages/extractors/python-dependencies/tests/fixtures/requirements/requirements.in @@ -0,0 +1,2 @@ +fastapi>=0.110 +httpx diff --git a/packages/extractors/python-dependencies/tests/fixtures/requirements/requirements.txt b/packages/extractors/python-dependencies/tests/fixtures/requirements/requirements.txt new file mode 100644 index 000000000..2b03dcbb8 --- /dev/null +++ b/packages/extractors/python-dependencies/tests/fixtures/requirements/requirements.txt @@ -0,0 +1,51 @@ +# This file was autogenerated by uv via the following command: +# uv pip compile requirements.in -o requirements.txt +annotated-doc==0.0.6 + # via fastapi +annotated-types==0.8.0 + # via pydantic +anyio==4.16.0 + # via + # fastapi + # httpx + # starlette +certifi==2026.11.20 + # via + # httpcore + # httpx +exceptiongroup==1.3.2 + # via anyio +fastapi==0.162.5 + # via -r requirements.in +h11==0.16.0 + # via httpcore +httpcore==1.0.9 + # via httpx +httpx==0.29.0 + # via -r requirements.in +idna==3.20 + # via + # anyio + # httpx +opentelemetry-api==1.45.2 + # via fastapi +pydantic==2.14.4 + # via fastapi +pydantic-core==2.50.5 + # via pydantic +starlette==1.7.0 + # via fastapi +typing-extensions==4.16.0 + # via + # anyio + # exceptiongroup + # fastapi + # opentelemetry-api + # pydantic + # pydantic-core + # starlette + # typing-inspection +typing-inspection==0.4.5 + # via + # fastapi + # pydantic diff --git a/packages/extractors/python-dependencies/tests/fixtures/uv-workspace.expected.json b/packages/extractors/python-dependencies/tests/fixtures/uv-workspace.expected.json new file mode 100644 index 000000000..45dc73a0e --- /dev/null +++ b/packages/extractors/python-dependencies/tests/fixtures/uv-workspace.expected.json @@ -0,0 +1,1018 @@ +{ + "entities": [ + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "4.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:anyio", + "kind": "package", + "label": "anyio" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "26.1.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:attrs", + "kind": "package", + "label": "attrs" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "2026.11.20" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:certifi", + "kind": "package", + "label": "certifi" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "8.5.1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:click", + "kind": "package", + "label": "click" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "0.4.6" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:colorama", + "kind": "package", + "label": "colorama" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "1.3.2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:exceptiongroup", + "kind": "package", + "label": "exceptiongroup" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "0.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:h11", + "kind": "package", + "label": "h11" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "4.4.1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:h2", + "kind": "package", + "label": "h2" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "4.2.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:hpack", + "kind": "package", + "label": "hpack" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "1.0.9" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:httpcore", + "kind": "package", + "label": "httpcore" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "0.29.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:httpx", + "kind": "package", + "label": "httpx" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "6.1.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:hyperframe", + "kind": "package", + "label": "hyperframe" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "3.20" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:idna", + "kind": "package", + "label": "idna" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "2.3.1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:iniconfig", + "kind": "package", + "label": "iniconfig" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "4.3.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:markdown-it-py", + "kind": "package", + "label": "markdown-it-py" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "0.1.2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:mdurl", + "kind": "package", + "label": "mdurl" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "26.4" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:packaging", + "kind": "package", + "label": "packaging" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "1.7.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:pluggy", + "kind": "package", + "label": "pluggy" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "2.21.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:pygments", + "kind": "package", + "label": "pygments" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "9.2.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:pytest", + "kind": "package", + "label": "pytest" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "15.0.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:rich", + "kind": "package", + "label": "rich" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "0.17.6" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:ruff", + "kind": "package", + "label": "ruff" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "2.5.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:tomli", + "kind": "package", + "label": "tomli" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "4.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:typing-extensions", + "kind": "package", + "label": "typing-extensions" + }, + { + "confidence": "authoritative", + "data": { + "path": ".", + "version": "1.4.0" + }, + "evidence": [ + { + "kind": "manifest", + "source": "pyproject.toml" + } + ], + "id": "project:harbor", + "kind": "project", + "label": "harbor" + }, + { + "confidence": "authoritative", + "data": { + "path": "packages/api", + "version": "0.3.0" + }, + "evidence": [ + { + "kind": "manifest", + "source": "packages/api/pyproject.toml" + } + ], + "id": "project:harbor-api", + "kind": "project", + "label": "harbor-api" + }, + { + "confidence": "authoritative", + "data": { + "path": "packages/core", + "version": "0.3.0" + }, + "evidence": [ + { + "kind": "manifest", + "source": "packages/core/pyproject.toml" + } + ], + "id": "project:harbor-core", + "kind": "project", + "label": "Harbor_Core" + } + ], + "metadata": { + "limitations": [ + "Every extra and dependency group a project declares is included; a package's extras are followed only where a dependency in the graph requests them.", + "Environment markers are recorded on relationships as `marker` but not evaluated: the graph covers every platform and Python version at once." + ], + "lockfile": "uv.lock", + "lockfileVersion": 1, + "manager": "uv", + "unresolved": [] + }, + "protocolVersion": 0, + "relationships": [ + { + "confidence": "authoritative", + "data": { + "resolved": "8.5.1", + "type": "dependencies", + "version": ">=8.1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor", + "id": "dependency:[\"harbor\",\"dependencies\",\"click\"]", + "kind": "dependencies", + "label": ">=8.1", + "to": "package:click" + }, + { + "confidence": "authoritative", + "data": { + "resolved": "0.3.0", + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor", + "id": "dependency:[\"harbor\",\"dependencies\",\"harbor-api\"]", + "kind": "dependencies", + "to": "project:harbor-api" + }, + { + "confidence": "authoritative", + "data": { + "marker": "python_full_version < '3.11'", + "resolved": "2.5.0", + "type": "dependencies", + "version": ">=2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor", + "id": "dependency:[\"harbor\",\"dependencies\",\"tomli\"]", + "kind": "dependencies", + "label": ">=2", + "to": "package:tomli" + }, + { + "confidence": "authoritative", + "data": { + "group": "dev", + "resolved": "9.2.0", + "type": "devDependencies", + "version": ">=8" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor", + "id": "dependency:[\"harbor\",\"devDependencies\",\"dev\",\"pytest\"]", + "kind": "devDependencies", + "label": ">=8", + "to": "package:pytest" + }, + { + "confidence": "authoritative", + "data": { + "group": "dev", + "resolved": "0.17.6", + "type": "devDependencies", + "version": ">=0.6" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor", + "id": "dependency:[\"harbor\",\"devDependencies\",\"dev\",\"ruff\"]", + "kind": "devDependencies", + "label": ">=0.6", + "to": "package:ruff" + }, + { + "confidence": "authoritative", + "data": { + "group": "test", + "resolved": "9.2.0", + "type": "devDependencies", + "version": ">=8" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor", + "id": "dependency:[\"harbor\",\"devDependencies\",\"test\",\"pytest\"]", + "kind": "devDependencies", + "label": ">=8", + "to": "package:pytest" + }, + { + "confidence": "authoritative", + "data": { + "resolved": "0.3.0", + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor-api", + "id": "dependency:[\"harbor-api\",\"dependencies\",\"harbor-core\"]", + "kind": "dependencies", + "to": "project:harbor-core" + }, + { + "confidence": "authoritative", + "data": { + "extras": [ + "http2" + ], + "resolved": "0.29.0", + "type": "dependencies", + "version": ">=0.27,<1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor-api", + "id": "dependency:[\"harbor-api\",\"dependencies\",\"httpx\"]", + "kind": "dependencies", + "label": ">=0.27,<1", + "to": "package:httpx" + }, + { + "confidence": "authoritative", + "data": { + "extra": "cli", + "resolved": "15.0.0", + "type": "optionalDependencies", + "version": ">=13" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor-api", + "id": "dependency:[\"harbor-api\",\"optionalDependencies\",\"cli\",\"rich\"]", + "kind": "optionalDependencies", + "label": ">=13", + "to": "package:rich" + }, + { + "confidence": "authoritative", + "data": { + "resolved": "26.1.0", + "type": "dependencies", + "version": ">=24" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor-core", + "id": "dependency:[\"harbor-core\",\"dependencies\",\"attrs\"]", + "kind": "dependencies", + "label": ">=24", + "to": "package:attrs" + }, + { + "confidence": "authoritative", + "data": { + "marker": "python_full_version < '3.11'", + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:anyio", + "id": "dependency:[\"package:anyio\",\"dependencies\",\"exceptiongroup\"]", + "kind": "dependencies", + "to": "package:exceptiongroup" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:anyio", + "id": "dependency:[\"package:anyio\",\"dependencies\",\"idna\"]", + "kind": "dependencies", + "to": "package:idna" + }, + { + "confidence": "authoritative", + "data": { + "marker": "python_full_version < '3.15'", + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:anyio", + "id": "dependency:[\"package:anyio\",\"dependencies\",\"typing-extensions\"]", + "kind": "dependencies", + "to": "package:typing-extensions" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:exceptiongroup", + "id": "dependency:[\"package:exceptiongroup\",\"dependencies\",\"typing-extensions\"]", + "kind": "dependencies", + "to": "package:typing-extensions" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:h2", + "id": "dependency:[\"package:h2\",\"dependencies\",\"hpack\"]", + "kind": "dependencies", + "to": "package:hpack" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:h2", + "id": "dependency:[\"package:h2\",\"dependencies\",\"hyperframe\"]", + "kind": "dependencies", + "to": "package:hyperframe" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:httpcore", + "id": "dependency:[\"package:httpcore\",\"dependencies\",\"certifi\"]", + "kind": "dependencies", + "to": "package:certifi" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:httpcore", + "id": "dependency:[\"package:httpcore\",\"dependencies\",\"h11\"]", + "kind": "dependencies", + "to": "package:h11" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"dependencies\",\"anyio\"]", + "kind": "dependencies", + "to": "package:anyio" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"dependencies\",\"certifi\"]", + "kind": "dependencies", + "to": "package:certifi" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"dependencies\",\"httpcore\"]", + "kind": "dependencies", + "to": "package:httpcore" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"dependencies\",\"idna\"]", + "kind": "dependencies", + "to": "package:idna" + }, + { + "confidence": "authoritative", + "data": { + "extra": "http2", + "type": "optionalDependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"optionalDependencies\",\"http2\",\"h2\"]", + "kind": "optionalDependencies", + "to": "package:h2" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:markdown-it-py", + "id": "dependency:[\"package:markdown-it-py\",\"dependencies\",\"mdurl\"]", + "kind": "dependencies", + "to": "package:mdurl" + }, + { + "confidence": "authoritative", + "data": { + "marker": "sys_platform == 'win32'", + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"colorama\"]", + "kind": "dependencies", + "to": "package:colorama" + }, + { + "confidence": "authoritative", + "data": { + "marker": "python_full_version < '3.11'", + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"exceptiongroup\"]", + "kind": "dependencies", + "to": "package:exceptiongroup" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"iniconfig\"]", + "kind": "dependencies", + "to": "package:iniconfig" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"packaging\"]", + "kind": "dependencies", + "to": "package:packaging" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"pluggy\"]", + "kind": "dependencies", + "to": "package:pluggy" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"pygments\"]", + "kind": "dependencies", + "to": "package:pygments" + }, + { + "confidence": "authoritative", + "data": { + "marker": "python_full_version < '3.11'", + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"tomli\"]", + "kind": "dependencies", + "to": "package:tomli" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:rich", + "id": "dependency:[\"package:rich\",\"dependencies\",\"markdown-it-py\"]", + "kind": "dependencies", + "to": "package:markdown-it-py" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:rich", + "id": "dependency:[\"package:rich\",\"dependencies\",\"pygments\"]", + "kind": "dependencies", + "to": "package:pygments" + } + ], + "schema": "graph/v0" +} diff --git a/packages/extractors/python-dependencies/tests/fixtures/uv-workspace/packages/api/pyproject.toml b/packages/extractors/python-dependencies/tests/fixtures/uv-workspace/packages/api/pyproject.toml new file mode 100644 index 000000000..7a9c3509b --- /dev/null +++ b/packages/extractors/python-dependencies/tests/fixtures/uv-workspace/packages/api/pyproject.toml @@ -0,0 +1,18 @@ +[project] +name = "harbor-api" +version = "0.3.0" +requires-python = ">=3.10" +dependencies = [ + "harbor-core", + "httpx[http2]>=0.27,<1", +] + +[project.optional-dependencies] +cli = ["rich>=13"] + +[tool.uv.sources] +harbor-core = { workspace = true } + +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" diff --git a/packages/extractors/python-dependencies/tests/fixtures/uv-workspace/packages/api/src/harbor_api/__init__.py b/packages/extractors/python-dependencies/tests/fixtures/uv-workspace/packages/api/src/harbor_api/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/packages/extractors/python-dependencies/tests/fixtures/uv-workspace/packages/core/pyproject.toml b/packages/extractors/python-dependencies/tests/fixtures/uv-workspace/packages/core/pyproject.toml new file mode 100644 index 000000000..adce6a1e2 --- /dev/null +++ b/packages/extractors/python-dependencies/tests/fixtures/uv-workspace/packages/core/pyproject.toml @@ -0,0 +1,9 @@ +[project] +name = "Harbor_Core" +version = "0.3.0" +requires-python = ">=3.10" +dependencies = ["attrs>=24"] + +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" diff --git a/packages/extractors/python-dependencies/tests/fixtures/uv-workspace/packages/core/src/harbor_core/__init__.py b/packages/extractors/python-dependencies/tests/fixtures/uv-workspace/packages/core/src/harbor_core/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/packages/extractors/python-dependencies/tests/fixtures/uv-workspace/packages/legacy/pyproject.toml b/packages/extractors/python-dependencies/tests/fixtures/uv-workspace/packages/legacy/pyproject.toml new file mode 100644 index 000000000..a3630bf1c --- /dev/null +++ b/packages/extractors/python-dependencies/tests/fixtures/uv-workspace/packages/legacy/pyproject.toml @@ -0,0 +1,4 @@ +[project] +name = "harbor-legacy" +version = "0.1.0" +dependencies = ["requests"] diff --git a/packages/extractors/python-dependencies/tests/fixtures/uv-workspace/pyproject.toml b/packages/extractors/python-dependencies/tests/fixtures/uv-workspace/pyproject.toml new file mode 100644 index 000000000..7e20dcb57 --- /dev/null +++ b/packages/extractors/python-dependencies/tests/fixtures/uv-workspace/pyproject.toml @@ -0,0 +1,20 @@ +[project] +name = "harbor" +version = "1.4.0" +requires-python = ">=3.10" +dependencies = [ + "harbor-api", + "click>=8.1", + "tomli>=2; python_version < '3.11'", +] + +[dependency-groups] +test = ["pytest>=8"] +dev = [{ include-group = "test" }, "ruff>=0.6"] + +[tool.uv.workspace] +members = ["packages/*"] +exclude = ["packages/legacy"] + +[tool.uv.sources] +harbor-api = { workspace = true } diff --git a/packages/extractors/python-dependencies/tests/fixtures/uv-workspace/uv.lock b/packages/extractors/python-dependencies/tests/fixtures/uv-workspace/uv.lock new file mode 100644 index 000000000..88447153b --- /dev/null +++ b/packages/extractors/python-dependencies/tests/fixtures/uv-workspace/uv.lock @@ -0,0 +1,239 @@ +version = 1 +revision = 5 +requires-python = ">=3.10" + +[manifest] +members = [ + "harbor", + "harbor-api", + "harbor-core", +] + +[[package]] +name = "anyio" +version = "4.16.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "exceptiongroup", marker = "python_full_version < '3.11'" }, + { name = "idna" }, + { name = "typing-extensions", marker = "python_full_version < '3.15'" }, +] + +[[package]] +name = "attrs" +version = "26.1.0" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "certifi" +version = "2026.11.20" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "click" +version = "8.5.1" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "colorama" +version = "0.4.6" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "exceptiongroup" +version = "1.3.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions" }, +] + +[[package]] +name = "h11" +version = "0.16.0" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "h2" +version = "4.4.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "hpack" }, + { name = "hyperframe" }, +] + +[[package]] +name = "harbor" +version = "1.4.0" +source = { virtual = "." } +dependencies = [ + { name = "click" }, + { name = "harbor-api" }, + { name = "tomli", marker = "python_full_version < '3.11'" }, +] + +[package.dev-dependencies] +dev = [ + { name = "pytest" }, + { name = "ruff" }, +] +test = [ + { name = "pytest" }, +] + +[package.metadata] +requires-dist = [ + { name = "click", specifier = ">=8.1" }, + { name = "harbor-api", editable = "packages/api" }, + { name = "tomli", marker = "python_full_version < '3.11'", specifier = ">=2" }, +] + +[package.metadata.requires-dev] +dev = [ + { name = "pytest", specifier = ">=8" }, + { name = "ruff", specifier = ">=0.6" }, +] +test = [{ name = "pytest", specifier = ">=8" }] + +[[package]] +name = "harbor-api" +version = "0.3.0" +source = { editable = "packages/api" } +dependencies = [ + { name = "harbor-core" }, + { name = "httpx", extra = ["http2"] }, +] + +[package.optional-dependencies] +cli = [ + { name = "rich" }, +] + +[package.metadata] +requires-dist = [ + { name = "harbor-core", editable = "packages/core" }, + { name = "httpx", extras = ["http2"], specifier = ">=0.27,<1" }, + { name = "rich", marker = "extra == 'cli'", specifier = ">=13" }, +] +provides-extras = ["cli"] + +[[package]] +name = "harbor-core" +version = "0.3.0" +source = { editable = "packages/core" } +dependencies = [ + { name = "attrs" }, +] + +[package.metadata] +requires-dist = [{ name = "attrs", specifier = ">=24" }] + +[[package]] +name = "hpack" +version = "4.2.0" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "httpcore" +version = "1.0.9" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "certifi" }, + { name = "h11" }, +] + +[[package]] +name = "httpx" +version = "0.29.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "anyio" }, + { name = "certifi" }, + { name = "httpcore" }, + { name = "idna" }, +] + +[package.optional-dependencies] +http2 = [ + { name = "h2" }, +] + +[[package]] +name = "hyperframe" +version = "6.1.0" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "idna" +version = "3.20" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "iniconfig" +version = "2.3.1" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "markdown-it-py" +version = "4.3.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "mdurl" }, +] + +[[package]] +name = "mdurl" +version = "0.1.2" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "packaging" +version = "26.4" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "pluggy" +version = "1.7.0" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "pygments" +version = "2.21.0" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "pytest" +version = "9.2.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "colorama", marker = "sys_platform == 'win32'" }, + { name = "exceptiongroup", marker = "python_full_version < '3.11'" }, + { name = "iniconfig" }, + { name = "packaging" }, + { name = "pluggy" }, + { name = "pygments" }, + { name = "tomli", marker = "python_full_version < '3.11'" }, +] + +[[package]] +name = "rich" +version = "15.0.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "markdown-it-py" }, + { name = "pygments" }, +] + +[[package]] +name = "ruff" +version = "0.17.6" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "tomli" +version = "2.5.0" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "typing-extensions" +version = "4.16.0" +source = { registry = "https://pypi.org/simple" } diff --git a/packages/extractors/python-dependencies/tests/lockfiles.rs b/packages/extractors/python-dependencies/tests/lockfiles.rs new file mode 100644 index 000000000..bf5ce4209 --- /dev/null +++ b/packages/extractors/python-dependencies/tests/lockfiles.rs @@ -0,0 +1,333 @@ +//! Each fixture's lockfile was written by the package manager itself +//! (`tests/fixtures/lock.mjs`); regenerate the golden extractions with +//! `PROJECTIONS_UPDATE_GOLDEN=1 cargo test -p projections-extractor-python-dependencies`. + +use projections_extractor_python_dependencies::collect; +use projections_extractor_sdk::repository_files; +use projections_extractor_sdk::testing::{self, golden}; +use serde_json::{Value, json}; +use std::fs; +use std::path::{Path, PathBuf}; + +fn fixture(name: &str) -> PathBuf { + Path::new(env!("CARGO_MANIFEST_DIR")) + .join("tests/fixtures") + .join(name) + .canonicalize() + .unwrap() +} + +fn extract(root: &Path, inputs: Value) -> anyhow::Result { + let files = repository_files(root).unwrap(); + let definition = json!({"id":"python","extractor":"python-dependencies","inputs":inputs}); + collect(&testing::context(root, definition).with_files(files)) +} + +fn manager(name: &str) -> Value { + let root = fixture(name); + let extraction = extract(&root, json!({})).unwrap(); + golden(&root.parent().unwrap().join(format!("{name}.expected.json")), &extraction); + extraction +} + +fn entity<'a>(extraction: &'a Value, id: &str) -> &'a Value { + extraction["entities"] + .as_array() + .unwrap() + .iter() + .find(|e| e["id"] == id) + .unwrap_or_else(|| panic!("missing {id}")) +} + +fn has_entity(extraction: &Value, id: &str) -> bool { + extraction["entities"].as_array().unwrap().iter().any(|e| e["id"] == id) +} + +/// The relationship from `from` to `to`, of `kind`. +fn edge<'a>(extraction: &'a Value, from: &str, kind: &str, to: &str) -> &'a Value { + extraction["relationships"] + .as_array() + .unwrap() + .iter() + .find(|e| e["from"] == from && e["kind"] == kind && e["to"] == to) + .unwrap_or_else(|| panic!("missing {from} {kind} {to}")) +} + +/// A scratch directory holding `files`. +fn scratch(name: &str, files: &[(&str, &str)]) -> PathBuf { + let root = Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../../target/python-dependencies-tests") + .join(format!("{name}-{}", std::process::id())); + let _ = fs::remove_dir_all(&root); + for (file, text) in files { + let path = root.join(file); + fs::create_dir_all(path.parent().unwrap()).unwrap(); + fs::write(path, text).unwrap(); + } + root.canonicalize().unwrap() +} + +#[test] +fn a_uv_workspace_is_its_members_and_what_uv_locked_for_them() { + let extraction = manager("uv-workspace"); + assert_eq!(extraction["metadata"]["manager"], "uv"); + assert_eq!(extraction["metadata"]["lockfile"], "uv.lock"); + assert_eq!(extraction["metadata"]["unresolved"], json!([])); + // The root and the members `packages/*` selects; `exclude` leaves the legacy package out. + for (id, label, path) in [ + ("project:harbor", "harbor", "."), + ("project:harbor-api", "harbor-api", "packages/api"), + ("project:harbor-core", "Harbor_Core", "packages/core"), + ] { + let project = entity(&extraction, id); + assert_eq!( + (project["kind"].as_str(), project["label"].as_str()), + (Some("project"), Some(label)) + ); + assert_eq!(project["data"]["path"], path); + } + assert!(!has_entity(&extraction, "project:harbor-legacy")); + // Members depend on each other as projects, labelled with the declared specifier. + let api = edge(&extraction, "project:harbor", "dependencies", "project:harbor-api"); + assert_eq!(api["data"]["resolved"], "0.3.0"); + let httpx = edge(&extraction, "project:harbor-api", "dependencies", "package:httpx"); + assert_eq!(httpx["label"], ">=0.27,<1"); + assert_eq!(httpx["data"]["extras"], json!(["http2"])); + // The extra httpx is asked for is followed: h2 is in the graph through it. + let h2 = edge(&extraction, "package:httpx", "optionalDependencies", "package:h2"); + assert_eq!(h2["data"]["extra"], "http2"); + assert_eq!(h2["id"], r#"dependency:["package:httpx","optionalDependencies","http2","h2"]"#); + // A member's extra and the root's dependency groups (one including the other) are declarations. + assert_eq!( + edge(&extraction, "project:harbor-api", "optionalDependencies", "package:rich")["data"]["extra"], + "cli" + ); + for group in ["dev", "test"] { + let pytest = extraction["relationships"] + .as_array() + .unwrap() + .iter() + .find(|e| e["from"] == "project:harbor" && e["to"] == "package:pytest" && e["data"]["group"] == group); + assert!(pytest.is_some(), "pytest in {group}"); + } + // Markers are recorded, not evaluated. + assert_eq!( + edge(&extraction, "project:harbor", "dependencies", "package:tomli")["data"]["marker"], + "python_full_version < '3.11'" + ); + // Versions are data, never identity. + assert!(entity(&extraction, "package:httpx")["data"]["version"].is_string()); +} + +#[test] +fn a_poetry_project_is_read_from_its_manifest_and_poetry_lock() { + let extraction = manager("poetry"); + assert_eq!(extraction["metadata"]["manager"], "poetry"); + assert_eq!(entity(&extraction, "project:ledger")["data"]["version"], "2.1.0"); + // Poetry's python constraint is no package. + assert!(!has_entity(&extraction, "package:python")); + let httpx = edge(&extraction, "project:ledger", "dependencies", "package:httpx"); + assert_eq!( + (httpx["label"].as_str(), &httpx["data"]["extras"]), + (Some(">=0.27"), &json!(["socks"])) + ); + // httpx's optional socksio is installed for the socks extra the project asks for, and only it. + assert_eq!( + edge(&extraction, "package:httpx", "optionalDependencies", "package:socksio")["data"]["extra"], + "socks" + ); + assert_eq!( + edge(&extraction, "project:ledger", "optionalDependencies", "package:psycopg")["data"]["extra"], + "postgres" + ); + assert_eq!( + edge(&extraction, "project:ledger", "devDependencies", "package:pytest")["data"]["group"], + "test" + ); + assert!(edge(&extraction, "package:pytest", "dependencies", "package:pluggy")["label"].is_string()); +} + +#[test] +fn a_pdm_project_folds_each_locked_extra_into_its_package() { + let extraction = manager("pdm"); + assert_eq!(extraction["metadata"]["manager"], "pdm"); + assert_eq!( + edge(&extraction, "package:httpx", "optionalDependencies", "package:h2")["data"]["extra"], + "http2" + ); + // The extra's own entry depends on httpx itself, which is no dependency. + assert!( + !extraction["relationships"] + .as_array() + .unwrap() + .iter() + .any(|e| e["from"] == "package:httpx" && e["to"] == "package:httpx") + ); + edge(&extraction, "project:beacon", "optionalDependencies", "package:rich"); + edge(&extraction, "project:beacon", "devDependencies", "package:pytest"); +} + +#[test] +fn requirements_files_pin_direct_dependencies_and_via_annotations_add_the_graph() { + let extraction = manager("requirements"); + let metadata = &extraction["metadata"]; + assert_eq!(metadata["manager"], "requirements"); + assert_eq!(metadata["lockfile"], Value::Null); + assert_eq!(metadata["requirements"], json!(["requirements.txt", "requirements-dev.txt"])); + assert_eq!( + metadata["skipped"], + json!([["requirements-dev.txt", "ruff>=0.6"], ["requirements-dev.txt", "-e ."]]) + ); + assert_eq!(entity(&extraction, "project-root")["label"], "(project root)"); + // `# via -r requirements.in` pins are direct; what they pull in is transitive. + let fastapi = edge(&extraction, "project-root", "dependencies", "package:fastapi"); + assert_eq!(fastapi["data"]["file"], "requirements.txt"); + assert!(fastapi["label"].as_str().unwrap().starts_with("==")); + edge(&extraction, "package:fastapi", "dependencies", "package:starlette"); + assert!( + !extraction["relationships"] + .as_array() + .unwrap() + .iter() + .any(|e| e["from"] == "project-root" && e["to"] == "package:starlette") + ); + // A hand-written file without annotations is direct throughout. + assert_eq!( + edge(&extraction, "project-root", "dependencies", "package:pytest")["data"]["file"], + "requirements-dev.txt" + ); +} + +#[test] +fn a_revision_without_a_python_project_has_no_packages() { + let root = scratch("empty", &[("README.md", "nothing here\n")]); + let extraction = extract(&root, json!({})).unwrap(); + assert_eq!(extraction["entities"], json!([])); + let _ = fs::remove_dir_all(&root); +} + +#[test] +fn without_a_lockfile_declarations_keep_their_ranges() { + let root = scratch( + "unlocked", + &[( + "app/pyproject.toml", + "[project]\nname = \"app\"\ndependencies = [\"httpx>=0.27\"]\n", + )], + ); + let extraction = extract(&root, json!({"root": "app"})).unwrap(); + let httpx = edge(&extraction, "project:app", "dependencies", "package:httpx"); + assert_eq!(httpx["label"], ">=0.27"); + assert_eq!(httpx["data"].get("resolved"), None); + assert_eq!(extraction["metadata"]["manager"], Value::Null); + assert!( + extraction["metadata"]["limitations"][0] + .as_str() + .unwrap() + .starts_with("No lockfile") + ); + assert_eq!(entity(&extraction, "project:app")["evidence"][0]["source"], "app/pyproject.toml"); + let _ = fs::remove_dir_all(&root); +} + +#[test] +fn several_lockfiles_need_the_manager_named_unless_the_manifest_configures_one() { + let uv = fs::read_to_string(fixture("uv-workspace").join("uv.lock")).unwrap(); + let poetry = fs::read_to_string(fixture("poetry").join("poetry.lock")).unwrap(); + let manifest = "[project]\nname = \"app\"\ndependencies = [\"click\"]\n"; + let root = scratch( + "several", + &[("pyproject.toml", manifest), ("uv.lock", &uv), ("poetry.lock", &poetry)], + ); + let error = format!("{:#}", extract(&root, json!({})).unwrap_err()); + assert!(error.contains("Several lockfiles (uv.lock, poetry.lock)"), "{error}"); + let chosen = extract(&root, json!({"manager": "poetry"})).unwrap(); + assert_eq!(chosen["metadata"]["lockfile"], "poetry.lock"); + fs::write(root.join("pyproject.toml"), format!("{manifest}[tool.uv]\npackage = false\n")).unwrap(); + assert_eq!(extract(&root, json!({})).unwrap()["metadata"]["manager"], "uv"); + let _ = fs::remove_dir_all(&root); +} + +#[test] +fn a_dependency_no_lockfile_entry_resolves_is_unresolved() { + let root = scratch( + "stale", + &[ + ( + "pyproject.toml", + "[tool.poetry]\nname = \"app\"\n[tool.poetry.dependencies]\npython = \"^3.10\"\nclick = \"^8\"\nmissing = \"^1\"\n", + ), + ( + "poetry.lock", + "[[package]]\nname = \"click\"\nversion = \"8.1.7\"\n\n[metadata]\nlock-version = \"2.1\"\n", + ), + ], + ); + let extraction = extract(&root, json!({})).unwrap(); + assert_eq!(extraction["metadata"]["unresolved"], json!([["app", "dependencies", "missing"]])); + assert_eq!(entity(&extraction, "package:missing")["data"], json!({})); + assert_eq!( + edge(&extraction, "project:app", "dependencies", "package:click")["data"]["resolved"], + "8.1.7" + ); + let _ = fs::remove_dir_all(&root); +} + +#[test] +fn several_locked_versions_of_one_name_keep_the_most_used_copy_under_the_plain_id() { + let lock = r#"version = 1 +requires-python = ">=3.9" + +[[package]] +name = "app" +version = "1.0.0" +source = { virtual = "." } +dependencies = [ + { name = "numpy", version = "1.26.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.10'" }, + { name = "numpy", version = "2.1.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.10'" }, + { name = "tool" }, +] + +[[package]] +name = "numpy" +version = "1.26.4" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "numpy" +version = "2.1.0" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "tool" +version = "0.1.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [{ name = "numpy", version = "2.1.0", source = { registry = "https://pypi.org/simple" } }] +"#; + let root = scratch( + "forked", + &[ + ("pyproject.toml", "[project]\nname = \"app\"\nversion = \"1.0.0\"\n"), + ("uv.lock", lock), + ], + ); + let extraction = extract(&root, json!({})).unwrap(); + assert_eq!(entity(&extraction, "package:numpy")["data"]["version"], "2.1.0"); + assert_eq!(entity(&extraction, "package:numpy@1")["data"]["version"], "1.26.4"); + let ids: Vec<&str> = extraction["relationships"] + .as_array() + .unwrap() + .iter() + .filter(|e| e["from"] == "project:app" && e["kind"] == "dependencies") + .map(|e| e["id"].as_str().unwrap()) + .collect(); + assert_eq!( + ids, + [ + r#"dependency:["app","dependencies","numpy","package:numpy@1"]"#, + r#"dependency:["app","dependencies","numpy"]"#, + r#"dependency:["app","dependencies","tool"]"#, + ] + ); + let _ = fs::remove_dir_all(&root); +} diff --git a/packages/renderers/graph/README.md b/packages/renderers/graph/README.md index 17af50c7f..1cc0578a1 100644 --- a/packages/renderers/graph/README.md +++ b/packages/renderers/graph/README.md @@ -19,10 +19,11 @@ presentations of this bundle, and their scenarios live in `scenarios.json` here. node of its own, with a menu to inspect each dependency. - `dependencies` is a package dependency graph, left to right from the workspace members (`data.workspaceMember`, as `workspace-dependencies` and - `cargo-dependencies` write them) or NuGet projects and target frameworks: what - each one pulls in, directly and transitively. It replaces the former list - renderer (`@githubnext/projections-renderer-dependencies`), which only - repeated the flat package list GitHub's dependency review already shows. See + `cargo-dependencies` write them), NuGet projects and target frameworks, or + Python projects (`python-dependencies`): what each one pulls in, directly and + transitively. It replaces the former list renderer + (`@githubnext/projections-renderer-dependencies`), which only repeated the + flat package list GitHub's dependency review already shows. See [Dependency graphs](#dependency-graphs). - `graph`, `graph-horizontal`, `dag` and `architecture` show facts from `data` when asked, through controls a definition presets in From 895f88a41953520d80bad38979b6e7c2f5eb4e74 Mon Sep 17 00:00:00 2001 From: agorischek <6295280+agorischek@users.noreply.github.com> Date: Fri, 4 Dec 2026 21:15:01 +0000 Subject: [PATCH 2/7] Changelog fragment for python-dependencies (#386) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- changelog.d/386.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog.d/386.md diff --git a/changelog.d/386.md b/changelog.d/386.md new file mode 100644 index 000000000..b36ddcea3 --- /dev/null +++ b/changelog.d/386.md @@ -0,0 +1,5 @@ +--- +section: built-ins +--- + +- **`python-dependencies` draws a Python project's dependency graph** (#386). The new built-in extractor reads `uv.lock`, `poetry.lock`, `pdm.lock` or pinned requirements files, with the projects `pyproject.toml` declares (PEP 621 `[project]`, Poetry and uv workspace members), straight from the revision's files: it runs no Python, installs nothing and needs no `--trust`. Projects and packages are drawn with the `dependencies` renderer like the npm, Cargo and NuGet graphs, direct and transitive dependencies come from the lockfile, and extras and dependency groups are relationships of their own; environment markers are recorded but not evaluated. `projections explore` proposes it for Python projects. See [Python dependencies](docs/builtins/extractors/python-dependencies.md). From 5be733aadf68502e58462fa89f90e9290ed2146c Mon Sep 17 00:00:00 2001 From: agorischek <6295280+agorischek@users.noreply.github.com> Date: Fri, 4 Dec 2026 21:19:01 +0000 Subject: [PATCH 3/7] python-dependencies: format the fixture lock script in the repository's style Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- .../tests/fixtures/lock.mjs | 93 ++++++++----------- 1 file changed, 40 insertions(+), 53 deletions(-) diff --git a/packages/extractors/python-dependencies/tests/fixtures/lock.mjs b/packages/extractors/python-dependencies/tests/fixtures/lock.mjs index 9c69493b3..c79382c84 100644 --- a/packages/extractors/python-dependencies/tests/fixtures/lock.mjs +++ b/packages/extractors/python-dependencies/tests/fixtures/lock.mjs @@ -6,79 +6,66 @@ // node packages/extractors/python-dependencies/tests/fixtures/lock.mjs [index URL] // // Without an index URL, PIP_INDEX_URL or https://pypi.org/simple is used. Requires uv; uvx runs Poetry and PDM. -import { execFileSync } from "node:child_process"; -import { readFileSync, rmSync, writeFileSync } from "node:fs"; -import path from "node:path"; -import { fileURLToPath } from "node:url"; +import {execFileSync} from 'node:child_process' +import {readFileSync, rmSync, writeFileSync} from 'node:fs' +import path from 'node:path' +import {fileURLToPath} from 'node:url' -const here = path.dirname(fileURLToPath(import.meta.url)); -const index = - process.argv[2] ?? process.env.PIP_INDEX_URL ?? "https://pypi.org/simple"; +const here = path.dirname(fileURLToPath(import.meta.url)) +const index = process.argv[2] ?? process.env.PIP_INDEX_URL ?? 'https://pypi.org/simple' const environment = { ...process.env, UV_INDEX_URL: index, PDM_PYPI_URL: index, -}; +} const run = (directory, command, ...args) => execFileSync(command, args, { cwd: path.join(here, directory), env: environment, - stdio: "inherit", - }); -const rewrite = (file, change) => - writeFileSync( - path.join(here, file), - change(readFileSync(path.join(here, file), "utf8")), - ); + stdio: 'inherit', + }) +const rewrite = (file, change) => writeFileSync(path.join(here, file), change(readFileSync(path.join(here, file), 'utf8'))) -for (const directory of ["uv-workspace"]) { - run(directory, "uv", "lock", "--index-url", index); - rewrite(`${directory}/uv.lock`, (text) => +for (const directory of ['uv-workspace']) { + run(directory, 'uv', 'lock', '--index-url', index) + rewrite(`${directory}/uv.lock`, text => text - .replaceAll( - `registry = "${index}"`, - 'registry = "https://pypi.org/simple"', - ) - .replace(/^sdist = .*\n/gmu, "") - .replace(/^wheels = \[\n(?: {4}.*\n)*\]\n/gmu, ""), - ); + .replaceAll(`registry = "${index}"`, 'registry = "https://pypi.org/simple"') + .replace(/^sdist = .*\n/gmu, '') + .replace(/^wheels = \[\n(?: {4}.*\n)*\]\n/gmu, ''), + ) } // Poetry reads its index from the project, so it is added while locking, and a lockfile naming another index is replaced. -rmSync(path.join(here, "poetry/poetry.lock"), { force: true }); -const manifest = readFileSync(path.join(here, "poetry/pyproject.toml"), "utf8"); +rmSync(path.join(here, 'poetry/poetry.lock'), {force: true}) +const manifest = readFileSync(path.join(here, 'poetry/pyproject.toml'), 'utf8') try { writeFileSync( - path.join(here, "poetry/pyproject.toml"), + path.join(here, 'poetry/pyproject.toml'), `${manifest}\n[[tool.poetry.source]]\nname = "index"\nurl = "${index}"\npriority = "primary"\n`, - ); - run("poetry", "uvx", "--python", "3.12", "poetry", "lock"); + ) + run('poetry', 'uvx', '--python', '3.12', 'poetry', 'lock') } finally { - writeFileSync(path.join(here, "poetry/pyproject.toml"), manifest); + writeFileSync(path.join(here, 'poetry/pyproject.toml'), manifest) } -rewrite("poetry/poetry.lock", (text) => - text.replace( - /\n\[package\.source\]\ntype = "legacy"\n(?:.*\n)*?(?=\n|$)/gu, - "\n", - ), -); +rewrite('poetry/poetry.lock', text => text.replace(/\n\[package\.source\]\ntype = "legacy"\n(?:.*\n)*?(?=\n|$)/gu, '\n')) -run("pdm", "uvx", "--python", "3.12", "pdm", "lock", "-G", ":all"); -rmSync(path.join(here, "pdm/.venv"), { recursive: true, force: true }); -rmSync(path.join(here, "pdm/.pdm-python"), { force: true }); +run('pdm', 'uvx', '--python', '3.12', 'pdm', 'lock', '-G', ':all') +rmSync(path.join(here, 'pdm/.venv'), {recursive: true, force: true}) +rmSync(path.join(here, 'pdm/.pdm-python'), {force: true}) run( - "requirements", - "uv", - "pip", - "compile", - "requirements.in", - "--index-url", + 'requirements', + 'uv', + 'pip', + 'compile', + 'requirements.in', + '--index-url', index, - "--python-version", - "3.10", - "--custom-compile-command", - "uv pip compile requirements.in -o requirements.txt", - "-o", - "requirements.txt", -); + '--python-version', + '3.10', + '--custom-compile-command', + 'uv pip compile requirements.in -o requirements.txt', + '-o', + 'requirements.txt', +) From fc82b4480ea7c95f8d0e0352e874b75e398c4dd5 Mon Sep 17 00:00:00 2001 From: agorischek <6295280+agorischek@users.noreply.github.com> Date: Fri, 4 Dec 2026 22:20:11 +0000 Subject: [PATCH 4/7] graph renderer: a Python uv workspace dependencies scenario 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> --- docs/reference/renderers.md | 2 +- packages/renderers/graph/README.md | 4 +- .../renderers/graph/fixtures/make-python.mjs | 72 ++ .../graph/fixtures/python-workspace-2025.json | 1068 +++++++++++++++ .../graph/fixtures/python-workspace-2026.json | 1145 +++++++++++++++++ .../v1/packages/api/pyproject.toml | 18 + .../v1/packages/core/pyproject.toml | 9 + .../python-workspace/v1/pyproject.toml | 19 + .../fixtures/python-workspace/v1/uv.lock | 251 ++++ .../v2/packages/api/pyproject.toml | 18 + .../v2/packages/core/pyproject.toml | 9 + .../python-workspace/v2/pyproject.toml | 19 + .../fixtures/python-workspace/v2/uv.lock | 265 ++++ packages/renderers/graph/scenarios.json | 8 + .../graph/test/dependencies.test.mjs | 15 +- 15 files changed, 2916 insertions(+), 6 deletions(-) create mode 100644 packages/renderers/graph/fixtures/make-python.mjs create mode 100644 packages/renderers/graph/fixtures/python-workspace-2025.json create mode 100644 packages/renderers/graph/fixtures/python-workspace-2026.json create mode 100644 packages/renderers/graph/fixtures/python-workspace/v1/packages/api/pyproject.toml create mode 100644 packages/renderers/graph/fixtures/python-workspace/v1/packages/core/pyproject.toml create mode 100644 packages/renderers/graph/fixtures/python-workspace/v1/pyproject.toml create mode 100644 packages/renderers/graph/fixtures/python-workspace/v1/uv.lock create mode 100644 packages/renderers/graph/fixtures/python-workspace/v2/packages/api/pyproject.toml create mode 100644 packages/renderers/graph/fixtures/python-workspace/v2/packages/core/pyproject.toml create mode 100644 packages/renderers/graph/fixtures/python-workspace/v2/pyproject.toml create mode 100644 packages/renderers/graph/fixtures/python-workspace/v2/uv.lock diff --git a/docs/reference/renderers.md b/docs/reference/renderers.md index 34383901f..57b3d3b5f 100644 --- a/docs/reference/renderers.md +++ b/docs/reference/renderers.md @@ -99,7 +99,7 @@ Built-in Projections graph renderer: staged, identity-stable graph transitions ( - Handles: `graph`, `graph-horizontal`, `dag`, `architecture`, `infrastructure`, `dependencies` - Comparison modes: `diff`, `side-by-side`, `animated`, `swipe` - Package: `@githubnext/projections-renderer-graph` -- Example scenarios ([`scenarios.json`](../../packages/renderers/graph/scenarios.json)): Service platform; Service platform, payments first (custom order); Test timings with volatile durations; Class summaries, generated by a model; Source references, left to right; Declared rename; Feature flags; Feature flags, one revision; Single extraction; CI pipeline restructure; Release workflow; Platform gains a worker; Storage module split; Single extraction; Card icons; OpenRewrite: JUnit 4 to JUnit 5; Terraform: the database is replaced; Bicep: a private endpoint subnet; Terraform: one revision's plan; React 19.2 and clsx; Express 5 and React 19; npm workspace (one revision); NuGet package update; NuGet library with long package names; A layered module graph; A layered module graph (one revision); A wide module graph; A wide module graph (one revision); A hub-heavy module graph (one revision); MCP tools, toolsets and OAuth scopes; An architecture of 42 components (one revision); Who may reach what: 6 callers, 16 owners, 74 relationships (graph); Who may reach what: 6 callers, 16 owners, 74 relationships (architecture) +- Example scenarios ([`scenarios.json`](../../packages/renderers/graph/scenarios.json)): Service platform; Service platform, payments first (custom order); Test timings with volatile durations; Class summaries, generated by a model; Source references, left to right; Declared rename; Feature flags; Feature flags, one revision; Single extraction; CI pipeline restructure; Release workflow; Platform gains a worker; Storage module split; Single extraction; Card icons; OpenRewrite: JUnit 4 to JUnit 5; Terraform: the database is replaced; Bicep: a private endpoint subnet; Terraform: one revision's plan; React 19.2 and clsx; Express 5 and React 19; npm workspace (one revision); NuGet package update; NuGet library with long package names; Python uv workspace: a year of releases; A layered module graph; A layered module graph (one revision); A wide module graph; A wide module graph (one revision); A hub-heavy module graph (one revision); MCP tools, toolsets and OAuth scopes; An architecture of 42 components (one revision); Who may reach what: 6 callers, 16 owners, 74 relationships (graph); Who may reach what: 6 callers, 16 owners, 74 relationships (architecture) ## `runtime-policy` diff --git a/packages/renderers/graph/README.md b/packages/renderers/graph/README.md index 1cc0578a1..e8f1b7746 100644 --- a/packages/renderers/graph/README.md +++ b/packages/renderers/graph/README.md @@ -216,4 +216,6 @@ Fixtures: `fixtures/npm-workspace-v{1,2,3}.json` are real extractions of the npm workspace revisions in `fixtures/npm-workspace/`, regenerated with `node packages/renderers/graph/fixtures/make-dependencies.mjs`; `fixtures/nuget-*.json` are synthetic NuGet-shaped extractions written by -`fixtures/make-nuget.mjs`. +`fixtures/make-nuget.mjs`; `fixtures/python-workspace-{2025,2026}.json` are real +extractions of the uv workspace revisions in `fixtures/python-workspace/`, +regenerated with `node packages/renderers/graph/fixtures/make-python.mjs`. diff --git a/packages/renderers/graph/fixtures/make-python.mjs b/packages/renderers/graph/fixtures/make-python.mjs new file mode 100644 index 000000000..f2818605d --- /dev/null +++ b/packages/renderers/graph/fixtures/make-python.mjs @@ -0,0 +1,72 @@ +// Regenerates the Python dependency graph fixtures from the uv workspaces beside this script: two revisions of one +// workspace, `python-workspace/v1` and `v2`, are committed to a scratch Git repository, and the python-dependencies +// extractor reads each with the Projections CLI into `python-workspace-.json`, named by the year its packages +// were locked at rather than `-v1` and `-v2`, which the rules comparator's golden corpus would pick up as a pair. From +// v1 to v2 a year of releases is locked (v1 resolves packages published before 2025-03-01, v2 before 2026-11-01), the +// core package adopts pydantic, the API drops httpx's HTTP/2 extra, and the root swaps tomli for structlog. +// +// node packages/renderers/graph/fixtures/make-python.mjs [path/to/projections] [--lock [index URL]] +// +// Without a path the debug CLI is built with Cargo. `--lock` first relocks both revisions with uv against the index +// (default https://pypi.org/simple), naming https://pypi.org/simple as their registry and dropping the sdist and wheel +// entries, which the extractor doesn't read. +import {execFileSync} from 'node:child_process' +import {cpSync, mkdtempSync, readFileSync, rmSync, writeFileSync} from 'node:fs' +import {tmpdir} from 'node:os' +import path from 'node:path' +import {fileURLToPath} from 'node:url' + +const here = path.dirname(fileURLToPath(import.meta.url)) +const workspace = path.resolve(here, '../../../..') +const args = process.argv.slice(2) +const lock = args.indexOf('--lock') +const revisions = {v1: '2025-03-01T00:00:00Z', v2: '2026-11-01T00:00:00Z'} +if (lock >= 0) { + const index = args[lock + 1] && !args[lock + 1].startsWith('-') ? args.splice(lock + 1, 1)[0] : 'https://pypi.org/simple' + args.splice(lock, 1) + for (const [revision, before] of Object.entries(revisions)) { + const directory = path.join(here, 'python-workspace', revision) + execFileSync('uv', ['lock', '--index-url', index, '--exclude-newer', before], {cwd: directory, stdio: 'inherit'}) + const file = path.join(directory, 'uv.lock') + const text = readFileSync(file, 'utf8') + .replaceAll(`registry = "${index}"`, 'registry = "https://pypi.org/simple"') + .replace(/^sdist = .*\n/gmu, '') + .replace(/^wheels = \[\n(?: {4}.*\n)*\]\n/gmu, '') + writeFileSync(file, text) + } +} +let cli = args[0] && path.resolve(args[0]) +if (!cli) { + execFileSync('cargo', ['build', '-q', '-p', 'projections-cli'], { + cwd: workspace, + stdio: 'inherit', + }) + cli = path.join(process.env.CARGO_TARGET_DIR ?? path.join(workspace, 'target'), 'debug/projections') +} +const repository = mkdtempSync(path.join(tmpdir(), 'projections-python-fixtures-')) +const git = (...command) => + execFileSync('git', ['-c', 'user.name=Fixtures', '-c', 'user.email=fixtures@example.com', ...command], {cwd: repository}) +try { + git('init', '-q') + const names = Object.keys(revisions) + for (const revision of names) { + git('rm', '-rq', '--ignore-unmatch', '.') + cpSync(path.join(here, 'python-workspace', revision), repository, { + recursive: true, + }) + git('add', '-A') + git('commit', '-qm', revision) + } + for (const [position, revision] of names.entries()) { + const commit = `HEAD~${names.length - 1 - position}` + const saved = JSON.parse( + execFileSync(cli, ['show', commit, '-p', 'python-dependencies', '--json'], {cwd: repository, encoding: 'utf8'}), + ) + writeFileSync( + path.join(here, `python-workspace-${revisions[revision].slice(0, 4)}.json`), + `${JSON.stringify(saved.extraction, null, 2)}\n`, + ) + } +} finally { + rmSync(repository, {recursive: true, force: true}) +} diff --git a/packages/renderers/graph/fixtures/python-workspace-2025.json b/packages/renderers/graph/fixtures/python-workspace-2025.json new file mode 100644 index 000000000..2683a993c --- /dev/null +++ b/packages/renderers/graph/fixtures/python-workspace-2025.json @@ -0,0 +1,1068 @@ +{ + "entities": [ + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "4.8.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:anyio", + "kind": "package", + "label": "anyio" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "25.1.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:attrs", + "kind": "package", + "label": "attrs" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "2025.1.31" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:certifi", + "kind": "package", + "label": "certifi" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "8.1.8" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:click", + "kind": "package", + "label": "click" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "0.4.6" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:colorama", + "kind": "package", + "label": "colorama" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "1.2.2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:exceptiongroup", + "kind": "package", + "label": "exceptiongroup" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "0.14.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:h11", + "kind": "package", + "label": "h11" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "4.2.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:h2", + "kind": "package", + "label": "h2" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "4.1.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:hpack", + "kind": "package", + "label": "hpack" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "1.0.7" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:httpcore", + "kind": "package", + "label": "httpcore" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "0.28.1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:httpx", + "kind": "package", + "label": "httpx" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "6.1.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:hyperframe", + "kind": "package", + "label": "hyperframe" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "3.10" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:idna", + "kind": "package", + "label": "idna" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "2.0.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:iniconfig", + "kind": "package", + "label": "iniconfig" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "3.0.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:markdown-it-py", + "kind": "package", + "label": "markdown-it-py" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "0.1.2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:mdurl", + "kind": "package", + "label": "mdurl" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "24.2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:packaging", + "kind": "package", + "label": "packaging" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "1.5.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:pluggy", + "kind": "package", + "label": "pluggy" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "2.19.1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:pygments", + "kind": "package", + "label": "pygments" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "8.3.4" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:pytest", + "kind": "package", + "label": "pytest" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "2.3.1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:pytest-timeout", + "kind": "package", + "label": "pytest-timeout" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "13.9.4" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:rich", + "kind": "package", + "label": "rich" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "1.3.1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:sniffio", + "kind": "package", + "label": "sniffio" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "2.2.1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:tomli", + "kind": "package", + "label": "tomli" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "4.12.2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:typing-extensions", + "kind": "package", + "label": "typing-extensions" + }, + { + "confidence": "authoritative", + "data": { + "path": ".", + "version": "1.4.0" + }, + "evidence": [ + { + "kind": "manifest", + "source": "pyproject.toml" + } + ], + "id": "project:harbor", + "kind": "project", + "label": "harbor" + }, + { + "confidence": "authoritative", + "data": { + "path": "packages/api", + "version": "0.3.0" + }, + "evidence": [ + { + "kind": "manifest", + "source": "packages/api/pyproject.toml" + } + ], + "id": "project:harbor-api", + "kind": "project", + "label": "harbor-api" + }, + { + "confidence": "authoritative", + "data": { + "path": "packages/core", + "version": "0.3.0" + }, + "evidence": [ + { + "kind": "manifest", + "source": "packages/core/pyproject.toml" + } + ], + "id": "project:harbor-core", + "kind": "project", + "label": "Harbor_Core" + } + ], + "metadata": { + "limitations": [ + "Every extra and dependency group a project declares is included; a package's extras are followed only where a dependency in the graph requests them.", + "Environment markers are recorded on relationships as `marker` but not evaluated: the graph covers every platform and Python version at once." + ], + "lockfile": "uv.lock", + "lockfileVersion": 1, + "manager": "uv", + "unresolved": [] + }, + "protocolVersion": 0, + "relationships": [ + { + "confidence": "authoritative", + "data": { + "resolved": "8.1.8", + "type": "dependencies", + "version": ">=8.1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor", + "id": "dependency:[\"harbor\",\"dependencies\",\"click\"]", + "kind": "dependencies", + "label": ">=8.1", + "to": "package:click" + }, + { + "confidence": "authoritative", + "data": { + "resolved": "0.3.0", + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor", + "id": "dependency:[\"harbor\",\"dependencies\",\"harbor-api\"]", + "kind": "dependencies", + "to": "project:harbor-api" + }, + { + "confidence": "authoritative", + "data": { + "marker": "python_full_version < '3.11'", + "resolved": "2.2.1", + "type": "dependencies", + "version": ">=2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor", + "id": "dependency:[\"harbor\",\"dependencies\",\"tomli\"]", + "kind": "dependencies", + "label": ">=2", + "to": "package:tomli" + }, + { + "confidence": "authoritative", + "data": { + "group": "dev", + "resolved": "8.3.4", + "type": "devDependencies", + "version": ">=8" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor", + "id": "dependency:[\"harbor\",\"devDependencies\",\"dev\",\"pytest\"]", + "kind": "devDependencies", + "label": ">=8", + "to": "package:pytest" + }, + { + "confidence": "authoritative", + "data": { + "group": "dev", + "resolved": "2.3.1", + "type": "devDependencies", + "version": ">=2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor", + "id": "dependency:[\"harbor\",\"devDependencies\",\"dev\",\"pytest-timeout\"]", + "kind": "devDependencies", + "label": ">=2", + "to": "package:pytest-timeout" + }, + { + "confidence": "authoritative", + "data": { + "group": "test", + "resolved": "8.3.4", + "type": "devDependencies", + "version": ">=8" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor", + "id": "dependency:[\"harbor\",\"devDependencies\",\"test\",\"pytest\"]", + "kind": "devDependencies", + "label": ">=8", + "to": "package:pytest" + }, + { + "confidence": "authoritative", + "data": { + "resolved": "0.3.0", + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor-api", + "id": "dependency:[\"harbor-api\",\"dependencies\",\"harbor-core\"]", + "kind": "dependencies", + "to": "project:harbor-core" + }, + { + "confidence": "authoritative", + "data": { + "extras": [ + "http2" + ], + "resolved": "0.28.1", + "type": "dependencies", + "version": ">=0.27,<1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor-api", + "id": "dependency:[\"harbor-api\",\"dependencies\",\"httpx\"]", + "kind": "dependencies", + "label": ">=0.27,<1", + "to": "package:httpx" + }, + { + "confidence": "authoritative", + "data": { + "extra": "cli", + "resolved": "13.9.4", + "type": "optionalDependencies", + "version": ">=13" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor-api", + "id": "dependency:[\"harbor-api\",\"optionalDependencies\",\"cli\",\"rich\"]", + "kind": "optionalDependencies", + "label": ">=13", + "to": "package:rich" + }, + { + "confidence": "authoritative", + "data": { + "resolved": "25.1.0", + "type": "dependencies", + "version": ">=24" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor-core", + "id": "dependency:[\"harbor-core\",\"dependencies\",\"attrs\"]", + "kind": "dependencies", + "label": ">=24", + "to": "package:attrs" + }, + { + "confidence": "authoritative", + "data": { + "marker": "python_full_version < '3.11'", + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:anyio", + "id": "dependency:[\"package:anyio\",\"dependencies\",\"exceptiongroup\"]", + "kind": "dependencies", + "to": "package:exceptiongroup" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:anyio", + "id": "dependency:[\"package:anyio\",\"dependencies\",\"idna\"]", + "kind": "dependencies", + "to": "package:idna" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:anyio", + "id": "dependency:[\"package:anyio\",\"dependencies\",\"sniffio\"]", + "kind": "dependencies", + "to": "package:sniffio" + }, + { + "confidence": "authoritative", + "data": { + "marker": "python_full_version < '3.13'", + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:anyio", + "id": "dependency:[\"package:anyio\",\"dependencies\",\"typing-extensions\"]", + "kind": "dependencies", + "to": "package:typing-extensions" + }, + { + "confidence": "authoritative", + "data": { + "marker": "sys_platform == 'win32'", + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:click", + "id": "dependency:[\"package:click\",\"dependencies\",\"colorama\"]", + "kind": "dependencies", + "to": "package:colorama" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:h2", + "id": "dependency:[\"package:h2\",\"dependencies\",\"hpack\"]", + "kind": "dependencies", + "to": "package:hpack" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:h2", + "id": "dependency:[\"package:h2\",\"dependencies\",\"hyperframe\"]", + "kind": "dependencies", + "to": "package:hyperframe" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:httpcore", + "id": "dependency:[\"package:httpcore\",\"dependencies\",\"certifi\"]", + "kind": "dependencies", + "to": "package:certifi" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:httpcore", + "id": "dependency:[\"package:httpcore\",\"dependencies\",\"h11\"]", + "kind": "dependencies", + "to": "package:h11" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"dependencies\",\"anyio\"]", + "kind": "dependencies", + "to": "package:anyio" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"dependencies\",\"certifi\"]", + "kind": "dependencies", + "to": "package:certifi" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"dependencies\",\"httpcore\"]", + "kind": "dependencies", + "to": "package:httpcore" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"dependencies\",\"idna\"]", + "kind": "dependencies", + "to": "package:idna" + }, + { + "confidence": "authoritative", + "data": { + "extra": "http2", + "type": "optionalDependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"optionalDependencies\",\"http2\",\"h2\"]", + "kind": "optionalDependencies", + "to": "package:h2" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:markdown-it-py", + "id": "dependency:[\"package:markdown-it-py\",\"dependencies\",\"mdurl\"]", + "kind": "dependencies", + "to": "package:mdurl" + }, + { + "confidence": "authoritative", + "data": { + "marker": "sys_platform == 'win32'", + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"colorama\"]", + "kind": "dependencies", + "to": "package:colorama" + }, + { + "confidence": "authoritative", + "data": { + "marker": "python_full_version < '3.11'", + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"exceptiongroup\"]", + "kind": "dependencies", + "to": "package:exceptiongroup" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"iniconfig\"]", + "kind": "dependencies", + "to": "package:iniconfig" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"packaging\"]", + "kind": "dependencies", + "to": "package:packaging" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"pluggy\"]", + "kind": "dependencies", + "to": "package:pluggy" + }, + { + "confidence": "authoritative", + "data": { + "marker": "python_full_version < '3.11'", + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"tomli\"]", + "kind": "dependencies", + "to": "package:tomli" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:pytest-timeout", + "id": "dependency:[\"package:pytest-timeout\",\"dependencies\",\"pytest\"]", + "kind": "dependencies", + "to": "package:pytest" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:rich", + "id": "dependency:[\"package:rich\",\"dependencies\",\"markdown-it-py\"]", + "kind": "dependencies", + "to": "package:markdown-it-py" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:rich", + "id": "dependency:[\"package:rich\",\"dependencies\",\"pygments\"]", + "kind": "dependencies", + "to": "package:pygments" + }, + { + "confidence": "authoritative", + "data": { + "marker": "python_full_version < '3.11'", + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:rich", + "id": "dependency:[\"package:rich\",\"dependencies\",\"typing-extensions\"]", + "kind": "dependencies", + "to": "package:typing-extensions" + } + ], + "schema": "graph/v0" +} diff --git a/packages/renderers/graph/fixtures/python-workspace-2026.json b/packages/renderers/graph/fixtures/python-workspace-2026.json new file mode 100644 index 000000000..334ad6d39 --- /dev/null +++ b/packages/renderers/graph/fixtures/python-workspace-2026.json @@ -0,0 +1,1145 @@ +{ + "entities": [ + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "0.8.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:annotated-types", + "kind": "package", + "label": "annotated-types" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "4.15.1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:anyio", + "kind": "package", + "label": "anyio" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "26.1.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:attrs", + "kind": "package", + "label": "attrs" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "2026.10.23" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:certifi", + "kind": "package", + "label": "certifi" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "8.5.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:click", + "kind": "package", + "label": "click" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "0.4.6" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:colorama", + "kind": "package", + "label": "colorama" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "1.3.1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:exceptiongroup", + "kind": "package", + "label": "exceptiongroup" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "0.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:h11", + "kind": "package", + "label": "h11" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "1.0.9" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:httpcore", + "kind": "package", + "label": "httpcore" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "0.28.1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:httpx", + "kind": "package", + "label": "httpx" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "3.20" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:idna", + "kind": "package", + "label": "idna" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "2.3.1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:iniconfig", + "kind": "package", + "label": "iniconfig" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "4.2.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:markdown-it-py", + "kind": "package", + "label": "markdown-it-py" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "0.1.2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:mdurl", + "kind": "package", + "label": "mdurl" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "26.3" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:packaging", + "kind": "package", + "label": "packaging" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "1.7.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:pluggy", + "kind": "package", + "label": "pluggy" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "2.14.2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:pydantic", + "kind": "package", + "label": "pydantic" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "2.50.2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:pydantic-core", + "kind": "package", + "label": "pydantic-core" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "2.21.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:pygments", + "kind": "package", + "label": "pygments" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "9.2.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:pytest", + "kind": "package", + "label": "pytest" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "2.4.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:pytest-timeout", + "kind": "package", + "label": "pytest-timeout" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "15.0.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:rich", + "kind": "package", + "label": "rich" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "26.1.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:structlog", + "kind": "package", + "label": "structlog" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "2.5.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:tomli", + "kind": "package", + "label": "tomli" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "4.16.0" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:typing-extensions", + "kind": "package", + "label": "typing-extensions" + }, + { + "confidence": "authoritative", + "data": { + "source": "https://pypi.org/simple", + "version": "0.4.4" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "id": "package:typing-inspection", + "kind": "package", + "label": "typing-inspection" + }, + { + "confidence": "authoritative", + "data": { + "path": ".", + "version": "1.4.0" + }, + "evidence": [ + { + "kind": "manifest", + "source": "pyproject.toml" + } + ], + "id": "project:harbor", + "kind": "project", + "label": "harbor" + }, + { + "confidence": "authoritative", + "data": { + "path": "packages/api", + "version": "0.3.0" + }, + "evidence": [ + { + "kind": "manifest", + "source": "packages/api/pyproject.toml" + } + ], + "id": "project:harbor-api", + "kind": "project", + "label": "harbor-api" + }, + { + "confidence": "authoritative", + "data": { + "path": "packages/core", + "version": "0.3.0" + }, + "evidence": [ + { + "kind": "manifest", + "source": "packages/core/pyproject.toml" + } + ], + "id": "project:harbor-core", + "kind": "project", + "label": "Harbor_Core" + } + ], + "metadata": { + "limitations": [ + "Every extra and dependency group a project declares is included; a package's extras are followed only where a dependency in the graph requests them.", + "Environment markers are recorded on relationships as `marker` but not evaluated: the graph covers every platform and Python version at once." + ], + "lockfile": "uv.lock", + "lockfileVersion": 1, + "manager": "uv", + "unresolved": [] + }, + "protocolVersion": 0, + "relationships": [ + { + "confidence": "authoritative", + "data": { + "resolved": "8.5.0", + "type": "dependencies", + "version": ">=8.1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor", + "id": "dependency:[\"harbor\",\"dependencies\",\"click\"]", + "kind": "dependencies", + "label": ">=8.1", + "to": "package:click" + }, + { + "confidence": "authoritative", + "data": { + "resolved": "0.3.0", + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor", + "id": "dependency:[\"harbor\",\"dependencies\",\"harbor-api\"]", + "kind": "dependencies", + "to": "project:harbor-api" + }, + { + "confidence": "authoritative", + "data": { + "resolved": "26.1.0", + "type": "dependencies", + "version": ">=24" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor", + "id": "dependency:[\"harbor\",\"dependencies\",\"structlog\"]", + "kind": "dependencies", + "label": ">=24", + "to": "package:structlog" + }, + { + "confidence": "authoritative", + "data": { + "group": "dev", + "resolved": "9.2.0", + "type": "devDependencies", + "version": ">=8" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor", + "id": "dependency:[\"harbor\",\"devDependencies\",\"dev\",\"pytest\"]", + "kind": "devDependencies", + "label": ">=8", + "to": "package:pytest" + }, + { + "confidence": "authoritative", + "data": { + "group": "dev", + "resolved": "2.4.0", + "type": "devDependencies", + "version": ">=2" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor", + "id": "dependency:[\"harbor\",\"devDependencies\",\"dev\",\"pytest-timeout\"]", + "kind": "devDependencies", + "label": ">=2", + "to": "package:pytest-timeout" + }, + { + "confidence": "authoritative", + "data": { + "group": "test", + "resolved": "9.2.0", + "type": "devDependencies", + "version": ">=8" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor", + "id": "dependency:[\"harbor\",\"devDependencies\",\"test\",\"pytest\"]", + "kind": "devDependencies", + "label": ">=8", + "to": "package:pytest" + }, + { + "confidence": "authoritative", + "data": { + "resolved": "0.3.0", + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor-api", + "id": "dependency:[\"harbor-api\",\"dependencies\",\"harbor-core\"]", + "kind": "dependencies", + "to": "project:harbor-core" + }, + { + "confidence": "authoritative", + "data": { + "resolved": "0.28.1", + "type": "dependencies", + "version": ">=0.28,<1" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor-api", + "id": "dependency:[\"harbor-api\",\"dependencies\",\"httpx\"]", + "kind": "dependencies", + "label": ">=0.28,<1", + "to": "package:httpx" + }, + { + "confidence": "authoritative", + "data": { + "extra": "cli", + "resolved": "15.0.0", + "type": "optionalDependencies", + "version": ">=13" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor-api", + "id": "dependency:[\"harbor-api\",\"optionalDependencies\",\"cli\",\"rich\"]", + "kind": "optionalDependencies", + "label": ">=13", + "to": "package:rich" + }, + { + "confidence": "authoritative", + "data": { + "resolved": "26.1.0", + "type": "dependencies", + "version": ">=24" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor-core", + "id": "dependency:[\"harbor-core\",\"dependencies\",\"attrs\"]", + "kind": "dependencies", + "label": ">=24", + "to": "package:attrs" + }, + { + "confidence": "authoritative", + "data": { + "resolved": "2.14.2", + "type": "dependencies", + "version": ">=2.8" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "project:harbor-core", + "id": "dependency:[\"harbor-core\",\"dependencies\",\"pydantic\"]", + "kind": "dependencies", + "label": ">=2.8", + "to": "package:pydantic" + }, + { + "confidence": "authoritative", + "data": { + "marker": "python_full_version < '3.11'", + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:anyio", + "id": "dependency:[\"package:anyio\",\"dependencies\",\"exceptiongroup\"]", + "kind": "dependencies", + "to": "package:exceptiongroup" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:anyio", + "id": "dependency:[\"package:anyio\",\"dependencies\",\"idna\"]", + "kind": "dependencies", + "to": "package:idna" + }, + { + "confidence": "authoritative", + "data": { + "marker": "python_full_version < '3.15'", + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:anyio", + "id": "dependency:[\"package:anyio\",\"dependencies\",\"typing-extensions\"]", + "kind": "dependencies", + "to": "package:typing-extensions" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:exceptiongroup", + "id": "dependency:[\"package:exceptiongroup\",\"dependencies\",\"typing-extensions\"]", + "kind": "dependencies", + "to": "package:typing-extensions" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:httpcore", + "id": "dependency:[\"package:httpcore\",\"dependencies\",\"certifi\"]", + "kind": "dependencies", + "to": "package:certifi" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:httpcore", + "id": "dependency:[\"package:httpcore\",\"dependencies\",\"h11\"]", + "kind": "dependencies", + "to": "package:h11" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"dependencies\",\"anyio\"]", + "kind": "dependencies", + "to": "package:anyio" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"dependencies\",\"certifi\"]", + "kind": "dependencies", + "to": "package:certifi" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"dependencies\",\"httpcore\"]", + "kind": "dependencies", + "to": "package:httpcore" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:httpx", + "id": "dependency:[\"package:httpx\",\"dependencies\",\"idna\"]", + "kind": "dependencies", + "to": "package:idna" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:markdown-it-py", + "id": "dependency:[\"package:markdown-it-py\",\"dependencies\",\"mdurl\"]", + "kind": "dependencies", + "to": "package:mdurl" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:pydantic", + "id": "dependency:[\"package:pydantic\",\"dependencies\",\"annotated-types\"]", + "kind": "dependencies", + "to": "package:annotated-types" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:pydantic", + "id": "dependency:[\"package:pydantic\",\"dependencies\",\"pydantic-core\"]", + "kind": "dependencies", + "to": "package:pydantic-core" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:pydantic", + "id": "dependency:[\"package:pydantic\",\"dependencies\",\"typing-extensions\"]", + "kind": "dependencies", + "to": "package:typing-extensions" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:pydantic", + "id": "dependency:[\"package:pydantic\",\"dependencies\",\"typing-inspection\"]", + "kind": "dependencies", + "to": "package:typing-inspection" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:pydantic-core", + "id": "dependency:[\"package:pydantic-core\",\"dependencies\",\"typing-extensions\"]", + "kind": "dependencies", + "to": "package:typing-extensions" + }, + { + "confidence": "authoritative", + "data": { + "marker": "sys_platform == 'win32'", + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"colorama\"]", + "kind": "dependencies", + "to": "package:colorama" + }, + { + "confidence": "authoritative", + "data": { + "marker": "python_full_version < '3.11'", + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"exceptiongroup\"]", + "kind": "dependencies", + "to": "package:exceptiongroup" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"iniconfig\"]", + "kind": "dependencies", + "to": "package:iniconfig" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"packaging\"]", + "kind": "dependencies", + "to": "package:packaging" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"pluggy\"]", + "kind": "dependencies", + "to": "package:pluggy" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"pygments\"]", + "kind": "dependencies", + "to": "package:pygments" + }, + { + "confidence": "authoritative", + "data": { + "marker": "python_full_version < '3.11'", + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:pytest", + "id": "dependency:[\"package:pytest\",\"dependencies\",\"tomli\"]", + "kind": "dependencies", + "to": "package:tomli" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:pytest-timeout", + "id": "dependency:[\"package:pytest-timeout\",\"dependencies\",\"pytest\"]", + "kind": "dependencies", + "to": "package:pytest" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:rich", + "id": "dependency:[\"package:rich\",\"dependencies\",\"markdown-it-py\"]", + "kind": "dependencies", + "to": "package:markdown-it-py" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:rich", + "id": "dependency:[\"package:rich\",\"dependencies\",\"pygments\"]", + "kind": "dependencies", + "to": "package:pygments" + }, + { + "confidence": "authoritative", + "data": { + "marker": "python_full_version < '3.11'", + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:structlog", + "id": "dependency:[\"package:structlog\",\"dependencies\",\"typing-extensions\"]", + "kind": "dependencies", + "to": "package:typing-extensions" + }, + { + "confidence": "authoritative", + "data": { + "type": "dependencies" + }, + "evidence": [ + { + "kind": "lockfile", + "source": "uv.lock" + } + ], + "from": "package:typing-inspection", + "id": "dependency:[\"package:typing-inspection\",\"dependencies\",\"typing-extensions\"]", + "kind": "dependencies", + "to": "package:typing-extensions" + } + ], + "schema": "graph/v0" +} diff --git a/packages/renderers/graph/fixtures/python-workspace/v1/packages/api/pyproject.toml b/packages/renderers/graph/fixtures/python-workspace/v1/packages/api/pyproject.toml new file mode 100644 index 000000000..7a9c3509b --- /dev/null +++ b/packages/renderers/graph/fixtures/python-workspace/v1/packages/api/pyproject.toml @@ -0,0 +1,18 @@ +[project] +name = "harbor-api" +version = "0.3.0" +requires-python = ">=3.10" +dependencies = [ + "harbor-core", + "httpx[http2]>=0.27,<1", +] + +[project.optional-dependencies] +cli = ["rich>=13"] + +[tool.uv.sources] +harbor-core = { workspace = true } + +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" diff --git a/packages/renderers/graph/fixtures/python-workspace/v1/packages/core/pyproject.toml b/packages/renderers/graph/fixtures/python-workspace/v1/packages/core/pyproject.toml new file mode 100644 index 000000000..adce6a1e2 --- /dev/null +++ b/packages/renderers/graph/fixtures/python-workspace/v1/packages/core/pyproject.toml @@ -0,0 +1,9 @@ +[project] +name = "Harbor_Core" +version = "0.3.0" +requires-python = ">=3.10" +dependencies = ["attrs>=24"] + +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" diff --git a/packages/renderers/graph/fixtures/python-workspace/v1/pyproject.toml b/packages/renderers/graph/fixtures/python-workspace/v1/pyproject.toml new file mode 100644 index 000000000..7196a8c26 --- /dev/null +++ b/packages/renderers/graph/fixtures/python-workspace/v1/pyproject.toml @@ -0,0 +1,19 @@ +[project] +name = "harbor" +version = "1.4.0" +requires-python = ">=3.10" +dependencies = [ + "harbor-api", + "click>=8.1", + "tomli>=2; python_version < '3.11'", +] + +[dependency-groups] +test = ["pytest>=8"] +dev = [{ include-group = "test" }, "pytest-timeout>=2"] + +[tool.uv.workspace] +members = ["packages/*"] + +[tool.uv.sources] +harbor-api = { workspace = true } diff --git a/packages/renderers/graph/fixtures/python-workspace/v1/uv.lock b/packages/renderers/graph/fixtures/python-workspace/v1/uv.lock new file mode 100644 index 000000000..cd22833d0 --- /dev/null +++ b/packages/renderers/graph/fixtures/python-workspace/v1/uv.lock @@ -0,0 +1,251 @@ +version = 1 +revision = 5 +requires-python = ">=3.10" + +[options] +exclude-newer = "2025-03-01T00:00:00Z" + +[manifest] +members = [ + "harbor", + "harbor-api", + "harbor-core", +] + +[[package]] +name = "anyio" +version = "4.8.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "exceptiongroup", marker = "python_full_version < '3.11'" }, + { name = "idna" }, + { name = "sniffio" }, + { name = "typing-extensions", marker = "python_full_version < '3.13'" }, +] + +[[package]] +name = "attrs" +version = "25.1.0" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "certifi" +version = "2025.1.31" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "click" +version = "8.1.8" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "colorama", marker = "sys_platform == 'win32'" }, +] + +[[package]] +name = "colorama" +version = "0.4.6" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "exceptiongroup" +version = "1.2.2" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "h11" +version = "0.14.0" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "h2" +version = "4.2.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "hpack" }, + { name = "hyperframe" }, +] + +[[package]] +name = "harbor" +version = "1.4.0" +source = { virtual = "." } +dependencies = [ + { name = "click" }, + { name = "harbor-api" }, + { name = "tomli", marker = "python_full_version < '3.11'" }, +] + +[package.dev-dependencies] +dev = [ + { name = "pytest" }, + { name = "pytest-timeout" }, +] +test = [ + { name = "pytest" }, +] + +[package.metadata] +requires-dist = [ + { name = "click", specifier = ">=8.1" }, + { name = "harbor-api", editable = "packages/api" }, + { name = "tomli", marker = "python_full_version < '3.11'", specifier = ">=2" }, +] + +[package.metadata.requires-dev] +dev = [ + { name = "pytest", specifier = ">=8" }, + { name = "pytest-timeout", specifier = ">=2" }, +] +test = [{ name = "pytest", specifier = ">=8" }] + +[[package]] +name = "harbor-api" +version = "0.3.0" +source = { editable = "packages/api" } +dependencies = [ + { name = "harbor-core" }, + { name = "httpx", extra = ["http2"] }, +] + +[package.optional-dependencies] +cli = [ + { name = "rich" }, +] + +[package.metadata] +requires-dist = [ + { name = "harbor-core", editable = "packages/core" }, + { name = "httpx", extras = ["http2"], specifier = ">=0.27,<1" }, + { name = "rich", marker = "extra == 'cli'", specifier = ">=13" }, +] +provides-extras = ["cli"] + +[[package]] +name = "harbor-core" +version = "0.3.0" +source = { editable = "packages/core" } +dependencies = [ + { name = "attrs" }, +] + +[package.metadata] +requires-dist = [{ name = "attrs", specifier = ">=24" }] + +[[package]] +name = "hpack" +version = "4.1.0" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "httpcore" +version = "1.0.7" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "certifi" }, + { name = "h11" }, +] + +[[package]] +name = "httpx" +version = "0.28.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "anyio" }, + { name = "certifi" }, + { name = "httpcore" }, + { name = "idna" }, +] + +[package.optional-dependencies] +http2 = [ + { name = "h2" }, +] + +[[package]] +name = "hyperframe" +version = "6.1.0" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "idna" +version = "3.10" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "iniconfig" +version = "2.0.0" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "markdown-it-py" +version = "3.0.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "mdurl" }, +] + +[[package]] +name = "mdurl" +version = "0.1.2" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "packaging" +version = "24.2" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "pluggy" +version = "1.5.0" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "pygments" +version = "2.19.1" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "pytest" +version = "8.3.4" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "colorama", marker = "sys_platform == 'win32'" }, + { name = "exceptiongroup", marker = "python_full_version < '3.11'" }, + { name = "iniconfig" }, + { name = "packaging" }, + { name = "pluggy" }, + { name = "tomli", marker = "python_full_version < '3.11'" }, +] + +[[package]] +name = "pytest-timeout" +version = "2.3.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "pytest" }, +] + +[[package]] +name = "rich" +version = "13.9.4" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "markdown-it-py" }, + { name = "pygments" }, + { name = "typing-extensions", marker = "python_full_version < '3.11'" }, +] + +[[package]] +name = "sniffio" +version = "1.3.1" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "tomli" +version = "2.2.1" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "typing-extensions" +version = "4.12.2" +source = { registry = "https://pypi.org/simple" } diff --git a/packages/renderers/graph/fixtures/python-workspace/v2/packages/api/pyproject.toml b/packages/renderers/graph/fixtures/python-workspace/v2/packages/api/pyproject.toml new file mode 100644 index 000000000..388c3af24 --- /dev/null +++ b/packages/renderers/graph/fixtures/python-workspace/v2/packages/api/pyproject.toml @@ -0,0 +1,18 @@ +[project] +name = "harbor-api" +version = "0.3.0" +requires-python = ">=3.10" +dependencies = [ + "harbor-core", + "httpx>=0.28,<1", +] + +[project.optional-dependencies] +cli = ["rich>=13"] + +[tool.uv.sources] +harbor-core = { workspace = true } + +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" diff --git a/packages/renderers/graph/fixtures/python-workspace/v2/packages/core/pyproject.toml b/packages/renderers/graph/fixtures/python-workspace/v2/packages/core/pyproject.toml new file mode 100644 index 000000000..d14049d5a --- /dev/null +++ b/packages/renderers/graph/fixtures/python-workspace/v2/packages/core/pyproject.toml @@ -0,0 +1,9 @@ +[project] +name = "Harbor_Core" +version = "0.3.0" +requires-python = ">=3.10" +dependencies = ["attrs>=24", "pydantic>=2.8"] + +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" diff --git a/packages/renderers/graph/fixtures/python-workspace/v2/pyproject.toml b/packages/renderers/graph/fixtures/python-workspace/v2/pyproject.toml new file mode 100644 index 000000000..645aa1014 --- /dev/null +++ b/packages/renderers/graph/fixtures/python-workspace/v2/pyproject.toml @@ -0,0 +1,19 @@ +[project] +name = "harbor" +version = "1.4.0" +requires-python = ">=3.10" +dependencies = [ + "harbor-api", + "click>=8.1", + "structlog>=24", +] + +[dependency-groups] +test = ["pytest>=8"] +dev = [{ include-group = "test" }, "pytest-timeout>=2"] + +[tool.uv.workspace] +members = ["packages/*"] + +[tool.uv.sources] +harbor-api = { workspace = true } diff --git a/packages/renderers/graph/fixtures/python-workspace/v2/uv.lock b/packages/renderers/graph/fixtures/python-workspace/v2/uv.lock new file mode 100644 index 000000000..180ffdacf --- /dev/null +++ b/packages/renderers/graph/fixtures/python-workspace/v2/uv.lock @@ -0,0 +1,265 @@ +version = 1 +revision = 5 +requires-python = ">=3.10" + +[options] +exclude-newer = "2026-11-01T00:00:00Z" + +[manifest] +members = [ + "harbor", + "harbor-api", + "harbor-core", +] + +[[package]] +name = "annotated-types" +version = "0.8.0" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "anyio" +version = "4.15.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "exceptiongroup", marker = "python_full_version < '3.11'" }, + { name = "idna" }, + { name = "typing-extensions", marker = "python_full_version < '3.15'" }, +] + +[[package]] +name = "attrs" +version = "26.1.0" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "certifi" +version = "2026.10.23" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "click" +version = "8.5.0" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "colorama" +version = "0.4.6" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "exceptiongroup" +version = "1.3.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions" }, +] + +[[package]] +name = "h11" +version = "0.16.0" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "harbor" +version = "1.4.0" +source = { virtual = "." } +dependencies = [ + { name = "click" }, + { name = "harbor-api" }, + { name = "structlog" }, +] + +[package.dev-dependencies] +dev = [ + { name = "pytest" }, + { name = "pytest-timeout" }, +] +test = [ + { name = "pytest" }, +] + +[package.metadata] +requires-dist = [ + { name = "click", specifier = ">=8.1" }, + { name = "harbor-api", editable = "packages/api" }, + { name = "structlog", specifier = ">=24" }, +] + +[package.metadata.requires-dev] +dev = [ + { name = "pytest", specifier = ">=8" }, + { name = "pytest-timeout", specifier = ">=2" }, +] +test = [{ name = "pytest", specifier = ">=8" }] + +[[package]] +name = "harbor-api" +version = "0.3.0" +source = { editable = "packages/api" } +dependencies = [ + { name = "harbor-core" }, + { name = "httpx" }, +] + +[package.optional-dependencies] +cli = [ + { name = "rich" }, +] + +[package.metadata] +requires-dist = [ + { name = "harbor-core", editable = "packages/core" }, + { name = "httpx", specifier = ">=0.28,<1" }, + { name = "rich", marker = "extra == 'cli'", specifier = ">=13" }, +] +provides-extras = ["cli"] + +[[package]] +name = "harbor-core" +version = "0.3.0" +source = { editable = "packages/core" } +dependencies = [ + { name = "attrs" }, + { name = "pydantic" }, +] + +[package.metadata] +requires-dist = [ + { name = "attrs", specifier = ">=24" }, + { name = "pydantic", specifier = ">=2.8" }, +] + +[[package]] +name = "httpcore" +version = "1.0.9" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "certifi" }, + { name = "h11" }, +] + +[[package]] +name = "httpx" +version = "0.28.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "anyio" }, + { name = "certifi" }, + { name = "httpcore" }, + { name = "idna" }, +] + +[[package]] +name = "idna" +version = "3.20" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "iniconfig" +version = "2.3.1" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "markdown-it-py" +version = "4.2.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "mdurl" }, +] + +[[package]] +name = "mdurl" +version = "0.1.2" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "packaging" +version = "26.3" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "pluggy" +version = "1.7.0" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "pydantic" +version = "2.14.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "annotated-types" }, + { name = "pydantic-core" }, + { name = "typing-extensions" }, + { name = "typing-inspection" }, +] + +[[package]] +name = "pydantic-core" +version = "2.50.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions" }, +] + +[[package]] +name = "pygments" +version = "2.21.0" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "pytest" +version = "9.2.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "colorama", marker = "sys_platform == 'win32'" }, + { name = "exceptiongroup", marker = "python_full_version < '3.11'" }, + { name = "iniconfig" }, + { name = "packaging" }, + { name = "pluggy" }, + { name = "pygments" }, + { name = "tomli", marker = "python_full_version < '3.11'" }, +] + +[[package]] +name = "pytest-timeout" +version = "2.4.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "pytest" }, +] + +[[package]] +name = "rich" +version = "15.0.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "markdown-it-py" }, + { name = "pygments" }, +] + +[[package]] +name = "structlog" +version = "26.1.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions", marker = "python_full_version < '3.11'" }, +] + +[[package]] +name = "tomli" +version = "2.5.0" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "typing-extensions" +version = "4.16.0" +source = { registry = "https://pypi.org/simple" } + +[[package]] +name = "typing-inspection" +version = "0.4.4" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions" }, +] diff --git a/packages/renderers/graph/scenarios.json b/packages/renderers/graph/scenarios.json index e35ad12b8..6d943a8eb 100644 --- a/packages/renderers/graph/scenarios.json +++ b/packages/renderers/graph/scenarios.json @@ -1718,6 +1718,14 @@ "before": "fixtures/nuget-library-before.json", "after": "fixtures/nuget-library-after.json" }, + { + "id": "python-uv-workspace", + "title": "Python uv workspace: a year of releases", + "description": "Three projects in a uv workspace, read from uv.lock a year apart. Most packages move up a version, each one modified package; the core adopts pydantic, which brings its own packages, the API drops httpx's HTTP/2 extra, so h2 and its packages leave, newer anyio no longer needs sniffio, and the root swaps tomli for structlog, while pytest still pulls tomli in.", + "renderer": "dependencies", + "before": "fixtures/python-workspace-2025.json", + "after": "fixtures/python-workspace-2026.json" + }, { "id": "module-graph-layered", "title": "A layered module graph", diff --git a/packages/renderers/graph/test/dependencies.test.mjs b/packages/renderers/graph/test/dependencies.test.mjs index da8f0f38c..126b5ce26 100644 --- a/packages/renderers/graph/test/dependencies.test.mjs +++ b/packages/renderers/graph/test/dependencies.test.mjs @@ -94,6 +94,7 @@ test('every change and the path that pulls it in stays visible; summaries change for (const [from, to] of [ ['npm-workspace-v2', 'npm-workspace-v3'], ['npm-workspace-v1', 'npm-workspace-v2'], + ['python-workspace-2025', 'python-workspace-2026'], ]) { const model = await compare(fixture(from), fixture(to)) const view = dependencyView(model, [], new Set()) @@ -310,10 +311,15 @@ test('while scrubbing a dependency graph, no visible relationship passes through const {transition} = await dependencyTransition(from, to) assert.deepEqual(crossings(transition, frames).slice(0, 8), [], `${from} to ${to}`) } - // A major upgrade rewires dozens of packages at once: routes may brush a card while - // cards make room or close gaps, but never at rest, at either endpoint or a step's hold. - const {schedule, transition} = await dependencyTransition('npm-workspace-v1', 'npm-workspace-v2') - assert.deepEqual(crossings(transition, [0, 1, ...stepEnds(schedule, 1)]).slice(0, 8), []) + // A major upgrade, or a year of releases, rewires dozens of packages at once: routes may brush + // a card while cards make room or close gaps, but never at rest, at either endpoint or a step's hold. + for (const [from, to] of [ + ['npm-workspace-v1', 'npm-workspace-v2'], + ['python-workspace-2025', 'python-workspace-2026'], + ]) { + const {schedule, transition} = await dependencyTransition(from, to) + assert.deepEqual(crossings(transition, [0, 1, ...stepEnds(schedule, 1)]).slice(0, 8), [], `${from} to ${to}`) + } }) test('primary paths: each package keeps the edge that pulls it in and every added or removed dependency; the rest are counted on its card', async () => { @@ -322,6 +328,7 @@ test('primary paths: each package keeps the edge that pulls it in and every adde ['npm-workspace-v2', 'npm-workspace-v3'], ['nuget-before', 'nuget-after'], ['nuget-library-before', 'nuget-library-after'], + ['python-workspace-2025', 'python-workspace-2026'], ]) { const model = await compare(fixture(beforeFixture), fixture(afterFixture)) const every = dependencyView(model, scheduleSteps(model), new Set(), 'all') From ba0f5e7e0dc5ced30b652a03ebf66db79975333d Mon Sep 17 00:00:00 2001 From: agorischek <6295280+agorischek@users.noreply.github.com> Date: Fri, 4 Dec 2026 22:22:46 +0000 Subject: [PATCH 5/7] python-dependencies: split PEP 440 ordering and package identities out 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> --- .../python-dependencies/src/graph.rs | 164 +----------------- .../python-dependencies/src/graph/identity.rs | 60 +++++++ .../extractors/python-dependencies/src/lib.rs | 1 + .../src/lockfile/requirements.rs | 2 +- .../python-dependencies/src/version.rs | 110 ++++++++++++ 5 files changed, 175 insertions(+), 162 deletions(-) create mode 100644 packages/extractors/python-dependencies/src/graph/identity.rs create mode 100644 packages/extractors/python-dependencies/src/version.rs diff --git a/packages/extractors/python-dependencies/src/graph.rs b/packages/extractors/python-dependencies/src/graph.rs index 126a5d8c8..9469043e0 100644 --- a/packages/extractors/python-dependencies/src/graph.rs +++ b/packages/extractors/python-dependencies/src/graph.rs @@ -5,9 +5,10 @@ use crate::model::{DEV, Declaration, Dependency, Locked, Lockfile, OPTIONAL}; use anyhow::{Result, bail}; use serde_json::{Value, json}; -use std::cmp::Ordering; use std::collections::{BTreeMap, BTreeSet}; +mod identity; + /// A project: the root, or a uv workspace member. pub(crate) struct Project { /// The normalized name; `None` for a project without one (requirements files alone, or a virtual workspace root). @@ -138,7 +139,7 @@ pub(crate) fn build(projects: &[Project], lockfile: Option<&Lockfile>) -> Result by_name, }; let reached = builder.reached(); - let package_ids = identities(&builder, &reached); + let package_ids = identity::identities(&builder, &reached); let target_id = |target: Target| match target { Target::Project(i) => project_ids[i].clone(), Target::Package(i) => package_ids[&i].clone(), @@ -342,162 +343,3 @@ fn project_identities(projects: &[Project]) -> Result<(Vec, Vec) } Ok((ids, owners)) } - -/// Stable IDs for the reached packages that leave the version out, so an -/// upgrade is one modified package: `package:`. When a name is locked at -/// several versions at once (uv forks the resolution by Python version or -/// platform), the copy most packages depend on keeps `package:` (the -/// lowest version of those tied), so the copy already there keeps its ID when -/// another version appears beside it, and each other copy is -/// `package:@` by compatible line, or by full version if two share one. -fn identities(builder: &Builder, reached: &BTreeMap>) -> BTreeMap { - let mut dependents: BTreeMap = BTreeMap::new(); - let declared = builder - .projects - .iter() - .flat_map(|p| &p.declarations) - .flat_map(|d| builder.resolve(&d.dependency, d.pinned)); - let transitive = reached - .iter() - .flat_map(|(index, extras)| builder.active(*index, extras).map(|(_, d)| d).collect::>()) - .flat_map(|d| builder.resolve(d, None)); - for target in declared.chain(transitive) { - if let Target::Package(index) = target { - *dependents.entry(index).or_default() += 1; - } - } - let packages = builder.packages; - let mut by_name: BTreeMap<&str, Vec> = BTreeMap::new(); - for index in reached.keys() { - by_name.entry(&packages[*index].name).or_default().push(*index); - } - let mut ids = BTreeMap::new(); - for (name, indexes) in by_name { - let count = |index: &usize| dependents.get(index).copied().unwrap_or(0); - let primary = indexes - .iter() - .copied() - .min_by(|a, b| { - count(b) - .cmp(&count(a)) - .then_with(|| compare_versions(&packages[*a].version, &packages[*b].version)) - }) - .expect("a name has a package"); - ids.insert(primary, format!("package:{name}")); - let lines: BTreeSet = indexes.iter().map(|i| compatible_line(&packages[*i].version)).collect(); - for index in indexes.iter().copied().filter(|index| *index != primary) { - let version = &packages[index].version; - let suffix = if lines.len() == indexes.len() { - compatible_line(version) - } else { - version.clone() - }; - ids.insert(index, format!("package:{name}@{suffix}")); - } - } - ids -} - -/// The release line versions are told apart by: the major version, or `0.` before 1.0. -fn compatible_line(version: &str) -> String { - let release = version.split(['+', '!']).next_back().unwrap_or(version); - let parts: Vec<&str> = release - .split('.') - .map(|part| part.trim_end_matches(|c: char| !c.is_ascii_digit())) - .collect(); - match parts.as_slice() { - ["0", minor, ..] => format!("0.{minor}"), - [major, ..] if !major.is_empty() => (*major).to_owned(), - _ => version.to_owned(), - } -} - -/// A PEP 440 version's ordering key: epoch, release, then development releases -/// before pre-releases (`a`, `b`, `rc`) before the release before its post-releases. -fn version_key(version: &str) -> Option<(u64, Vec, (u8, u8, u64), Option, (bool, u64))> { - let version = version.trim().to_ascii_lowercase(); - let version = version.split('+').next().unwrap_or_default(); - let (epoch, version) = match version.split_once('!') { - Some((epoch, rest)) => (epoch.parse().ok()?, rest), - None => (0, version), - }; - let end = version.find(|c: char| !(c.is_ascii_digit() || c == '.')).unwrap_or(version.len()); - let mut release: Vec = version[..end] - .trim_end_matches('.') - .split('.') - .map(|part| part.parse().ok()) - .collect::>()?; - while release.len() > 1 && release.last() == Some(&0) { - release.pop(); - } - let rest = version[end..].trim_start_matches(['.', '-', '_']); - let number = |text: &str| text.trim_start_matches(['.', '-', '_']).parse::().unwrap_or(0); - let (mut pre, mut post, mut dev) = (None, None, None); - let mut remaining = rest; - while !remaining.is_empty() { - let letters = remaining - .find(|c: char| c.is_ascii_digit() || matches!(c, '.' | '-' | '_')) - .unwrap_or(remaining.len()); - let (word, tail) = remaining.split_at(letters); - let digits_end = tail - .trim_start_matches(['.', '-', '_']) - .find(|c: char| !c.is_ascii_digit()) - .map_or(tail.len(), |i| i + tail.len() - tail.trim_start_matches(['.', '-', '_']).len()); - let value = number(&tail[..digits_end]); - match word { - "a" | "alpha" => pre = Some((0, value)), - "b" | "beta" => pre = Some((1, value)), - "rc" | "c" | "pre" | "preview" => pre = Some((2, value)), - "post" | "rev" | "r" | "" => post = Some(value), - "dev" => dev = Some(value), - _ => return None, - } - remaining = tail[digits_end..].trim_start_matches(['.', '-', '_']); - } - let phase = match (pre, post, dev) { - (None, None, Some(_)) => (0, 0, 0), - (Some((rank, n)), _, _) => (1, rank, n), - _ => (2, 0, 0), - }; - Some((epoch, release, phase, post, (dev.is_none(), dev.unwrap_or(0)))) -} - -/// Two versions in PEP 440 order; versions that aren't PEP 440, and ties, by text. -fn compare_versions(a: &str, b: &str) -> Ordering { - match (version_key(a), version_key(b)) { - (Some(left), Some(right)) => left.cmp(&right), - _ => Ordering::Equal, - } - .then_with(|| a.cmp(b)) -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn versions_follow_pep_440() { - for (lower, higher) in [ - ("1.0.dev1", "1.0a1"), - ("1.0a1", "1.0b2"), - ("1.0b2", "1.0rc1"), - ("1.0rc1", "1.0"), - ("1.0", "1.0.post1"), - ("1.0", "1.0.1"), - ("2.0", "10.0"), - ("1.0.post1.dev0", "1.0.post1"), - ("2024.10", "1!0.1"), - ] { - assert_eq!(compare_versions(lower, higher), Ordering::Less, "{lower} < {higher}"); - } - assert_eq!(version_key("1.0"), version_key("1.0.0")); - } - - #[test] - fn copies_are_told_apart_by_their_line() { - assert_eq!(compatible_line("2.1.3"), "2"); - assert_eq!(compatible_line("0.27.2"), "0.27"); - assert_eq!(compatible_line("2024.10.1"), "2024"); - assert_eq!(compatible_line("1!3.0"), "3"); - } -} diff --git a/packages/extractors/python-dependencies/src/graph/identity.rs b/packages/extractors/python-dependencies/src/graph/identity.rs new file mode 100644 index 000000000..706faff2a --- /dev/null +++ b/packages/extractors/python-dependencies/src/graph/identity.rs @@ -0,0 +1,60 @@ +//! Package identities that leave versions out, so an upgrade is one modified package. + +use super::{Builder, Target}; +use crate::version::{compare_versions, compatible_line}; +use std::collections::{BTreeMap, BTreeSet}; + +/// Stable IDs for the reached packages that leave the version out, so an +/// upgrade is one modified package: `package:`. When a name is locked at +/// several versions at once (uv forks the resolution by Python version or +/// platform), the copy most packages depend on keeps `package:` (the +/// lowest version of those tied), so the copy already there keeps its ID when +/// another version appears beside it, and each other copy is +/// `package:@` by compatible line, or by full version if two share one. +pub(super) fn identities(builder: &Builder, reached: &BTreeMap>) -> BTreeMap { + let mut dependents: BTreeMap = BTreeMap::new(); + let declared = builder + .projects + .iter() + .flat_map(|p| &p.declarations) + .flat_map(|d| builder.resolve(&d.dependency, d.pinned)); + let transitive = reached + .iter() + .flat_map(|(index, extras)| builder.active(*index, extras).map(|(_, d)| d).collect::>()) + .flat_map(|d| builder.resolve(d, None)); + for target in declared.chain(transitive) { + if let Target::Package(index) = target { + *dependents.entry(index).or_default() += 1; + } + } + let packages = builder.packages; + let mut by_name: BTreeMap<&str, Vec> = BTreeMap::new(); + for index in reached.keys() { + by_name.entry(&packages[*index].name).or_default().push(*index); + } + let mut ids = BTreeMap::new(); + for (name, indexes) in by_name { + let count = |index: &usize| dependents.get(index).copied().unwrap_or(0); + let primary = indexes + .iter() + .copied() + .min_by(|a, b| { + count(b) + .cmp(&count(a)) + .then_with(|| compare_versions(&packages[*a].version, &packages[*b].version)) + }) + .expect("a name has a package"); + ids.insert(primary, format!("package:{name}")); + let lines: BTreeSet = indexes.iter().map(|i| compatible_line(&packages[*i].version)).collect(); + for index in indexes.iter().copied().filter(|index| *index != primary) { + let version = &packages[index].version; + let suffix = if lines.len() == indexes.len() { + compatible_line(version) + } else { + version.clone() + }; + ids.insert(index, format!("package:{name}@{suffix}")); + } + } + ids +} diff --git a/packages/extractors/python-dependencies/src/lib.rs b/packages/extractors/python-dependencies/src/lib.rs index 186609950..de6c2c9f7 100644 --- a/packages/extractors/python-dependencies/src/lib.rs +++ b/packages/extractors/python-dependencies/src/lib.rs @@ -7,6 +7,7 @@ mod lockfile; mod model; mod pyproject; mod requirement; +mod version; use anyhow::{Result, bail}; use graph::Project; diff --git a/packages/extractors/python-dependencies/src/lockfile/requirements.rs b/packages/extractors/python-dependencies/src/lockfile/requirements.rs index 34dee1b23..7421973e5 100644 --- a/packages/extractors/python-dependencies/src/lockfile/requirements.rs +++ b/packages/extractors/python-dependencies/src/lockfile/requirements.rs @@ -121,7 +121,7 @@ fn lines(file: &str, text: &str) -> (Vec, Vec, Vec) { if items.starts_with("-r") || items.starts_with("--requirement") || items.contains('(') { pin.required = true; } else if !items.starts_with('-') { - pin.via.extend(items.split(',').map(|item| requirement::normalize(item))); + pin.via.extend(items.split(',').map(requirement::normalize)); } continue; } diff --git a/packages/extractors/python-dependencies/src/version.rs b/packages/extractors/python-dependencies/src/version.rs new file mode 100644 index 000000000..88525da0b --- /dev/null +++ b/packages/extractors/python-dependencies/src/version.rs @@ -0,0 +1,110 @@ +//! PEP 440 versions: their order, and the release line that tells copies of one package apart. + +use std::cmp::Ordering; + +/// The release line versions are told apart by: the major version, or `0.` before 1.0. +pub(crate) fn compatible_line(version: &str) -> String { + let release = version.split(['+', '!']).next_back().unwrap_or(version); + let parts: Vec<&str> = release + .split('.') + .map(|part| part.trim_end_matches(|c: char| !c.is_ascii_digit())) + .collect(); + match parts.as_slice() { + ["0", minor, ..] => format!("0.{minor}"), + [major, ..] if !major.is_empty() => (*major).to_owned(), + _ => version.to_owned(), + } +} + +/// What [`version_key`] orders versions by. +type Key = (u64, Vec, (u8, u8, u64), Option, (bool, u64)); + +/// A PEP 440 version's ordering key: epoch, release, then development releases +/// before pre-releases (`a`, `b`, `rc`) before the release before its post-releases. +fn version_key(version: &str) -> Option { + let version = version.trim().to_ascii_lowercase(); + let version = version.split('+').next().unwrap_or_default(); + let (epoch, version) = match version.split_once('!') { + Some((epoch, rest)) => (epoch.parse().ok()?, rest), + None => (0, version), + }; + let end = version.find(|c: char| !(c.is_ascii_digit() || c == '.')).unwrap_or(version.len()); + let mut release: Vec = version[..end] + .trim_end_matches('.') + .split('.') + .map(|part| part.parse().ok()) + .collect::>()?; + while release.len() > 1 && release.last() == Some(&0) { + release.pop(); + } + let rest = version[end..].trim_start_matches(['.', '-', '_']); + let number = |text: &str| text.trim_start_matches(['.', '-', '_']).parse::().unwrap_or(0); + let (mut pre, mut post, mut dev) = (None, None, None); + let mut remaining = rest; + while !remaining.is_empty() { + let letters = remaining + .find(|c: char| c.is_ascii_digit() || matches!(c, '.' | '-' | '_')) + .unwrap_or(remaining.len()); + let (word, tail) = remaining.split_at(letters); + let digits_end = tail + .trim_start_matches(['.', '-', '_']) + .find(|c: char| !c.is_ascii_digit()) + .map_or(tail.len(), |i| i + tail.len() - tail.trim_start_matches(['.', '-', '_']).len()); + let value = number(&tail[..digits_end]); + match word { + "a" | "alpha" => pre = Some((0, value)), + "b" | "beta" => pre = Some((1, value)), + "rc" | "c" | "pre" | "preview" => pre = Some((2, value)), + "post" | "rev" | "r" | "" => post = Some(value), + "dev" => dev = Some(value), + _ => return None, + } + remaining = tail[digits_end..].trim_start_matches(['.', '-', '_']); + } + let phase = match (pre, post, dev) { + (None, None, Some(_)) => (0, 0, 0), + (Some((rank, n)), _, _) => (1, rank, n), + _ => (2, 0, 0), + }; + Some((epoch, release, phase, post, (dev.is_none(), dev.unwrap_or(0)))) +} + +/// Two versions in PEP 440 order; versions that aren't PEP 440, and ties, by text. +pub(crate) fn compare_versions(a: &str, b: &str) -> Ordering { + match (version_key(a), version_key(b)) { + (Some(left), Some(right)) => left.cmp(&right), + _ => Ordering::Equal, + } + .then_with(|| a.cmp(b)) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn versions_follow_pep_440() { + for (lower, higher) in [ + ("1.0.dev1", "1.0a1"), + ("1.0a1", "1.0b2"), + ("1.0b2", "1.0rc1"), + ("1.0rc1", "1.0"), + ("1.0", "1.0.post1"), + ("1.0", "1.0.1"), + ("2.0", "10.0"), + ("1.0.post1.dev0", "1.0.post1"), + ("2024.10", "1!0.1"), + ] { + assert_eq!(compare_versions(lower, higher), Ordering::Less, "{lower} < {higher}"); + } + assert_eq!(version_key("1.0"), version_key("1.0.0")); + } + + #[test] + fn copies_are_told_apart_by_their_line() { + assert_eq!(compatible_line("2.1.3"), "2"); + assert_eq!(compatible_line("0.27.2"), "0.27"); + assert_eq!(compatible_line("2024.10.1"), "2024"); + assert_eq!(compatible_line("1!3.0"), "3"); + } +} From 0d9cd7d307ce1cf5f51ce1c5a95dd13eab19898f Mon Sep 17 00:00:00 2001 From: agorischek <6295280+agorischek@users.noreply.github.com> Date: Fri, 4 Dec 2026 22:44:50 +0000 Subject: [PATCH 6/7] python-dependencies: keep the fixtures out of dependency review and DollarLint'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> --- .dollarlint.toml | 5 +++++ packages/renderers/graph/fixtures/make-python.mjs | 10 ++++++++-- .../python-workspace/v1/{uv.lock => uv.lock.fixture} | 0 .../python-workspace/v2/{uv.lock => uv.lock.fixture} | 0 4 files changed, 13 insertions(+), 2 deletions(-) rename packages/renderers/graph/fixtures/python-workspace/v1/{uv.lock => uv.lock.fixture} (100%) rename packages/renderers/graph/fixtures/python-workspace/v2/{uv.lock => uv.lock.fixture} (100%) diff --git a/.dollarlint.toml b/.dollarlint.toml index 5ad204720..e6b88f608 100644 --- a/.dollarlint.toml +++ b/.dollarlint.toml @@ -22,6 +22,11 @@ exclude = [ "package-lock.json", "packages.lock.json", "pnpm-lock.yaml", + # Python projects as the python-dependencies extractor tests and the dependencies scenario read them. SchemaStore's + # catalog points pyproject.toml at a schema on raw.githubusercontent.com, outside the allowed domains below; uv, + # Poetry and PDM validate these when they lock the fixtures. + "packages/extractors/python-dependencies/tests/fixtures/**/pyproject.toml", + "packages/renderers/graph/fixtures/python-workspace/**/pyproject.toml", # Kubernetes manifests (Tetragon TracingPolicies, their CRDs, workloads, Helm values and kernel profiles) as the # tetragon-policies extractor and its docs examples read them. Kubernetes schemas are per kind and per cluster # version, and none is published for a mixed manifest; the extractor validates the policies against the CRDs. diff --git a/packages/renderers/graph/fixtures/make-python.mjs b/packages/renderers/graph/fixtures/make-python.mjs index f2818605d..e87e7e16b 100644 --- a/packages/renderers/graph/fixtures/make-python.mjs +++ b/packages/renderers/graph/fixtures/make-python.mjs @@ -10,8 +10,12 @@ // Without a path the debug CLI is built with Cargo. `--lock` first relocks both revisions with uv against the index // (default https://pypi.org/simple), naming https://pypi.org/simple as their registry and dropping the sdist and wheel // entries, which the extractor doesn't read. +// +// Each lockfile is kept as `uv.lock.fixture` and copied in as `uv.lock`: GitHub's dependency graph reads every `uv.lock`, +// and v1 deliberately locks year-old releases with since-published advisories, which would fail dependency review and +// raise Dependabot alerts for packages nothing installs. import {execFileSync} from 'node:child_process' -import {cpSync, mkdtempSync, readFileSync, rmSync, writeFileSync} from 'node:fs' +import {cpSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync} from 'node:fs' import {tmpdir} from 'node:os' import path from 'node:path' import {fileURLToPath} from 'node:url' @@ -32,7 +36,8 @@ if (lock >= 0) { .replaceAll(`registry = "${index}"`, 'registry = "https://pypi.org/simple"') .replace(/^sdist = .*\n/gmu, '') .replace(/^wheels = \[\n(?: {4}.*\n)*\]\n/gmu, '') - writeFileSync(file, text) + writeFileSync(`${file}.fixture`, text) + rmSync(file) } } let cli = args[0] && path.resolve(args[0]) @@ -54,6 +59,7 @@ try { cpSync(path.join(here, 'python-workspace', revision), repository, { recursive: true, }) + renameSync(path.join(repository, 'uv.lock.fixture'), path.join(repository, 'uv.lock')) git('add', '-A') git('commit', '-qm', revision) } diff --git a/packages/renderers/graph/fixtures/python-workspace/v1/uv.lock b/packages/renderers/graph/fixtures/python-workspace/v1/uv.lock.fixture similarity index 100% rename from packages/renderers/graph/fixtures/python-workspace/v1/uv.lock rename to packages/renderers/graph/fixtures/python-workspace/v1/uv.lock.fixture diff --git a/packages/renderers/graph/fixtures/python-workspace/v2/uv.lock b/packages/renderers/graph/fixtures/python-workspace/v2/uv.lock.fixture similarity index 100% rename from packages/renderers/graph/fixtures/python-workspace/v2/uv.lock rename to packages/renderers/graph/fixtures/python-workspace/v2/uv.lock.fixture From 589902058a69fba4b94c75003a4eab3a9db066eb Mon Sep 17 00:00:00 2001 From: agorischek <6295280+agorischek@users.noreply.github.com> Date: Fri, 4 Dec 2026 22:59:04 +0000 Subject: [PATCH 7/7] python-dependencies: address review: copies, conditions, Git commits 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> --- .../extractors/python-dependencies/README.md | 11 +- .../python-dependencies/src/graph.rs | 52 ++++-- .../python-dependencies/src/lockfile/pdm.rs | 9 +- .../src/lockfile/poetry.rs | 11 +- .../src/lockfile/requirements.rs | 114 ++++++++++--- .../python-dependencies/src/lockfile/uv.rs | 35 ++-- .../python-dependencies/src/model.rs | 3 + .../python-dependencies/src/pyproject.rs | 24 ++- .../python-dependencies/tests/lockfiles.rs | 152 ++++++++++++++++++ 9 files changed, 346 insertions(+), 65 deletions(-) diff --git a/packages/extractors/python-dependencies/README.md b/packages/extractors/python-dependencies/README.md index ebca89c4a..97afe39d3 100644 --- a/packages/extractors/python-dependencies/README.md +++ b/packages/extractors/python-dependencies/README.md @@ -91,7 +91,8 @@ Each lockfile is parsed, not resolved by running the manager: package and a direct dependency of the root project, with its extras and marker; `-r` includes are read too, each file once. Requirements files record no graph, except where `pip-compile` or `uv pip compile` annotated each pin - with what pulls it in (`# via httpx`): there a pin the annotation says another + with what pulls it in (`# via httpx`, below the pin or, with + `--annotation-style=line`, after it): there a pin the annotation says another pin pulls in is that pin's dependency, and only pins an input requires (`# via -r requirements.in`, `# via app (pyproject.toml)`) or nothing annotates are direct. Lines that don't pin one version (ranges, URLs, VCS @@ -120,7 +121,7 @@ or unsupported lockfile is an error. | Project | `project:` | `project` | `path`, `version` from its manifest | | Project without a name (the root) | `project-root` | `project` | as above; labelled `(project root)` | | Workspace member without a name | `project:./` | `project` | as above; labelled with its path | -| Package | `package:`; when several versions are locked at once, the copy most packages depend on keeps it (the lowest version of those tied) and each other copy is `package:@` (major version, or `0.`), or the full version if two share a line | `package` | `version`, and `source` (the registry URL, `git+`, or a local path) | +| Package | `package:`; when several versions are locked at once, the copy most packages depend on keeps it (the lowest version of those tied) and each other copy is `package:@` (major version, or `0.`), or the full version if two share a line | `package` | `version`, and `source` (the registry URL, `git+` with the locked commit, or a local path) | Names are normalized as installers compare them (PEP 503: lowercase, runs of `-`, `_` and `.` as one `-`), so `Typing_Extensions` and `typing-extensions` are @@ -134,8 +135,10 @@ dependencies are `dependencies` relationships, and those its activated extras add are `optionalDependencies`, with ID `dependency:["","",("",)""]` and the lockfile as evidence. Where one ID would name several relationships (a dependency on every -copy of a name, or one name listed twice for different environments), the one to -the copy with the plain ID keeps it and the others add their target's ID. +copy of a name, or one name listed twice for different environments), identical +ones are one, the one to the copy with the plain ID keeps it, the others add +their target's ID, and those to one target under different conditions add their +marker too. | `data` field | Meaning | diff --git a/packages/extractors/python-dependencies/src/graph.rs b/packages/extractors/python-dependencies/src/graph.rs index 9469043e0..506847a1c 100644 --- a/packages/extractors/python-dependencies/src/graph.rs +++ b/packages/extractors/python-dependencies/src/graph.rs @@ -46,7 +46,7 @@ struct Builder<'a> { impl Builder<'_> { /// What a dependency points at: the pinned package, a project of that name, - /// the locked copy of the version it names, else every locked copy of the name. + /// the locked copy of the version (and source) it names, else every locked copy of the name. fn resolve(&self, dependency: &Dependency, pinned: Option) -> Vec { if let Some(index) = pinned { return vec![Target::Package(index)]; @@ -60,6 +60,7 @@ impl Builder<'_> { let exact: Vec = copies .iter() .filter(|i| Some(&self.packages[**i].version) == dependency.version.as_ref()) + .filter(|i| dependency.source.is_none() || self.packages[**i].source == dependency.source) .map(|i| Target::Package(*i)) .collect(); if exact.is_empty() { @@ -272,21 +273,9 @@ pub(crate) fn build(projects: &[Project], lockfile: Option<&Lockfile>) -> Result } } } - // Of relationships sharing an ID, the one to the copy with the plain ID keeps it and the others add their target, so - // IDs don't depend on the order the lockfile lists copies in. let mut relationships = BTreeMap::new(); - for (id, mut group) in grouped { - group.sort_by(|(_, a), (_, b)| { - let to = |r: &Value| r["to"].as_str().unwrap_or_default().to_owned(); - (to(a).len(), to(a)).cmp(&(to(b).len(), to(b))) - }); - for (position, (mut parts, mut relationship)) in group.into_iter().enumerate() { - let id = if position == 0 { - id.clone() - } else { - parts.push(relationship["to"].as_str().unwrap_or_default().to_owned()); - format!("dependency:{}", json!(parts)) - }; + for (id, group) in grouped { + for (id, mut relationship) in distinct(id, group) { relationship["id"] = json!(id); relationships.insert(id, relationship); } @@ -298,6 +287,39 @@ pub(crate) fn build(projects: &[Project], lockfile: Option<&Lockfile>) -> Result }) } +/// IDs for relationships whose declarations give them one `id`: one to several copies of a package, or one declared +/// several times for different environments. Identical ones are one. The one to the copy with the plain ID keeps `id`; +/// the others add their target, and those to one target under different conditions add their marker (else their data), +/// so IDs depend neither on the order the lockfile lists copies in nor on one condition overwriting another. +fn distinct(id: String, mut group: Vec<(Vec, Value)>) -> Vec<(String, Value)> { + let to = |r: &Value| r["to"].as_str().unwrap_or_default().to_owned(); + let variant = |r: &Value| r["data"]["marker"].as_str().map_or_else(|| r["data"].to_string(), str::to_owned); + let key = |r: &Value| (to(r).len(), to(r), variant(r), r.to_string()); + group.sort_by_key(|(_, r)| key(r)); + group.dedup_by(|(_, a), (_, b)| a == b); + let mut used = BTreeSet::new(); + let mut ids = vec![]; + for (position, (mut parts, relationship)) in group.into_iter().enumerate() { + let mut id = id.clone(); + if position > 0 { + parts.push(to(&relationship)); + id = format!("dependency:{}", json!(parts)); + } + if used.contains(&id) { + parts.push(variant(&relationship)); + id = format!("dependency:{}", json!(parts)); + } + let mut copy = 2; + while used.contains(&id) { + id = format!("dependency:{}", json!([&parts[..], &[copy.to_string()]].concat())); + copy += 1; + } + used.insert(id.clone()); + ids.push((id, relationship)); + } + ids +} + /// A relationship's data: its kind, the requested specifier, the extras it requests and its marker. fn data(kind: &str, dependency: &Dependency) -> Value { let mut data = json!({"type":kind}); diff --git a/packages/extractors/python-dependencies/src/lockfile/pdm.rs b/packages/extractors/python-dependencies/src/lockfile/pdm.rs index e80c3b255..66b8fc291 100644 --- a/packages/extractors/python-dependencies/src/lockfile/pdm.rs +++ b/packages/extractors/python-dependencies/src/lockfile/pdm.rs @@ -39,6 +39,7 @@ pub(crate) fn parse(path: &str, text: &str) -> Result { specifier: r.specifier.or(r.url), extras: r.extras, marker: r.marker, + source: None, }) .collect(); let extras = super::strings(&package["extras"]); @@ -75,11 +76,15 @@ pub(crate) fn parse(path: &str, text: &str) -> Result { Ok(lockfile) } -/// Where a package comes from, when not a registry: `git+`, a URL, or `path `. +/// Where a package comes from, when not a registry: `git+@`, a URL, or `path `. The locked commit is +/// part of it, so moving a Git dependency to another commit is a change. fn source(package: &Value) -> Option { let text = |key: &str| package[key].as_str(); text("git") - .map(|url| format!("git+{url}")) + .map(|url| match text("revision") { + Some(revision) => format!("git+{url}@{revision}"), + None => format!("git+{url}"), + }) .or_else(|| text("url").map(str::to_owned)) .or_else(|| text("path").map(|path| format!("path {path}"))) } diff --git a/packages/extractors/python-dependencies/src/lockfile/poetry.rs b/packages/extractors/python-dependencies/src/lockfile/poetry.rs index 7fbb89d1e..ca443813b 100644 --- a/packages/extractors/python-dependencies/src/lockfile/poetry.rs +++ b/packages/extractors/python-dependencies/src/lockfile/poetry.rs @@ -51,6 +51,7 @@ pub(crate) fn parse(path: &str, text: &str) -> Result { specifier: named.specifier, extras: named.extras, marker: named.marker, + source: None, })); } extras.insert(normalize(extra), list); @@ -67,14 +68,16 @@ pub(crate) fn parse(path: &str, text: &str) -> Result { Ok(lockfile) } -/// `[package.source]`: `git+` for Git, ` ` for a local +/// `[package.source]`: `git+@` for Git, with the commit Poetry +/// locked so moving to another is a change, ` ` for a local /// directory or file, else the URL of a legacy repository or archive. fn source(source: &Value) -> Option { let kind = source["type"].as_str()?; let url = source["url"].as_str().unwrap_or_default(); - Some(match kind { - "git" => format!("git+{url}"), - "directory" | "file" => format!("{kind} {url}"), + Some(match (kind, source["resolved_reference"].as_str()) { + ("git", Some(commit)) => format!("git+{url}@{commit}"), + ("git", None) => format!("git+{url}"), + ("directory" | "file", _) => format!("{kind} {url}"), _ => url.to_owned(), }) } diff --git a/packages/extractors/python-dependencies/src/lockfile/requirements.rs b/packages/extractors/python-dependencies/src/lockfile/requirements.rs index 7421973e5..b22ad53e9 100644 --- a/packages/extractors/python-dependencies/src/lockfile/requirements.rs +++ b/packages/extractors/python-dependencies/src/lockfile/requirements.rs @@ -48,9 +48,12 @@ pub(crate) fn parse(files: &[String], read: &dyn Fn(&str) -> Result = BTreeMap::new(); + // Each pin's package, and every copy of a name this file pins: one name can be pinned at several versions under + // markers that exclude each other, and a `# via` annotation names only the name. + let mut at = Vec::with_capacity(pins.len()); + let mut here: BTreeMap<&str, Vec> = BTreeMap::new(); for pin in &pins { - let at = *index.entry((pin.name.clone(), pin.version.clone())).or_insert_with(|| { + let package = *index.entry((pin.name.clone(), pin.version.clone())).or_insert_with(|| { lockfile.packages.push(Locked { name: pin.name.clone(), label: pin.label.clone(), @@ -59,20 +62,25 @@ pub(crate) fn parse(files: &[String], read: &dyn Fn(&str) -> Result = pin.via.iter().filter_map(|name| here.get(name).copied()).collect(); + for (pin, package) in pins.iter().zip(at) { + let pulled_by: Vec = pin.via.iter().flat_map(|name| here.get(name.as_str())).flatten().copied().collect(); let dependency = Dependency { name: pin.name.clone(), version: Some(pin.version.clone()), specifier: Some(format!("=={}", pin.version)), extras: pin.extras.clone(), marker: pin.marker.clone(), + ..Dependency::default() }; for from in &pulled_by { let dependencies = &mut lockfile.packages[*from].dependencies; - if !dependencies.iter().any(|d| d.name == pin.name) { + if !dependencies.iter().any(|d| d.name == pin.name && d.version == dependency.version) { dependencies.push(dependency.clone()); } } @@ -82,7 +90,7 @@ pub(crate) fn parse(files: &[String], read: &dyn Fn(&str) -> Result (Vec, Vec, Vec) { if let Some(comment) = trimmed.strip_prefix('#') { let comment = comment.trim(); let Some(pin) = pins.last_mut() else { continue }; - let items = match comment.strip_prefix("via") { - Some(rest) if rest.is_empty() || rest.starts_with(' ') => { + let items = match via_items(comment) { + Some(items) => { via = true; - rest.trim() + items } - _ if via => comment, - _ => continue, + None if via => comment, + None => continue, }; - if items.is_empty() { - continue; - } - if items.starts_with("-r") || items.starts_with("--requirement") || items.contains('(') { - pin.required = true; - } else if !items.starts_with('-') { - pin.via.extend(items.split(',').map(requirement::normalize)); - } + annotate(pin, items); continue; } via = false; @@ -133,8 +134,11 @@ fn lines(file: &str, text: &str) -> (Vec, Vec, Vec) { } logical.push_str(trimmed); let line = std::mem::take(&mut logical); - // An inline comment starts with whitespace and `#`. - let line = line.split(" #").next().unwrap_or_default().trim(); + // An inline comment starts with whitespace and `#`; `pip-compile --annotation-style=line` writes `# via` there. + let (line, inline) = match line.split_once(" #") { + Some((line, comment)) => (line.trim(), Some(comment.trim())), + None => (line.trim(), None), + }; if line.is_empty() { continue; } @@ -170,7 +174,7 @@ fn lines(file: &str, text: &str) -> (Vec, Vec, Vec) { .next() .unwrap_or_default() .to_owned(); - pins.push(Pin { + let mut pin = Pin { name: r.name, label, version, @@ -179,7 +183,11 @@ fn lines(file: &str, text: &str) -> (Vec, Vec, Vec) { line: start, via: vec![], required: false, - }); + }; + if let Some(items) = inline.and_then(via_items) { + annotate(&mut pin, items); + } + pins.push(pin); } None => skipped.push(requirement_text.to_owned()), } @@ -187,6 +195,26 @@ fn lines(file: &str, text: &str) -> (Vec, Vec, Vec) { (pins, includes, skipped) } +/// What a `# via` comment names (`via httpx`, or `via` alone before one item per line), else `None`. +fn via_items(comment: &str) -> Option<&str> { + comment + .strip_prefix("via") + .filter(|rest| rest.is_empty() || rest.starts_with(' ')) + .map(str::trim) +} + +/// Adds what a `# via` annotation names to `pin`: the input files that require it, or the pins that pull it in. +fn annotate(pin: &mut Pin, items: &str) { + if items.is_empty() { + return; + } + if items.starts_with("-r") || items.starts_with("--requirement") || items.contains('(') { + pin.required = true; + } else if !items.starts_with('-') { + pin.via.extend(items.split(',').map(requirement::normalize)); + } +} + /// `include`, named relative to the file including it, as a repository path. fn relative(file: &str, include: &str) -> String { let directory = parent(file); @@ -268,6 +296,44 @@ mod tests { assert_eq!(dependencies("fastapi"), ["starlette"]); } + #[test] + fn inline_via_annotations_count_as_annotations() { + let lockfile = parse( + &["requirements.txt".into()], + &read(&[( + "requirements.txt", + "anyio==4.4.0 # via httpx\nhttpx==0.27.0 # via -r requirements.in\n", + )]), + ) + .unwrap(); + assert_eq!(direct(&lockfile), ["httpx 0.27.0"]); + let httpx = lockfile.packages.iter().find(|p| p.name == "httpx").unwrap(); + assert_eq!(httpx.dependencies.iter().map(|d| d.name.as_str()).collect::>(), ["anyio"]); + } + + #[test] + fn a_name_pinned_twice_under_exclusive_markers_keeps_both_copies() { + let lockfile = parse( + &["requirements.txt".into()], + &read(&[( + "requirements.txt", + "numpy==1.26.4 ; python_version < \"3.10\"\n # via -r requirements.in\nnumpy==2.1.0 ; python_version >= \"3.10\"\n # via -r requirements.in\nscipy==1.13.1\n # via numpy\n", + )]), + ) + .unwrap(); + assert_eq!(direct(&lockfile), ["numpy 1.26.4", "numpy 2.1.0"]); + let pinned: Vec<&str> = lockfile + .root + .iter() + .map(|d| lockfile.packages[d.pinned.unwrap()].version.as_str()) + .collect(); + assert_eq!(pinned, ["1.26.4", "2.1.0"]); + // A `# via` naming only the name means every copy pulls it in. + for numpy in lockfile.packages.iter().filter(|p| p.name == "numpy") { + assert_eq!(numpy.dependencies.iter().map(|d| d.name.as_str()).collect::>(), ["scipy"]); + } + } + #[test] fn includes_are_relative_to_the_including_file() { assert_eq!(relative("requirements/dev.txt", "base.txt"), "requirements/base.txt"); diff --git a/packages/extractors/python-dependencies/src/lockfile/uv.rs b/packages/extractors/python-dependencies/src/lockfile/uv.rs index a3babe99e..72dc0bbbd 100644 --- a/packages/extractors/python-dependencies/src/lockfile/uv.rs +++ b/packages/extractors/python-dependencies/src/lockfile/uv.rs @@ -46,14 +46,12 @@ pub(crate) fn parse(path: &str, text: &str) -> Result { }); }; for dependency in &dependencies { - let declared = requirement(&metadata["requires-dist"], &dependency.name, |marker| { - marker_extra(marker).is_none() - }); + let declared = requirement(&metadata["requires-dist"], dependency, |marker| marker_extra(marker).is_none()); declare(DEPENDENCIES, None, dependency.clone(), declared); } for (extra, list) in &extras { for dependency in list { - let declared = requirement(&metadata["requires-dist"], &dependency.name, |marker| { + let declared = requirement(&metadata["requires-dist"], dependency, |marker| { marker_extra(marker).as_ref() == Some(extra) }); declare(OPTIONAL, Some(extra), dependency.clone(), declared); @@ -61,7 +59,7 @@ pub(crate) fn parse(path: &str, text: &str) -> Result { } for (group, list) in groups(&package["dev-dependencies"], path)? { for dependency in list { - let declared = requirement(&metadata["requires-dev"][&group], &dependency.name, |_| true); + let declared = requirement(&metadata["requires-dev"][&group], &dependency, |_| true); declare(DEV, Some(&group), dependency, declared); } } @@ -135,6 +133,7 @@ fn dependency(item: &Value, path: &str) -> Result { .map(|extra| normalize(extra)) .collect(), marker: item["marker"].as_str().map(str::to_owned), + source: source(&item["source"]).0, }) } @@ -148,18 +147,30 @@ fn groups(table: &Value, path: &str) -> Result(list: &'a Value, name: &str, selects: impl Fn(&str) -> bool) -> Option<&'a Value> { +/// The declared requirement a locked dependency comes from, in a member's +/// `requires-dist` or a `requires-dev` group: of those for its name whose +/// marker `selects`, the one with its marker (a project can require one name +/// under several markers, each with its own specifier, and uv locks each as +/// its own dependency), else one whose marker includes it (`extra == 'cli' +/// and …`), else the first; else any for its name. +fn requirement<'a>(list: &'a Value, dependency: &Dependency, selects: impl Fn(&str) -> bool) -> Option<&'a Value> { + let marker = |item: &Value| item["marker"].as_str().unwrap_or_default().to_owned(); let named: Vec<&Value> = list .as_array() .into_iter() .flatten() - .filter(|item| item["name"].as_str().is_some_and(|n| normalize(n) == name)) + .filter(|item| item["name"].as_str().is_some_and(|n| normalize(n) == dependency.name)) .collect(); - named - .iter() - .find(|item| selects(item["marker"].as_str().unwrap_or_default())) + let selected: Vec<&Value> = named.iter().copied().filter(|item| selects(&marker(item))).collect(); + let locked = dependency.marker.as_deref(); + locked + .and_then(|locked| { + selected + .iter() + .find(|item| marker(item) == locked) + .or_else(|| selected.iter().find(|item| marker(item).contains(locked))) + }) + .or(selected.first()) .or(named.first()) .copied() } diff --git a/packages/extractors/python-dependencies/src/model.rs b/packages/extractors/python-dependencies/src/model.rs index 8d6a11ee7..fa85b9030 100644 --- a/packages/extractors/python-dependencies/src/model.rs +++ b/packages/extractors/python-dependencies/src/model.rs @@ -17,6 +17,9 @@ pub(crate) struct Dependency { pub extras: Vec, /// The environment marker, recorded but not evaluated. pub marker: Option, + /// The source of the locked copy it means, when the lockfile names one (uv, where one name and version can be + /// locked from several sources), in the form [`Locked::source`] takes. + pub source: Option, } /// One locked (or, for requirements files, pinned) package. diff --git a/packages/extractors/python-dependencies/src/pyproject.rs b/packages/extractors/python-dependencies/src/pyproject.rs index ac62b5f6d..9e95d83bb 100644 --- a/packages/extractors/python-dependencies/src/pyproject.rs +++ b/packages/extractors/python-dependencies/src/pyproject.rs @@ -146,12 +146,14 @@ impl Manifest { /// A PEP 735 group's requirements, with the groups it includes. fn group(&self, table: &serde_json::Map, group: &str, seen: &mut BTreeSet) -> Result> { - if !seen.insert(group.to_owned()) { + // Group names compare normalized, as package names do (PEP 735): `Test.Tools` includes `test_tools`. + if !seen.insert(normalize(group)) { bail!("{}: dependency group {group} includes itself", self.path); } let mut dependencies = vec![]; - let list = table - .get(group) + let (group, list) = table + .get_key_value(group) + .or_else(|| table.iter().find(|(name, _)| normalize(name) == normalize(group))) .with_context(|| format!("{}: no dependency group is named {group}", self.path))?; for item in list .as_array() @@ -169,7 +171,7 @@ impl Manifest { _ => bail!("{}: dependency-groups.{group} items must be strings or tables", self.path), } } - seen.remove(group); + seen.remove(&normalize(group)); Ok(dependencies) } @@ -213,6 +215,7 @@ fn dependency(text: &str) -> Option { specifier: requirement.specifier.or(requirement.url), extras: requirement.extras, marker: requirement.marker, + source: None, }) } @@ -286,6 +289,7 @@ pub(crate) fn poetry_dependency(name: &str, value: &Value) -> (Dependency, bool) specifier: Some(specifiers.join(" || ")).filter(|s| !s.is_empty()), extras: extras.into_iter().collect(), marker, + source: None, }; (dependency, optional) } @@ -388,6 +392,18 @@ black = "*" ); } + #[test] + fn groups_are_included_by_normalized_name() { + let m = manifest("[dependency-groups]\ntest_tools = [\"pytest\"]\ndev = [{include-group = \"Test.Tools\"}]\n"); + let declarations = m.declarations().unwrap(); + let dev: Vec<&str> = declarations + .iter() + .filter(|d| d.group.as_deref() == Some("dev")) + .map(|d| d.dependency.name.as_str()) + .collect(); + assert_eq!(dev, ["pytest"]); + } + #[test] fn a_group_that_includes_itself_is_an_error() { let m = manifest("[dependency-groups]\na = [{include-group = \"b\"}]\nb = [{include-group = \"a\"}]\n"); diff --git a/packages/extractors/python-dependencies/tests/lockfiles.rs b/packages/extractors/python-dependencies/tests/lockfiles.rs index bf5ce4209..1fe22d704 100644 --- a/packages/extractors/python-dependencies/tests/lockfiles.rs +++ b/packages/extractors/python-dependencies/tests/lockfiles.rs @@ -331,3 +331,155 @@ dependencies = [{ name = "numpy", version = "2.1.0", source = { registry = "http ); let _ = fs::remove_dir_all(&root); } + +#[test] +fn a_git_dependency_s_source_names_its_locked_commit() { + let poetry = scratch( + "poetry-git", + &[ + ( + "pyproject.toml", + "[tool.poetry]\nname = \"app\"\n[tool.poetry.dependencies]\npython = \"^3.10\"\nlib = { git = \"https://example.com/lib.git\", branch = \"main\" }\n", + ), + ( + "poetry.lock", + "[[package]]\nname = \"lib\"\nversion = \"1.0.0\"\n\n[package.source]\ntype = \"git\"\nurl = \"https://example.com/lib.git\"\nreference = \"main\"\nresolved_reference = \"0123abc\"\n\n[metadata]\nlock-version = \"2.1\"\n", + ), + ], + ); + let pdm = scratch( + "pdm-git", + &[ + ( + "pyproject.toml", + "[project]\nname = \"app\"\nversion = \"1.0.0\"\ndependencies = [\"lib @ git+https://example.com/lib.git@main\"]\n", + ), + ( + "pdm.lock", + "[metadata]\nlock_version = \"4.5.1\"\n\n[[package]]\nname = \"lib\"\nversion = \"1.0.0\"\ngit = \"https://example.com/lib.git\"\nref = \"main\"\nrevision = \"0123abc\"\n", + ), + ], + ); + for root in [poetry, pdm] { + let extraction = extract(&root, json!({})).unwrap(); + assert_eq!( + entity(&extraction, "package:lib")["data"]["source"], + "git+https://example.com/lib.git@0123abc", + "{}", + root.display() + ); + let _ = fs::remove_dir_all(&root); + } +} + +/// The relationships from `from` of `kind`, as `(id, to, data)`. +fn edges<'a>(extraction: &'a Value, from: &str, kind: &str) -> Vec<(&'a str, &'a str, &'a Value)> { + extraction["relationships"] + .as_array() + .unwrap() + .iter() + .filter(|e| e["from"] == from && e["kind"] == kind) + .map(|e| (e["id"].as_str().unwrap(), e["to"].as_str().unwrap(), &e["data"])) + .collect() +} + +#[test] +fn one_dependency_declared_for_several_environments_keeps_each_condition() { + let root = scratch( + "markers", + &[( + "pyproject.toml", + "[project]\nname = \"app\"\nversion = \"1.0.0\"\ndependencies = [\n \"lib>=1; sys_platform == 'linux'\",\n \"lib>=2; sys_platform == 'win32'\",\n \"lib>=3; sys_platform == 'darwin'\",\n \"lib>=3; sys_platform == 'darwin'\",\n]\n", + )], + ); + let extraction = extract(&root, json!({})).unwrap(); + let mut markers: Vec<&str> = edges(&extraction, "project:app", "dependencies") + .iter() + .map(|(_, _, data)| data["marker"].as_str().unwrap()) + .collect(); + markers.sort_unstable(); + assert_eq!( + markers, + ["sys_platform == 'darwin'", "sys_platform == 'linux'", "sys_platform == 'win32'"] + ); + let _ = fs::remove_dir_all(&root); +} + +#[test] +fn uv_dependencies_name_the_source_and_marker_of_the_copy_they_mean() { + let lock = r#"version = 1 +requires-python = ">=3.9" + +[[package]] +name = "app" +version = "1.0.0" +source = { virtual = "." } +dependencies = [ + { name = "lib", version = "1.0.0", source = { registry = "https://a.example/simple" }, marker = "sys_platform == 'linux'" }, + { name = "lib", version = "1.0.0", source = { registry = "https://b.example/simple" }, marker = "sys_platform != 'linux'" }, + { name = "numpy", version = "1.26.4", source = { registry = "https://a.example/simple" }, marker = "python_full_version < '3.10'" }, + { name = "numpy", version = "2.1.0", source = { registry = "https://a.example/simple" }, marker = "python_full_version >= '3.10'" }, +] + +[package.metadata] +requires-dist = [ + { name = "lib" }, + { name = "numpy", marker = "python_full_version < '3.10'", specifier = ">=1.24,<2" }, + { name = "numpy", marker = "python_full_version >= '3.10'", specifier = ">=2" }, +] + +[[package]] +name = "lib" +version = "1.0.0" +source = { registry = "https://a.example/simple" } +dependencies = [{ name = "only-a" }] + +[[package]] +name = "lib" +version = "1.0.0" +source = { registry = "https://b.example/simple" } + +[[package]] +name = "only-a" +version = "1.0.0" +source = { registry = "https://a.example/simple" } + +[[package]] +name = "numpy" +version = "1.26.4" +source = { registry = "https://a.example/simple" } + +[[package]] +name = "numpy" +version = "2.1.0" +source = { registry = "https://a.example/simple" } +"#; + let root = scratch( + "sources", + &[ + ("pyproject.toml", "[project]\nname = \"app\"\nversion = \"1.0.0\"\n"), + ("uv.lock", lock), + ], + ); + let extraction = extract(&root, json!({})).unwrap(); + let edges = edges(&extraction, "project:app", "dependencies"); + // Each platform's declaration points at the one copy from its source. + let lib: Vec<(&str, &str)> = edges + .iter() + .filter(|(_, to, _)| to.starts_with("package:lib")) + .map(|(_, to, data)| (*to, data["marker"].as_str().unwrap())) + .collect(); + assert_eq!(lib.len(), 2, "{lib:?}"); + assert_ne!(lib[0].0, lib[1].0); + // Each numpy copy keeps the specifier declared under its marker. + let numpy = |version: &str| { + edges + .iter() + .find(|(_, _, data)| data["resolved"] == version) + .map(|(_, _, data)| data["version"].as_str().unwrap()) + .unwrap() + }; + assert_eq!(numpy("1.26.4"), ">=1.24,<2"); + assert_eq!(numpy("2.1.0"), ">=2"); + let _ = fs::remove_dir_all(&root); +}