{"modulePath":"github.com/chainguard-dev/omnibump","version":"v0.23.7","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package python\n\nPackage python implements omnibump support for Python projects.\n\nIt supports both manifest mode (editing pyproject.toml, requirements.txt, setup.cfg, or Pipfile in-place) and venv mode (upgrading packages directly in a staged Python virtualenv).\n\n### Build tool detection {#hdr-Build_tool_detection}\n\nManifest mode auto-detects build tools from the \\[build-system].build-backend field in pyproject.toml and can be overridden with the --tool flag. Supported build tools:\n\n  - pip / uv — requirements.txt or PEP 621 pyproject.toml\n  - poetry — \\[tool.poetry.dependencies] in pyproject.toml\n  - hatch — PEP 621 \\[project].dependencies via hatchling backend\n  - pdm — PEP 621 \\[project].dependencies; detected by pdm.lock\n  - flit — PEP 621 \\[project].dependencies via flit\\_core backend\n  - setuptools — PEP 621 pyproject.toml, setup.cfg, or setup.py\n  - maturin — PEP 621 \\[project].dependencies for Rust+Python (PyO3) projects; used by polars, pydantic-core, orjson, ruff, and other performance-critical packages\n  - scikit-build-core — PEP 621 \\[project].dependencies for C/C++ extension modules\n\nAll PEP 621 backends (hatch, flit, pdm, maturin, scikit-build-core, setuptools) share the same parsing path since they use the standard \\[project].dependencies array. Only Poetry requires a separate parser for its \\[tool.poetry.dependencies] section.\n\n### Manifest files {#hdr-Manifest_files}\n\nSupported manifest file formats, checked in priority order: pyproject.toml, requirements.txt, setup.cfg, setup.py (read-only), Pipfile.\n\n### Lockfile handling {#hdr-Lockfile_handling}\n\nFor uv and pdm projects, omnibump updates pyproject.toml directly. The user must re-run \\`uv lock\\` or \\`pdm lock\\` afterwards to regenerate the lockfile from the updated constraints. Lockfile detection (uv.lock, pdm.lock) is used to identify the build tool, but lockfiles themselves are not modified.\n\n### Venv mode {#hdr-Venv_mode}\n\nVenv mode is designed for application/leaf packages that bundle dependencies in a staged virtualenv. It validates strict == pinning, rejects downgrades, and verifies environment consistency with pip check. It supports both uv pip and standard pip installers.\n\nBoth modes integrate with omnibump's language interface for unified dependency version bumping across multiple ecosystems.\n\nPackage python implements omnibump support for Python projects. Supports multiple build tools (pip, uv, hatch, poetry, pdm, maturin, scikit-build-core, setuptools) through a unified interface.\n\n## Constants\n\n```go\nconst (\n\t// LanguagePython is the language identifier for Python.\n\tLanguagePython = \"python\"\n\n\t// UVCommand is the uv package manager command.\n\tUVCommand = \"uv\"\n\t// PipCommand is the pip package manager command.\n\tPipCommand = \"pip\"\n\n\t// ManifestPyprojectTOML is the pyproject.toml manifest type.\n\tManifestPyprojectTOML = \"pyproject.toml\"\n\t// ManifestRequirementsTxt is the requirements.txt manifest type.\n\tManifestRequirementsTxt = \"requirements.txt\"\n\t// ManifestSetupCfg is the setup.cfg manifest type.\n\tManifestSetupCfg = \"setup.cfg\"\n\t// ManifestSetupPy is the setup.py manifest type.\n\tManifestSetupPy = \"setup.py\"\n\t// ManifestPipfile is the Pipfile manifest type.\n\tManifestPipfile = \"Pipfile\"\n\t// ManifestRequirementsPinnedTxt is a pinned variant of requirements.txt\n\t// used by some projects (e.g. in-toto).\n\tManifestRequirementsPinnedTxt = \"requirements-pinned.txt\"\n)\n```\nManifest file type constants.\n\n## Variables\n\n```go\nvar (\n\t// ErrManifestNotFound is returned when no Python manifest is found.\n\tErrManifestNotFound = errors.New(\"no Python manifest file found\")\n\n\t// ErrPackageNotFound is returned when the target package is not in the manifest.\n\tErrPackageNotFound = errors.New(\"package not found in manifest\")\n\n\t// ErrInvalidVersion is returned when a version string fails validation.\n\tErrInvalidVersion = errors.New(\"invalid version string\")\n\n\t// ErrVersionResolverUnavailable is returned when no registry can resolve a version.\n\tErrVersionResolverUnavailable = errors.New(\"version resolver unavailable\")\n\n\t// ErrUnsupportedManifestType is returned for unsupported manifest types.\n\tErrUnsupportedManifestType = errors.New(\"unsupported manifest type\")\n\n\t// ErrVenvDowngrade is returned when a version downgrade is attempted.\n\tErrVenvDowngrade = errors.New(\"downgrade rejected\")\n\n\t// ErrVenvEmptyVersion is returned when a version is empty.\n\tErrVenvEmptyVersion = errors.New(\"empty version for package\")\n\n\t// ErrVenvInvalidPackageName is returned when a package name is invalid (e.g., starts with '-').\n\tErrVenvInvalidPackageName = errors.New(\"invalid package name\")\n\n\t// ErrVenvInvalidVersionFormat is returned when a version format is invalid.\n\tErrVenvInvalidVersionFormat = errors.New(\"invalid version format\")\n\n\t// ErrPipInstallFailed is returned when pip install fails.\n\tErrPipInstallFailed = errors.New(\"pip install failed\")\n\n\t// ErrPipCheckFailed is returned when pip check fails.\n\tErrPipCheckFailed = errors.New(\"pip check failed\")\n\n\t// ErrSetupPyReadOnly is returned when attempting to modify setup.py.\n\tErrSetupPyReadOnly = errors.New(\"setup.py is read-only: omnibump cannot safely update setup.py; migrate to setup.cfg or pyproject.toml\")\n\n\t// ErrVersionNotFound is returned when no versions are found in registry.\n\tErrVersionNotFound = errors.New(\"no versions found in registry\")\n\n\t// ErrInvalidVersionResponse is returned when version response is invalid.\n\tErrInvalidVersionResponse = errors.New(\"invalid version in response\")\n\n\t// ErrHTTPNotFound is returned for 404 HTTP responses.\n\tErrHTTPNotFound = errors.New(\"not found\")\n\n\t// ErrUnexpectedHTTPStatus is returned for unexpected HTTP status codes.\n\tErrUnexpectedHTTPStatus = errors.New(\"unexpected HTTP status\")\n\n\t// ErrInvalidPath is returned when a manifest path is not absolute.\n\tErrInvalidPath = errors.New(\"invalid path\")\n\n\t// ErrInvalidPathAfterClean is returned when a path is still invalid after filepath.Clean.\n\tErrInvalidPathAfterClean = errors.New(\"invalid path after clean\")\n\n\t// ErrInvalidManifestFile is returned when the file is not a known manifest type.\n\tErrInvalidManifestFile = errors.New(\"invalid manifest file\")\n)\n```\n\n## Functions\n\n```go\nfunc HasPDMLock(dir string) bool\n```\nHasPDMLock returns true when a pdm.lock file exists in dir.\n\n```go\nfunc HasUVLock(dir string) bool\n```\nHasUVLock returns true when a uv.lock file exists in dir.\n\n```go\nfunc UpdatePipfile(path, packageName, newVersion string) error\n```\nUpdatePipfile updates the version of a named package in a Pipfile. The existing operator is preserved. newVersion is a bare version number.\n\n```go\nfunc UpdatePyprojectDep(path, packageName, newVersion string) error\n```\nUpdatePyprojectDep updates the version of a named dependency in pyproject.toml. It preserves comments and formatting by operating on the raw file text. newVersion should be just the version number (e.g. \"2.32.0\"), not include an operator. The existing operator is preserved.\n\n```go\nfunc UpdateRequirement(path, packageName, newVersion string) error\n```\nUpdateRequirement updates the version of the named package in a requirements.txt file. The existing version operator is preserved (==, \u003e=, ~=, etc.). newVersion is the bare version number without an operator.\n\n```go\nfunc UpdateSetupCfg(path, packageName, newVersion string) error\n```\nUpdateSetupCfg updates the version of a package in the install\\_requires section of a setup.cfg file. The existing operator is preserved.\n\n## Types\n\n```go\ntype Analyzer struct{}\n```\nAnalyzer implements analyzer.Analyzer for Python projects.\n\n```go\nfunc (a *Analyzer) Analyze(_ context.Context, projectPath string) (*analyzer.AnalysisResult, error)\n```\nAnalyze parses all manifest files in projectPath and returns a dependency map.\n\n```go\nfunc (a *Analyzer) AnalyzeRemote(_ context.Context, files map[string][]byte) (*analyzer.RemoteAnalysisResult, error)\n```\nAnalyzeRemote analyzes manifest files provided as raw bytes. files is a map of filename to content (e.g. \"pyproject.toml\" -\u003e bytes).\n\n```go\nfunc (a *Analyzer) RecommendStrategy(_ context.Context, _ *analyzer.AnalysisResult, deps []analyzer.Dependency) (*analyzer.Strategy, error)\n```\nRecommendStrategy always recommends direct updates for Python deps. Python doesn't have a \"property\" abstraction like Maven.\n\n```go\ntype BuildTool string\n```\nBuildTool identifies the Python build system in use.\n\n```go\nconst (\n\t// BuildToolPip indicates the pip build tool.\n\tBuildToolPip BuildTool = \"pip\"\n\t// BuildToolUV indicates the uv build tool.\n\tBuildToolUV BuildTool = \"uv\"\n\t// BuildToolHatch indicates the hatch build tool.\n\tBuildToolHatch BuildTool = \"hatch\"\n\t// BuildToolPoetry indicates the poetry build tool.\n\tBuildToolPoetry BuildTool = \"poetry\"\n\t// BuildToolPDM indicates the pdm build tool.\n\tBuildToolPDM BuildTool = \"pdm\"\n\t// BuildToolMaturin indicates the maturin build tool.\n\tBuildToolMaturin BuildTool = \"maturin\"\n\t// BuildToolSetuptools indicates the setuptools build tool.\n\tBuildToolSetuptools BuildTool = \"setuptools\"\n\t// BuildToolScikitBuild indicates the scikit-build tool.\n\tBuildToolScikitBuild BuildTool = \"scikit-build\"\n\t// BuildToolScikitBuildCore indicates the scikit-build-core tool.\n\tBuildToolScikitBuildCore BuildTool = \"scikit-build-core\"\n\t// BuildToolFlit indicates the flit build tool.\n\t// Flit uses PEP 621 [project].dependencies, same as hatch/setuptools.\n\tBuildToolFlit BuildTool = \"flit\"\n\t// BuildToolUnknown indicates an unknown build tool.\n\tBuildToolUnknown BuildTool = \"unknown\"\n)\n```\n\n```go\nfunc DetectBuildToolFromBytes(data []byte) (BuildTool, error)\n```\nDetectBuildToolFromBytes reads \\[build-system].build-backend from raw pyproject.toml bytes.\n\n```go\nfunc DetectBuildToolFromPyproject(path string) (BuildTool, error)\n```\nDetectBuildToolFromPyproject reads \\[build-system].build-backend from a pyproject.toml file on disk.\n\n```go\ntype ManifestInfo struct {\n\t// Path is the absolute path to the manifest file.\n\tPath string\n\t// Type is the manifest filename (e.g. \"pyproject.toml\", \"requirements.txt\").\n\tType string\n\t// BuildTool is the detected build backend.\n\tBuildTool BuildTool\n}\n```\nManifestInfo describes a detected Python manifest file.\n\n```go\nfunc DetectManifest(dir string) (*ManifestInfo, error)\n```\nDetectManifest returns the highest-priority manifest file found in dir. The returned ManifestInfo includes the build tool inferred from the file.\n\n```go\nfunc DetectManifestWithHint(dir, toolHint string) (*ManifestInfo, error)\n```\nDetectManifestWithHint returns a manifest file with optional tool preference. If toolHint is non-empty, it reorders the priority to check the preferred manifest for that tool first, then falls back to the standard order. toolHint examples: \"pip\" → requirements.txt, \"poetry\" → pyproject.toml, etc.\n\n```go\ntype Python struct{}\n```\nPython implements the Language interface for Python projects. It auto-detects the build tool and delegates updates to the appropriate handler.\n\n```go\nfunc (p *Python) Detect(_ context.Context, dir string) (bool, error)\n```\nDetect checks whether a Python manifest file exists in dir.\n\n```go\nfunc (p *Python) GetManifestFiles() []string\n```\nGetManifestFiles returns all Python manifest filenames omnibump can process.\n\n```go\nfunc (p *Python) Name() string\n```\nName returns the language identifier.\n\n```go\nfunc (p *Python) SupportsAnalysis() bool\n```\nSupportsAnalysis returns true since Python has full analysis capabilities.\n\n```go\nfunc (p *Python) Update(ctx context.Context, cfg *languages.UpdateConfig) error\n```\nUpdate performs dependency version updates on a Python project. For each dependency in cfg.Dependencies, it locates the highest-priority manifest and updates the version in-place. If Options\\[\"venv\"] is set, uses venv mode (uv/pip install into a staged venv). Otherwise uses manifest mode (edit pyproject.toml, requirements.txt, etc. in-place).\n\n```go\nfunc (p *Python) Validate(ctx context.Context, cfg *languages.UpdateConfig) error\n```\nValidate checks that each dependency was updated to the expected version. If Options\\[\"venv\"] is set, validates versions in the venv. Otherwise validates versions in the manifest file.\n\n```go\ntype VersionResolver struct {\n\t// contains filtered or unexported fields\n}\n```\nVersionResolver resolves Python package versions. It checks the Chainguard GAR-backed registry first, then falls back to PyPI.\n\n```go\nfunc NewVersionResolver() *VersionResolver\n```\nNewVersionResolver creates a VersionResolver from environment variables.\n\n```go\nfunc (r *VersionResolver) GetLatestVersion(ctx context.Context, pkg string) (string, error)\n```\nGetLatestVersion returns the latest available version of a Python package. Checks the Chainguard registry first; falls back to PyPI.\n\n```go\nfunc (r *VersionResolver) VersionExists(ctx context.Context, pkg, version string) (bool, error)\n```\nVersionExists checks whether a specific version of a package is available.\n\n```go\ntype VersionSpec struct {\n\t// Package is the normalized package name.\n\tPackage string\n\t// Specifier is the version operator(s), e.g. \"\u003e=\", \"==\", \"~=\", \"^\".\n\tSpecifier string\n\t// Version is the version string without the operator.\n\tVersion string\n\t// RawLine is the original unparsed line from the manifest.\n\tRawLine string\n}\n```\nVersionSpec represents a single parsed dependency entry.\n\n```go\nfunc ParsePipfile(data []byte) ([]VersionSpec, error)\n```\nParsePipfile parses \\[packages] and \\[dev-packages] from a Pipfile.\n\n```go\nfunc ParsePyprojectDeps(data []byte, buildTool BuildTool) ([]VersionSpec, error)\n```\nParsePyprojectDeps parses dependencies from pyproject.toml content. For Poetry projects, it reads \\[tool.poetry.dependencies]. For all others (PEP 621), it reads \\[project].dependencies plus \\[project.optional-dependencies] and \\[dependency-groups] (PEP 735). Optional and group dependencies are included in the result with their source annotated in RawLine for informational purposes.\n\n```go\nfunc ParseRequirements(data []byte) []VersionSpec\n```\nParseRequirements parses a requirements.txt byte slice and returns dependency specs. Comment lines, blank lines, and option flags (-r, -c, -e, -i, --index-url) are skipped.\n\n```go\nfunc ParseSetupCfg(data []byte) []VersionSpec\n```\nParseSetupCfg parses install\\_requires from a setup.cfg file.\n\n```go\nfunc ParseSetupPy(data []byte) []VersionSpec\n```\nParseSetupPy extracts install\\_requires entries from setup.py using regex. This handles the common pattern: install\\_requires=\\[\"pkg\u003e=1.0\", ...] or install\\_requires=\\[ ... ] across multiple lines.\n\n","path":"github.com/chainguard-dev/omnibump/pkg/languages/python","name":"python","synopsis":"Package python implements omnibump support for Python projects.","isRedistributable":true}
