Skip to content

Latest commit

 

History

History
451 lines (388 loc) · 27.9 KB

dependency-sources.md

File metadata and controls

451 lines (388 loc) · 27.9 KB
Created 2026-09-04
Last-Modified 2026-11-17
SPDX-FileCopyrightText 2026-present Arthit Suriyawongkul
SPDX-FileType DOCUMENTATION
SPDX-License-Identifier CC0-1.0

Dependency sources and precedence

Note: Background reading -- useful for understanding what shows up in a generated Source SBOM's dependency list and why, not needed to just generate one.

Two kinds of dependency information

Every Source SBOM (loom project/loom generate) always includes your project's declared dependencies -- the version ranges listed in pyproject.toml's [project.dependencies] (or [tool.poetry.dependencies] for a Poetry project), e.g. requests>=2.0, and the project's own extras (see Extras and the optional edge). These are read directly and always present, with or without a lock file.

If a lock file is also present next to pyproject.toml, Pitloom additionally reads its exact resolved versions and adds any dependency they introduce that your declared list doesn't already name -- your project's transitive dependencies, pinned exactly (e.g. idna==3.7).

When a direct dependency is declared with a version range and a lock file is present, Pitloom uses the lock file's exact resolved version for the emitted SBOM package. For example, if pyproject.toml declares requests>=2.0 and your lock file resolved it to 2.31.0, the package's software_packageVersion and PyPI PURL become 2.31.0 (with enrichment fetching metadata for that exact release), while the original declared range is preserved in the element's declared_constraint provenance annotation. The same holds for a requirement of one of your own extras for uv.lock, poetry.lock and pdm.lock (see the table). Transitive dependencies revealed only by the lock file (e.g. idna==3.7) are added as new, additive entries.

A dependency is named by its PEP 503 name (Foo_Bar is foo-bar) on every route, loom env included; see How a dependency-version source is chosen.

Extras and the optional edge

Every route describing a project lists its own extras: a directory (loom project), an sdist, a wheel, the Hatchling build hook and the GitHub Action; loom env describes an environment, not a project, and lists none. The sources are [project.optional-dependencies], Poetry's [tool.poetry.extras] and setuptools' extras_require. Each requirement is tagged ; extra == "x", as a built wheel writes it, in the dependency's declared_constraint provenance. An extra's requirement on the project itself (demo[dev] in all) is replaced by the requirements of the extras it names, its marker joined to theirs; Hatchling drops that marker and setuptools and flit_core keep the requirement as declared, but the relationships come out the same. A cycle of such requirements is dropped where it closes, with a WARNING:. Pitloom keeps every such requirement as declared, with a WARNING:, when replacing them would read or copy more than 100,000 entries or nest more than 64 markers. PEP 735 [dependency-groups], Poetry's group.* and PDM's dev-dependencies are not listed: a wheel carries no equivalent.

Poetry's [tool.poetry.extras] is ignored, with a WARNING:, when [project] has a non-empty dependencies or optional-dependencies, as Poetry 2 does. A [project] list declared empty counts as absent there: Poetry then builds from [tool.poetry.dependencies] and [tool.poetry.extras]. A Poetry optional = true dependency that no extra lists is skipped with a WARNING:. [tool.poetry.dependencies] is ignored too, with a WARNING:, when [project] has an extra with a requirement, no dependencies and neither in dynamic, as poetry-core does.

