MatchSpec#
MatchSpec #
A MatchSpec is a query language for conda packages.
It can be composed of any of the attributes of PackageRecord.
MatchSpec can be composed of keyword arguments, where keys are
any of the attributes of PackageRecord. Values for keyword arguments
are exact values the attributes should match against. Many fields can
be matched against non-exact values by including wildcard * and >/<
ranges where supported. Any non-specified field is the equivalent of a
full wildcard match.
MatchSpecs can also be composed using a single positional argument, with optional keyword arguments. Keyword arguments also override any conflicting information provided in the positional argument. Conda has historically had several string representations for equivalent MatchSpecs.
A series of rules are now followed for creating the canonical string representation of a MatchSpec instance. The canonical string representation can generically be represented by:
(channel(/subdir):(namespace):)name(version(build))[key1=value1,key2=value2]
where () indicate optional fields.
The rules for constructing a canonical string representation are:
name(i.e. "package name") is required, but its value can be '*'. Its position is always outside the key-value brackets.- If
versionis an exact version, it goes outside the key-value brackets and is prepended by==. Ifversionis a "fuzzy" value (e.g.1.11.*), it goes outside the key-value brackets with the.*left off and is prepended by=. Otherwiseversionis included inside key-value brackets. - If
versionis an exact version, andbuildis an exact value,buildgoes outside key-value brackets prepended by a=. Otherwise,buildgoes inside key-value brackets.build_stringis an alias forbuild. - The
namespaceposition is being held for a future feature. It is currently ignored. - If
channelis included and is an exact value, a::separator is used betweenchannelandname.channelcan either be a canonical channel name or a channel url. In the canonical string representation, the canonical channel name will always be used. - If
channelis an exact value andsubdiris an exact value,subdiris appended tochannelwith a/separator. Otherwise,subdiris included in the key-value brackets. - Key-value brackets can be delimited by comma, space, or comma+space. Value can
optionally be wrapped in single or double quotes, but must be wrapped if
valuecontains a comma, space, or equal sign. The canonical format uses comma delimiters and single quotes. - When constructing a
MatchSpecinstance from a string, any key-value pair given inside the key-value brackets overrides any matching parameter given outside the brackets.
When MatchSpec attribute values are simple strings, the are interpreted using the
following conventions:
- If the string begins with ^ and ends with $, it is converted to a regex.
- If the string contains an asterisk (*), it is transformed from a glob to a
regex.
- Otherwise, an exact match to the string is sought.
To fully-specify a package with a full, exact spec, the following fields must be given as exact values: - channel - subdir - name - version - build
__init__ #
from_url
classmethod
#
Constructs a MatchSpec from a URL.
Examples#
>>> MatchSpec.from_url('https://repo.anaconda.com/pkgs/main/linux-64/python-3.9.0-h3.tar.bz2')
MatchSpec("python[url="https://repo.anaconda.com/pkgs/main/linux-64/python-3.9.0-h3.tar.bz2"]")
>>> MatchSpec.from_url('https://conda.anaconda.org/conda-forge/linux-64/_libgcc_mutex-0.1-conda_forge.tar.bz2#d7c89558ba9fa0495403155b64376d81')
MatchSpec("_libgcc_mutex[md5="d7c89558ba9fa0495403155b64376d81", url="https://conda.anaconda.org/conda-forge/linux-64/_libgcc_mutex-0.1-conda_forge.tar.bz2"]")
>>> MatchSpec.from_url('https://conda.anaconda.org/conda-forge/linux-64/_libgcc_mutex-0.1-conda_forge.tar.bz2#sha256:adfa71f158cbd872a36394c56c3568e6034aa55c623634b37a4836bd036e6b91')
MatchSpec("_libgcc_mutex[sha256="adfa71f158cbd872a36394c56c3568e6034aa55c623634b37a4836bd036e6b91", url="https://conda.anaconda.org/conda-forge/linux-64/_libgcc_mutex-0.1-conda_forge.tar.bz2"]")
>>>