Documentation
¶
Overview ¶
Package python provides dependency resolution for Python packages.
Overview ¶
This package implements deps.Language for Python, supporting:
- PyPI registry resolution via pypi client
- poetry.lock manifest parsing (full transitive closure)
- requirements.txt parsing (direct dependencies, resolved via PyPI)
Registry Resolution ¶
Use [Language.Resolver] to fetch dependencies from PyPI:
resolver, _ := python.Language.Resolver()
g, _ := resolver.Resolve(ctx, "fastapi", deps.Options{MaxDepth: 10})
Manifest Parsing ¶
Parse local manifest files:
parser, _ := python.Language.Manifest("poetry", nil)
result, _ := parser.Parse("poetry.lock", deps.Options{})
Supported manifests:
- poetry.lock: Full dependency graph with versions (IncludesTransitive: true)
- requirements.txt: Direct deps only, resolved via PyPI (IncludesTransitive: false)
Package Name Normalization ¶
Python package names are normalized following PEP 503: converted to lowercase with runs of [_.-] replaced by single hyphens.
pypi: github.com/stacktower-io/stacktower/pkg/integrations/pypi deps.Language: github.com/stacktower-io/stacktower/pkg/core/deps.Language
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Language = &deps.Language{ Name: "python", DefaultRegistry: "pypi", DefaultRuntimeVersion: pypi.DefaultPythonVersion, ManifestTypes: []string{"uv", "poetry", "pyproject", "requirements"}, ManifestAliases: map[string]string{ "uv.lock": "uv", "poetry.lock": "poetry", "pyproject.toml": "pyproject", "requirements.txt": "requirements", }, NewResolver: newResolver, NewManifest: newManifest, ManifestParsers: manifestParsers, NormalizeName: normalize, }
Language provides Python dependency resolution via PyPI. Supports uv.lock, poetry.lock, pyproject.toml, and requirements.txt manifest files.
Functions ¶
This section is empty.
Types ¶
type PEP440Matcher ¶
type PEP440Matcher struct{}
PEP440Matcher implements constraint matching for Python's PEP 440 version specifiers. It supports common operators: ==, !=, <, <=, >, >=, ~= Multiple constraints can be combined with commas (e.g., ">=1.0,<2.0").
func (PEP440Matcher) BestMatch ¶
func (PEP440Matcher) BestMatch(constraint string, candidates []string) string
BestMatch finds the highest version from candidates that satisfies the constraint. Returns empty string if no version matches or constraint is empty/invalid.
func (PEP440Matcher) ParseConstraint ¶
func (PEP440Matcher) ParseConstraint(constraint string) pubgrub.Condition
ParseConstraint converts a PEP 440 constraint to a PubGrub Condition. Returns nil if the constraint is empty or cannot be parsed. Version set bounds are built from pep440Version values so that range containment checks use the same Sort() logic as the candidate versions.
func (PEP440Matcher) ParseVersion ¶
func (PEP440Matcher) ParseVersion(version string) pubgrub.Version
ParseVersion converts a Python version string to a PubGrub Version. The original string is preserved so downstream fetches use the exact registry form.
type PoetryLock ¶
type PoetryLock struct{}
PoetryLock parses poetry.lock files. It provides a full transitive closure of the dependency graph without needing to contact a registry.
func (*PoetryLock) IncludesTransitive ¶
func (p *PoetryLock) IncludesTransitive() bool
func (*PoetryLock) Parse ¶
func (p *PoetryLock) Parse(path string, opts deps.Options) (*deps.ManifestResult, error)
func (*PoetryLock) Supports ¶
func (p *PoetryLock) Supports(name string) bool
func (*PoetryLock) Type ¶
func (p *PoetryLock) Type() string
type PyProject ¶
type PyProject struct {
// contains filtered or unexported fields
}
PyProject parses pyproject.toml files. By default, it only provides direct dependencies. If a deps.Resolver is provided, it can resolve the full transitive closure.
Extracts production dependencies only from: - PEP 621 [project.dependencies] - Poetry [tool.poetry.dependencies] - Flit [tool.flit.metadata.requires]
Skips dev/test/optional dependencies from: - [project.optional-dependencies] - [tool.poetry.dev-dependencies] - [tool.poetry.group.*] - [dependency-groups] (PEP 735) - [tool.uv.dev-dependencies] - [tool.flit.metadata.requires-extra]
func (*PyProject) IncludesTransitive ¶
type Requirements ¶
type Requirements struct {
// contains filtered or unexported fields
}
Requirements parses requirements.txt files. By default, it only provides direct dependencies. If a deps.Resolver is provided, it can resolve the full transitive closure.
func (*Requirements) IncludesTransitive ¶
func (r *Requirements) IncludesTransitive() bool
func (*Requirements) Parse ¶
func (r *Requirements) Parse(path string, opts deps.Options) (*deps.ManifestResult, error)
func (*Requirements) Supports ¶
func (r *Requirements) Supports(name string) bool
func (*Requirements) Type ¶
func (r *Requirements) Type() string
type UVLock ¶
type UVLock struct{}
UVLock parses uv.lock files. It provides a full transitive closure of the dependency graph without needing to contact a registry. uv.lock is the lockfile format used by uv (https://github.com/astral-sh/uv).