Each Poetry dependency is read as poetry-core writes it: its version constraint (^1.0 is >=1.0,<2.0), extras (name[a,b]), a git or url source (name @ git+https://...@rev) and its markers, python and platform keys as one marker. Where two or more of those keys combine, poetry-core simplifies the joined marker and Pitloom keeps each term: the same environments match. A path dependency is skipped with a WARNING: (a local path is not portable).

[tool.poetry] fills what [project] leaves out only when the build-backend is Poetry's or none is declared; for another backend, one WARNING: names the [tool.poetry] keys not read, and only poetry.lock is used.

A setuptools project may list dependencies or optional-dependencies in [project] dynamic and name requirements files for them in [tool.setuptools.dynamic] (optional-dependencies.dev = {file = "requirements-dev.txt"}). A directory reads those files as setuptools does: comment and blank lines skipped, paths relative to the project directory. Each of these is skipped with a WARNING:: a file that is missing, unreadable, not UTF-8, over 1 MiB or outside the project directory; once the table's files reach 4 MiB in all, every file after; a pip option line such as -r or -e, or a line that is not valid PEP 508, both of which setuptools does not accept; and an attr directive. A file listed twice is read once, by any path that opens it (a hard link too); a path that cannot be opened as written is not found. setup.cfg's file: directive in install_requires and [options.extras_require] (dev = file: requirements-dev.txt, several files comma-separated) is read by the same rules, a one-line file split on ; as setuptools splits it. A dynamic field that [tool.setuptools.dynamic] has no key for takes setup.cfg's and setup.py's install_requires or extras_require, as setuptools does. A file read this way (requirements.txt included) declares dependencies: it is not also read as a pinned lock below.

Any other dynamic dependencies or optional-dependencies is computed by the build backend at build time (a PDM or Hatchling plugin, say). A directory read cannot know it: it lists no requirement from that field, without a message, and a wheel or sdist built from the project does carry it.

How a dependency is related to the project:

Where it is declared Relationship Lifecycle scope
[project].dependencies, any locked transitive dependency, or a bundled (phantom) library dependsOn (a LifecycleScopedRelationship) runtime
Only under one or more extras, locked or not hasOptionalDependency, comment extras: a, b (sorted) none
Both dependsOn, as above runtime

A lock does not make an extra's requirement dependsOn, even when another dependency needs it: Pitloom reads which packages a lock resolved, not which package needs which. A requirement that is not valid PEP 508 (one whose marker nests over 64 parentheses deep, or with a version number over 640 digits, counts as one), or whose marker's extra condition cannot be isolated (extra == "a" or python_version < "3.9"), is recorded as required, with a WARNING: (an extra's entry is skipped instead, with a WARNING:). One with an extra condition of its own inside an extra (foo; extra == 'x' in dev) is optional for both (extras: dev, x), its inner condition ignored with a WARNING:. For the same reason a package only the lock names (a transitive one) is dependsOn with scope runtime, even if only an extra's requirement needs it: the lock does not say.

A self-referencing extra (demo[dev] inside full) adds no package of its own: its requirements are listed with both extras (extras: dev, full). Hatchling expands it when it writes a wheel and other backends keep it, so every route gives the same packages and comments.

Naming your extras

Pitloom never infers a lifecycle scope from an extra's name: to a packaging tool, dev, lint and async are all just extras. Still, name an extra after the lifecycle stage it serves (dev, lint or docs for development, test or tests for testing) and keep feature names (full, async, postgres) for optional runtime features: an optional setting that maps an extra to a scope the project states is planned.

Supported lock formats, and what counts as "resolved"

Priority Format File What's included
1 (highest) PEP 751 pylock.toml Every resolved package the file records for its declared default-groups (a package needed only for a non-default dependency-group/extra, per its own marker field, is excluded). An own extra's requirement is pinned only when the exporter put its package in the file: uv export and pip lock write only the selected packages.
2 uv uv.lock Your project's own main/runtime dependencies, walked transitively (dependencies of dependencies, and so on), including any extra a real dependency requests on another package (e.g. uvicorn[standard] pulls in uvicorn's own standard extra). Your project's own extras (e.g. pip install yourpkg[dev]) add the exact pin of each requirement they list directly, not the extras' transitive closure; dev-dependencies groups are not included. A dependency pinned to more than one version for different Python versions is skipped, not guessed at, and nothing depending only on it is walked into either -- see below.
3 Poetry poetry.lock Packages in the main dependency group only (not [tool.poetry.group.*] groups), plus the pins of requirements your own [tool.poetry.extras] list directly.
4 PDM pdm.lock Packages in the default dependency group only, plus the pins of requirements your own extras list directly (needs static [project.optional-dependencies] keys).
5 Pipenv Pipfile.lock Packages in the default section only (not develop; no extras). A package whose resolved version isn't a single exact ==/=== pin is skipped, not guessed at.
6 (lowest) -- pinned requirements.txt Not a real lock file -- only used when every line in the file is already a single exact ==/=== pin (no extras). If even one line is unpinned, ranged, a pip option (-e, -r, --hash, ...), a URL-based requirement (even one that looks like it points at a tagged release), or one package name is pinned to two conflicting versions, the whole file is skipped, not just that line -- see below.

requirements.txt's entry is tagged Method: pinned_requirements in its provenance annotation (see "How to tell which source was used" below), not Method: resolved_lockfile like every format above it -- it's the one source here that isn't a real lock file, just a list of lines that happen to already be fully pinned.

A URL-based requirements.txt line is never treated as a version pin, even when the URL looks like it points at a tagged release (e.g. name @ https://github.com/org/repo/archive/refs/tags/v2.31.0.zip). A git tag or release filename is an arbitrary string with no guaranteed relationship to the package's real, normalised version -- Pitloom doesn't fetch the URL to check, so a line like that disqualifies the whole file the same as an unpinned or ranged one would.

Only the single highest-priority usable lock file present is used. If more than one lock file exists in the same project directory (uncommon, but possible after a build-tool migration), Pitloom picks the highest-ranked one in the table above that it can actually read and parse, and ignores every other one entirely -- it never merges two lock files' resolutions together. "Usable" matters: a higher-priority lock file that's absent, unparseable, or otherwise not a genuine file of its claimed format doesn't win by merely being present -- Pitloom moves on to the next-highest-priority source instead, the same as if that file weren't there at all. This holds even when the winning lock resolves to zero dependencies: a real, successfully-parsed lock file that legitimately has nothing to add is still a definitive answer, and a lower-priority lock present alongside it is still ignored, not used to fill in what looks like a gap.

A lock entry that can't be resolved to one exact version is left out, not guessed. uv.lock in particular can record the same package pinned to genuinely different versions for different Python versions in one file; Pitloom doesn't evaluate environment markers to pick one, so such a dependency is simply omitted from the additional (transitive) list rather than added with a possibly-wrong version. Check stderr for a WARNING: naming the skipped package (lock-entry-conflict, or lock-entry-malformed or lock-entry-unusable for an entry that cannot be read) if a dependency you expected is missing; see What Pitloom says about a lock file or a requirement.

Version comparison: PEP 440, not SemVer

Pitloom compares dependency versions using PEP 440 equality, not SemVer. "Same version" means the two version strings normalise to the identical release under PEP 440 -- trailing-zero components are padded and compared, so 1.0, 1.0.0, and 1.0.0.0 are all the same version. It does not mean "the latest release compatible with 1.0" or any other range/caret-style resolution: 1.0 and 1.0.1 are different versions under this comparison, exactly as they'd differ under strict string equality, even though a SemVer-style ^1.0.0 range would consider 1.0.1 compatible.

This comparison is what decides whether two version strings for the same package are treated as agreeing or genuinely conflicting. It shows up in two places:

  • A lock file's own duplicate entries. If one lock file records the same package name more than once (e.g. a platform-specific variant), entries that normalise to the same PEP 440 release are silently collapsed into one; entries that don't get a WARNING: (lock-entry-conflict) naming both versions, and that package is left out of the transitive list entirely rather than guessed at.
  • A declared range vs. the lock file's resolved version. When a direct dependency is unpinned or declared as a range, the lock file's resolved version is used (see above); when it's already pinned exactly (e.g. requests==2.31.0) and the lock file separately resolved it to a version that doesn't normalise the same way (e.g. 2.31.1), Pitloom logs a WARNING: but keeps the declared pin -- the lock's differing value never silently overrides an exact pin the project itself declared. Either direction, a genuine disagreement also adds a conflict Annotation (field: "dependency_version") to the generated SBOM, not just a stderr WARNING: -- see Metadata provenance.

A version with a number over 640 digits (1. followed by 5,000 nines; any run of digits counts, in a version, a specifier or a marker) is not read as a version: Python cannot convert such a number on every release and setting. A lock entry holding one is skipped with the lock's own WARNING: for an invalid version (lock-entry-malformed). A requirement holding one counts as not valid PEP 508 (above), with a WARNING: for the cap and the usual one for an invalid requirement (requirement-invalid; a Poetry dependency: its one skip line, which gives the reason); a whole requirements.txt with such a pin is ignored, with both lines. The project's own version or requires-python holding one fails the run with an ERROR:, as any invalid value does.

What Pitloom says about a lock file or a requirement

A lock file entry or a requirement Pitloom cannot use is said on stderr, in a line that ends with its [code]; the SBOM is still written. The clause after the last ; says what Pitloom did: skipped leaves the pin or requirement out; pin kept keeps the pin but does not follow what the line names; an extra-gate-* line records the requirement, as required or as optional. Each code, its causes and what to do about it are on Lock files and Dependencies. One line of each, with a value in place of each <name>:

Code A line of it
lock-entry-conflict WARNING: FILE=<file> PACKAGE=<package>: pinned to several versions; skipped, dropped <dropped> [lock-entry-conflict]
lock-entry-malformed WARNING: FILE=<file> PACKAGE=<package>: referenced but not in the lock's package table; skipped [lock-entry-malformed]
lock-entry-unusable WARNING: FILE=<file> PACKAGE=<package>: a <source-kind> source, not a registry version; skipped [lock-entry-unusable]
lock-file-conflict WARNING: two lock files hold resolved dependencies; kept <kept>, dropped <dropped> [lock-file-conflict]
lock-file-malformed WARNING: FILE=<file>: does not parse: <failure>; no pins read from it [lock-file-malformed]
lock-file-unusable WARNING: FILE=<file>: no entry for the project (no editable or virtual source); no pins read from it [lock-file-unusable]
lock-file-wrong-format WARNING: FILE=<file>: <lock-key> <lock-value> is a major version Pitloom does not read (it reads <number>); no pins read from it [lock-file-wrong-format]
requirement-invalid WARNING: dependency <dependency> (<declared-in>): optional and in no extra; skipped [requirement-invalid]
requirement-unusable WARNING: dependency <dependency> (<declared-in>): a local <source-kind> source, not portable; skipped [requirement-unusable]
extra-gate-unusable WARNING: PACKAGE=<package>: the extra marker of <dependency> cannot be isolated; recorded as required [extra-gate-unusable]
extra-gate-ambiguous WARNING: dependency <dependency>: needs extras <extra> together; recorded as optional for any of them [extra-gate-ambiguous]
dependency-name-ambiguous INFO: PACKAGE=<package>: a direct reference; not looked up on PyPI [dependency-name-ambiguous]

What Pitloom says about the project metadata it reads

Project metadata that Pitloom cannot read, or reads two ways, is said on stderr in a line that ends with its [code]. A WARNING: line means the SBOM is still written, with what Pitloom could read; the clause after the last ; says what it did (ignored, skipped, kept and dropped name the value it used). An ERROR: line means no SBOM. Each code, its causes and what to do about it are on Project metadata and Dependencies. One line of each, with a value in place of each <name>:

Code A line of it
metadata-invalid WARNING: FILE=<file>: [project] has no name; read setup.cfg and setup.py instead [metadata-invalid]
metadata-malformed WARNING: FILE=<file>: not valid Python; <failure> [metadata-malformed]
project-name-missing ERROR: FILE=<file>: neither [tool.poetry] nor [project] has a project name [project-name-missing]
metadata-conflict WARNING: DIR=<dir>: <field>: setup.py and setup.cfg disagree; kept setup.py's <kept>, dropped setup.cfg's <dropped> [metadata-conflict]
metadata-no-effect WARNING: FILE=<file>: [tool.poetry] <entries> not read: build-backend <backend> does not read them; ignored [metadata-no-effect]
dynamic-field-needs-build WARNING: FILE=<file>: dynamic <metadata_fields> not resolved without PKG-INFO; skipped [dynamic-field-needs-build]
dynamic-field-unusable WARNING: FILE=<file>: PDM dynamic version not resolved; <failure> [dynamic-field-unusable]
installed-metadata-unusable WARNING: DIR=<dir>: <entry> declares name <name>, not the project's; ignored [installed-metadata-unusable]
installed-metadata-ambiguous WARNING: DIR=<dir>: several installed-metadata candidates (<files>); used <entry> [installed-metadata-ambiguous]
dependency-pin-conflict WARNING: PACKAGE=<package>: lock and declared exact pin disagree; kept the declared <kept>, dropped the locked <dropped> [dependency-pin-conflict]

Which commands use lock files at all

Lock-file resolution only ever applies to a Source SBOM (loom project, loom generate, and the equivalent Python API call) -- describing your project as declared in source, before a build happens.

It's never consulted by:

  • loom wheel, loom embed-wheel, loom verify-wheel/validate-wheel -- a built wheel's own installed metadata is the ground truth for an Analyzed SBOM; a lock file (which describes what a future build might resolve to) is beside the point once a real wheel exists.
  • loom env -- describing what's actually installed in an environment is more authoritative than a lock file that may be stale relative to it.
  • The Hatchling build hook -- SBOMs it embeds during hatch build/pip install . describe the build artefact itself, the same "real build, not a lock's prediction" reasoning as loom wheel above.

So it's normal for loom project's SBOM to list more transitive dependencies than an SBOM embedded by the Hatchling build hook for the same project -- they're describing different things (a hypothetical resolution vs. what a real build actually installed), not a bug in either.

How to tell which source was used

Every transitive SBOM package introduced by a lock file carries a provenance annotation naming the file and method Pitloom used, e.g. Source: pylock.toml | Method: resolved_lockfile. Direct dependencies retain their declared source (e.g. Source: pyproject.toml), with Version resolved: Project lock file noting when a declared range was resolved to an exact version by the lock file. The cascade stops at the first usable source it tries, so it doesn't itself check whether a still-lower-priority lock file is also present on disk -- the one case it does detect and annotate is poetry.lock, since that one is resolved earlier, before the cascade runs, and the cascade can see its already-set result: if a higher-priority format then wins over it, the annotation adds a note, e.g. Source: pylock.toml | Method: resolved_lockfile | Note: supersedes poetry.lock. Two lock files that are both tried by the cascade itself (e.g. pdm.lock and Pipfile.lock both present) never produce this note -- only the single winning source's own annotation appears. See Metadata provenance for how to read these annotations in the generated SBOM.

Credentials in a URL

A URL a project declares (a direct dependency, a project URL, a dataset's download URL and the PURL built from it) may hold a user name or password, a query parameter named like a secret (token, key, signature, session_id) or an access token. An SBOM can be published, so Pitloom says so loudly; it never rewrites the URL. By default (the warn mode) the SBOM is written as it is, with one WARNING: line per value naming the value (masked), the element and field that hold it and a fingerprint, and the command exits 0:

WARNING: URL=foo @ https://***:***@example.org/foo-1.0.whl: holds a credential (<element> /statement/fields/declared_constraint/note, sha256:64a27d8a8c117f80); the SBOM states it as written; remove it from the source, or refuse such values with --refuse-url-credentials [credentials-unsafe/written]

With url-credentials = "refuse" in [tool.pitloom] or --refuse-url-credentials (recommended in CI), each value is one ERROR: line instead; a count line follows, the SBOM is refused (none is written) and the command exits 1.

ERROR: loom project: URL=foo @ https://***:***@example.org/foo-1.0.whl: holds a credential (<element> /statement/fields/declared_constraint/note, sha256:64a27d8a8c117f80); remove it from the source, or accept this value with --accept-url-credential sha256:64a27d8a8c117f80 [credentials-unsafe/refused]
ERROR: loom project: 1 URL value(s) in the SBOM hold credentials; the SBOM is refused [credentials-unsafe/refused]

Remove the credential from the source, and treat one that was in a project file as exposed. A value you know is no secret (an example URL) is accepted alone with --accept-url-credential and its fingerprint, or accept-url-credentials in [tool.pitloom]; the SBOM then states it as written, with a quieter WARNING:, in either mode.

A parameter named code, session, ticket, sid or otp, which holds a secret only sometimes, and a user name alone on an ssh or git URL (ssh://git@github.com/o/r) are only warned of, in either mode. The SBOM states them as written and says so once per value, masked: holds a code, session, ticket, sid, otp or other _key parameter or an ssh user name; the SBOM states it as written.

Only URL-typed fields and Pitloom's own provenance statements and comment lines (such as the direct reference a dependency is declared with) are read; a README, a description or a comment is prose and never read. What is found, the fields read, the other surfaces (library, build hook, Action, embed-wheel --sbom), the ID registry and what is not detected are in Credentials in URLs.

Pitloom's own log lines also mask a credential they print (https://***:***@host, ghp_***), whether or not the SBOM is refused, and so do the urllib3 and requests lines of a download (GET /x?token=***).

Configuration and flags

There is currently no setting to change the priority order above or choose a specific lock file -- which one wins is automatic, based purely on which lock file (if any) is present next to pyproject.toml.

To turn lock-file reading off entirely -- falling back to direct dependencies plus environment introspection only -- pass --no-use-lockfile on loom project, loom generate, or loom enrich (the last only together with --project-dir -- no project metadata is read at all on a bare loom enrich <model>, so the flag has no effect without it), or set [tool.pitloom] use-lockfile = false in pyproject.toml. On by default (an explicit CLI flag always wins over the config value); see Configuration.

loom enrich --project-dir DIR computes the fragment's target document identity from that same setting: pass --use-lockfile/--no-use-lockfile explicitly to match whatever produced the base SBOM, or omit it to auto-match DIR's own [tool.pitloom] use-lockfile config. A mismatch here silently produces a fragment referencing the wrong document identity.

--use-lockfile/--no-use-lockfile has no effect for an sdist archive target (loom project/loom generate on a .tar.gz/.zip): no lock/pin cascade support exists for archives yet, so a real lock file in the archive's own build environment was never read into it in the first place. An explicit flag passed for an archive target logs a WARNING: and is otherwise ignored.

--offline (also settable via [tool.pitloom] offline -- see Configuration) is unrelated to lock-file reading: it only controls whether Pitloom's own PyPI JSON API lookups (used to fill in a dependency package's originator, licence and hash gaps) are attempted. A lock file is always read from disk regardless of this setting -- there's no network involved in reading it. When a supported lock file contains SHA-256 digests, Pitloom uses them for verifiedUsing checksums across both online and offline builds, taking priority over PyPI JSON API lookups and eliminating the need for network access.

A direct reference (name @ URL: a Git repository, an archive, a local file: path) is never looked up on PyPI, online or offline: PyPI knows a package by name alone, and its project of that name may be a different package. Its package is listed with its declared constraint; its licence, supplier and hash come from its installed copy, if any, or stay unset. Pitloom says so once per such package, as an INFO: line (dependency-name-ambiguous), when it assembles dependencies online; an offline run, which looks nothing up, says nothing.

See also

  • Command line and Python API for how to run a Source SBOM generation that reads lock files this way.
  • Metadata provenance for the general provenance-annotation mechanism this page's "how to tell which source was used" section relies on.
  • Configuration for --offline and every other [tool.pitloom] setting.