match_spec#

实现了 Conda 包的查询语言(也称为 MatchSpec)。

MatchSpec 是 Conda 包规范(例如,conda==23.3python<3.7cryptography * *_0),用于传达要安装的所需包。

#

函数#

_parse_version_plus_build(v_plus_b)

这应该可靠地从版本 + 构建字符串组合中提取构建字符串。

_parse_legacy_dist(dist_str)

_parse_channel(channel_val)

_parse_spec_str(spec_str)

属性#

class MatchSpecType#

Bases: type

__call__(spec_arg=None, **kwargs)#

将自身作为函数调用。

class MatchSpec(optional=False, target=None, **kwargs)#

Conda 包的查询语言。

构成 PackageRecord 的任何字段都可用于组成 MatchSpec

MatchSpec 可以使用关键字参数组成,其中键是 PackageRecord 的任何属性。关键字参数的值是属性应匹配的精确值。许多字段也可以与非精确值匹配——通过包含通配符 *>/< 范围(如果支持)。任何未指定的字段都等同于完全通配符匹配。

MatchSpec 也可以使用单个位置参数和可选的关键字参数组成。关键字参数还会覆盖位置参数中提供的任何冲突信息。位置参数可以是现有的 MatchSpec 实例或字符串。Conda 历史上支持等效 MatchSpec 查询的多个字符串表示形式。此 MatchSpec 应接受任何现有的有效规范字符串,并正确组成 MatchSpec 实例。

现在遵循一系列规则来创建 MatchSpec 实例的规范字符串表示形式。规范字符串表示形式通常可以表示为

(channel(/subdir):(namespace):)name(version(build))[key1=value1,key2=value2]

其中 () 表示可选字段。构造规范字符串表示形式的规则是

  1. name(即“包名称”)是必需的,但其值可以是“*”。它的位置始终在键值括号之外。

  2. 如果 version 是精确版本,它会超出键值括号并在前面加上 ==。如果 version 是“模糊”值(例如 1.11.*),它会超出键值括号,并省略 .*,并在前面加上 =。否则,version 包含在键值括号内。

  3. 如果 version 是精确版本,并且 build 是精确值,则 build 会超出键值括号,并在前面加上 =。否则,build 包含在键值括号内。build_stringbuild 的别名。

  4. namespace 位置被保留用于未来的 Conda 功能。

  5. 如果包含 channel 并且是精确值,则在 channelname 之间使用 :: 分隔符。channel 可以是规范通道名称或通道 URL。在规范字符串表示形式中,将始终使用规范通道名称。

  6. 如果 channel 是精确值,并且 subdir 是精确值,则 subdir 会附加到 channel,并使用 / 分隔符。否则,subdir 包含在键值括号中。

  7. 键值括号可以使用逗号、空格或逗号+空格分隔。值可以选择用单引号或双引号括起来,但如果 value 包含逗号、空格或等号,则必须括起来。规范格式使用逗号分隔符和单引号。

  8. 从字符串构造 MatchSpec 实例时,键值括号内给出的任何键值对都会覆盖括号外给出的任何匹配参数。

MatchSpec 属性值是简单字符串时,将使用以下约定进行解释

  • 如果字符串以 ^ 开头并以 $ 结尾,则将其转换为正则表达式。

  • 如果字符串包含星号 (*),则会从 glob 转换为正则表达式。

  • 否则,将寻求与字符串的精确匹配。

示例

>>> str(MatchSpec(name='foo', build='py2*', channel='conda-forge'))
'conda-forge::foo[build=py2*]'
>>> str(MatchSpec('foo 1.0 py27_0'))
'foo==1.0=py27_0'
>>> str(MatchSpec('foo=1.0=py27_0'))
'foo==1.0=py27_0'
>>> str(MatchSpec('conda-forge::foo[version=1.0.*]'))
'conda-forge::foo=1.0'
>>> str(MatchSpec('conda-forge/linux-64::foo>=1.0'))
"conda-forge/linux-64::foo[version='>=1.0']"
>>> str(MatchSpec('*/linux-64::foo>=1.0'))
"foo[subdir=linux-64,version='>=1.0']"
要使用完整、精确的规范完全指定包,字段
  • channel

  • subdir

  • 名称

  • version

  • 构建

必须作为精确值给出。将来,命名空间字段将添加到此列表中。或者,精确规范由 '*[md5=12345678901234567890123456789012]' 或 '*[sha256=f453db4ffe2271ec492a2913af4e61d4a6c118201f07de757df0eff769b65d2e]' 给出。

