meta_package_manager.specifier moduleΒΆ
Utilities to manage and resolve constraints from a set of package specifiers.
- meta_package_manager.specifier.VERSION_SEP: Final = '@'ΒΆ
Separator used by
mpmto split packageβs ID from its version:This has been chosen as a separator because it is shared by popular package managers (like
npm) and pURLs...code-block:
package_id@version
- meta_package_manager.specifier.PURL_MAP: dict[str, set[str] | None] = {'alpine': None, 'alpm': {'aura', 'dkp-pacman', 'pacaur', 'pacman', 'pamac', 'paru', 'pikaur', 'shelly', 'trizen', 'yay'}, 'android': None, 'apache': None, 'apk': {'apk'}, 'bitbucket': None, 'bitnami': None, 'bower': None, 'brew': {'brew', 'cask'}, 'buildroot': None, 'cargo': {'cargo'}, 'carthage': None, 'chef': None, 'chocolatey': {'choco'}, 'clojars': None, 'cocoapods': None, 'composer': {'composer'}, 'conan': None, 'conda': {'conda', 'mamba', 'micromamba', 'pixi'}, 'coreos': None, 'cpan': {'cpan'}, 'cran': {'cran'}, 'crystal': None, 'ctan': None, 'deb': {'apt', 'apt-mint', 'aptitude', 'nala'}, 'docker': None, 'drupal': None, 'dtype': None, 'dub': None, 'ebuild': {'emerge', 'pmerge'}, 'eclipse': None, 'elm': None, 'gem': {'gem'}, 'generic': None, 'gitea': None, 'github': None, 'gitlab': None, 'golang': {'go'}, 'gradle': None, 'guix': {'guix'}, 'hackage': None, 'haxe': {'haxelib'}, 'helm': None, 'hex': None, 'huggingface': None, 'julia': None, 'luarocks': {'luarocks'}, 'maven': None, 'melpa': {'emacs'}, 'meteor': None, 'mlflow': None, 'nim': {'nimble'}, 'nix': {'nix'}, 'npm': {'bun', 'npm', 'pnpm', 'volta', 'yarn', 'yarn-berry'}, 'nuget': {'dotnet'}, 'oci': None, 'opam': None, 'openwrt': {'opkg'}, 'osgi': None, 'p2': None, 'pear': {'pear'}, 'pecl': None, 'perl6': {'zef'}, 'platformio': None, 'pub': None, 'puppet': None, 'pypi': {'pip', 'pipx', 'pipxu', 'uv', 'uvx'}, 'qpkg': None, 'rpm': {'dnf', 'dnf5', 'microdnf', 'rpm-ostree', 'urpmi', 'yum', 'zypper'}, 'rubygems': {'gem'}, 'sourceforge': None, 'sublime': None, 'swid': None, 'terraform': None, 'vagrant': None, 'vim': None, 'vscode-extension': {'vscode', 'vscodium'}, 'wordpress': None, 'yocto': None}ΒΆ
Map pURL types to the IDs of the managers handling them.
The keys hold most registered types of
PURL_TYPES, and the candidate types of the older list of the purl-spec repository, likealpineornix, which a pURL can still carry. A key mapping toNonenames a type no manager handles.
- meta_package_manager.specifier.BREW_DEFAULT_TAPS: dict[str, str] = {'homebrew/cask': 'cask', 'homebrew/core': 'brew'}ΒΆ
The default taps of Homebrew, by the ID of the manager installing from each.
Their formulae and casks go by a bare name:
pkg:brew/homebrew/cask/firefoxnames thefirefoxcask. Thebrewtype of purl-spec covers both, and reads a pURL without a namespace as a formula ofhomebrew/core.
- class meta_package_manager.specifier.Specifier(raw_spec, package_id, manager_id=None, version=None)[source]ΒΆ
Bases:
objectLightweight representation of a package specification.
Contains all parsed metadata to be used as constraints.
- classmethod parse_purl(spec_str)[source]ΒΆ
Resolve a pURL into its corresponding manager candidates.
Yields
Specifierobjects or returnsNone.The package ID joins the namespace back to the name, as
purl_parts()split them:pkg:npm/%40angular/animationresolves to@angular/animation, not to the unrelatedanimationpackage. The types ofPURL_QUALIFYING_NAMESPACESkeep the name alone, sopkg:deb/debian/curlresolves tocurl.parse_purl()decodes the parts, and normalizes them by the rules of a registered type alone:pkg:npm/JSONStreamkeeps its case. A pURL breaking the rules of its type is read anyway, with a warning. A type that is also a manager ID gets no warning: the pURLsmpmwrites take the manager ID as the type, and some managers name a package in a way the registered type forbids, like a Perl module in apkg:cpan/pURL.
- classmethod from_string(spec_str)[source]ΒΆ
Parse a string into a package specifier.
Supports various formats: - plain
package_id- simple package ID with version:package_id@version- package with multiple version separators:@eslint/json@0.9.0- pURL:pkg:npm/left-pad@3.7If a specifier resolves to multiple constraints (as it might be the case for pURL), we produce and returns all variations. That way the
Solverbelow has all necessary details to resolve the constraints.Returns a tuple of
Specifier.
- property parsed_version: TokenizedString[source]ΒΆ
- exception meta_package_manager.specifier.EmptyReduction[source]ΒΆ
Bases:
ExceptionRaised by the solver if no constraint canβt be met.
- class meta_package_manager.specifier.Solver(spec_strings=None, manager_priority=None)[source]ΒΆ
Bases:
objectCombine a set of
Specifierand solve the constraints they represent.- populate_from_strings(spec_strings)[source]ΒΆ
Populate the solver with package specifiers parsed from provided strings.
- top_priority_manager(keep_managers=None)[source]ΒΆ
Returns the top priority manager configured on the solver.
keep_managersallows for filtering by discarding managers not in that list.
- reduce_specs(specs)[source]ΒΆ
Reduce a collection of
Specifierto its essential, minimal and unique form.This method assumes that all provided
specsare of the same package (likeresolve_package_specs()does).The reduction process consist of several steps. At each step, as soon as we managed to reduce the constraints to one
Specifier, we returns it.Filtering steps:
We remove all constraints tied to all by the top priority manager if provided.
If no manager priority is provided, we discard constraints not tied to a manager.
We discard constraints not tied to a version.
We only keep constraints tied to the highest version.
If we ends up with more than one set of constraints after all this filtering, an error is raised to invite the developer to troubleshoot the situation and refine this process.
- Return type:
- resolve_package_specs()[source]ΒΆ
Regroup specs of the pool by package IDs, and solve their constraints.
Each package ID yields one reduced spec per distinct target manager. A package therefore produces several specs when the user explicitly names several managers for it (
pkg:uv/rich pkg:brew/richβ one spec each). In contrast, a single alias pURL that expands to several managers (pkg:rpm/pingβdnf/yum/zypper) is a set of alternatives, reduced to the top-priority one.