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': {'pacaur', 'pacman', 'pamac', 'paru', 'yay'}, 'android': None, 'apache': None, 'apk': {'apk'}, 'bitbucket': None, 'bitnami': None, 'bower': None, 'buildroot': None, 'cargo': {'cargo'}, 'carthage': None, 'chef': None, 'chocolatey': {'choco'}, 'clojars': None, 'cocoapods': None, 'composer': {'composer'}, 'conan': None, 'conda': {'conda', 'pixi'}, 'coreos': None, 'cpan': {'cpan'}, 'cran': None, 'crystal': None, 'ctan': None, 'deb': {'apt', 'apt-mint'}, 'docker': None, 'drupal': None, 'dtype': None, 'dub': None, 'ebuild': {'emerge'}, 'eclipse': None, 'elm': None, 'gem': {'gem'}, 'generic': None, 'gitea': None, 'github': None, 'gitlab': None, 'golang': None, 'gradle': None, 'guix': {'guix'}, 'hackage': None, 'haxe': {'haxelib'}, 'helm': None, 'hex': None, 'huggingface': None, 'julia': None, 'luarocks': {'luarocks'}, 'maven': None, 'melpa': None, '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': None, 'pecl': None, 'perl6': {'zef'}, 'platformio': None, 'pub': None, 'puppet': None, 'pypi': {'pip', 'pipx', 'uv'}, 'qpkg': None, 'rpm': {'dnf', 'dnf5', 'yum', 'zypper'}, 'rubygems': {'gem'}, 'sourceforge': None, 'sublime': None, 'swid': None, 'terraform': None, 'vagrant': None, 'vim': None, 'wordpress': None, 'yocto': None}¶
Map pURLās types to MPMās manager IDs.
Keys are recognized pURLās types, and values are the set of MPMās manager IDs that can handle the package type.
Warning
There is no official list of
pkg:<type>/...prefixes defined in the pURL specification.The only source we found lying around in the pURL literature is this list of diverse aliases, examples and libraries. We use this document to compile the keys of this
PURL_MAPmapping.Todo
Reuse the mapping that is proposed upstream to the package-url Python project.
- 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.
- 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 allow for the solving of 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.