property is_name_only_spec#
property optional#
property target#
property original_spec_str#
property name#
property strictness#
property spec#
property version#
属性 fn#
FIELD_NAMES = ('channel', 'subdir', 'name', 'version', 'build', 'build_number', 'track_features', 'features',...#
FIELD_NAMES_SET#
_MATCHER_CACHE#
类方法 from_dist_str(dist_str)#
get_exact_value(field_name)#
get_raw_value(field_name)#
get(field_name, default=None)#
dist_str()#
match(rec)#

接受 PackageRecord 或字典,并且匹配可以从该记录中的任何字段拉取。匹配则返回 True,不匹配则返回 False。

_match_individual(record, field_name, match_component)#
_is_simple()#
_is_single()#
_to_filename_do_not_use()#
__repr__()#

返回 repr(self)。

__str__()#

返回 str(self)。

__json__()#
conda_build_form()#
__eq__(other)#

返回 self==value。

__hash__()#

返回 hash(self)。

_hash_key()#
__contains__(field)#
_build_components(**kwargs)#
静态方法 _make_component(field_name, value)#
类方法 merge(match_specs, union=False)#
类方法 union(match_specs)#
_merge(other, union=False)#
_parse_version_plus_build(v_plus_b)#

这应该可靠地从版本 + 构建字符串组合中提取构建字符串。 .. rubric:: 示例

>>> _parse_version_plus_build("=1.2.3 0")
('=1.2.3', '0')
>>> _parse_version_plus_build("1.2.3=0")
('1.2.3', '0')
>>> _parse_version_plus_build(">=1.0 , < 2.0 py34_0")
('>=1.0,<2.0', 'py34_0')
>>> _parse_version_plus_build(">=1.0 , < 2.0 =py34_0")
('>=1.0,<2.0', 'py34_0')
>>> _parse_version_plus_build("=1.2.3 ")
('=1.2.3', None)
>>> _parse_version_plus_build(">1.8,<2|==1.7")
('>1.8,<2|==1.7', None)
>>> _parse_version_plus_build("* openblas_0")
('*', 'openblas_0')
>>> _parse_version_plus_build("* *")
('*', '*')
_parse_legacy_dist(dist_str)#

示例

>>> _parse_legacy_dist("_license-1.1-py27_1.tar.bz2")
('_license', '1.1', 'py27_1')
>>> _parse_legacy_dist("_license-1.1-py27_1")
('_license', '1.1', 'py27_1')
_parse_channel(channel_val)#
_PARSE_CACHE#
_parse_spec_str(spec_str)#
class MatchInterface(value)#
属性 raw_value#
abstract 属性 exact_value#

如果匹配值是精确的规范,则返回该值。否则返回 None。

abstract match(other)#
matches(value)#
merge(other)#
union(other)#
class _StrMatchMixin#
属性 exact_value#
__str__()#

返回 str(self)。

__repr__()#

返回 repr(self)。

__eq__(other)#

返回 self==value。

__hash__()#

返回 hash(self)。

class ExactStrMatch(value)#

基类: _StrMatchMixin, MatchInterface

__slots__ = ('_raw_value',)#
match(other)#
class ExactLowerStrMatch(value)#

基类: ExactStrMatch

match(other)#
class GlobStrMatch(value)#

基类: _StrMatchMixin, MatchInterface

属性 exact_value#

如果匹配值是精确的规范,则返回该值。否则返回 None。

matches_all#
__slots__ = ('_raw_value', '_re_match')#
match(other)#
merge(other)#
class GlobLowerStrMatch(value)#

基类: GlobStrMatch

class SplitStrMatch(value)#

基类: MatchInterface

property exact_value#

如果匹配值是精确的规范,则返回该值。否则返回 None。

__slots__ = ('_raw_value',)#
_convert(value)#
match(other)#
__repr__()#

返回 repr(self)。

__str__()#

返回 str(self)。

__eq__(other)#

返回 self==value。

__hash__()#

返回 hash(self)。

class FeatureMatch(value)#

基类: MatchInterface

property exact_value#

如果匹配值是精确的规范,则返回该值。否则返回 None。

__slots__ = ('_raw_value',)#
_convert(value)#
match(other)#
__repr__()#

返回 repr(self)。

__str__()#

返回 str(self)。

__eq__(other)#

返回 self==value。

__hash__()#

返回 hash(self)。

class ChannelMatch(value)#

基类: GlobStrMatch

match(other)#
__str__()#

返回 str(self)。

__repr__()#

返回 repr(self)。

class CaseInsensitiveStrMatch(value)#

Bases: GlobLowerStrMatch

match(other)#
_implementors#