version#

实现版本规范,包含解析和比较逻辑。

对象继承

Inheritance diagram of BaseSpec, VersionSpec, BuildNumberMatch

#

SingleStrArgCachingType

VersionOrder

实现版本字符串之间的顺序关系。

BaseSpec

VersionSpec

BuildNumberMatch

函数#

normalized_version(→ VersionOrder)

解析版本字符串并返回 VersionOrder 对象。

ver_eval(vtest, spec)

treeify(spec_str)

untreeify(spec[, _inand, depth])

compatible_release_operator(x, y)

属性#

normalized_version(version: str) VersionOrder#

解析版本字符串并返回 VersionOrder 对象。

ver_eval(vtest, spec)#
version_check_re#
version_split_re#
version_cache#
class SingleStrArgCachingType#

基类: type

__call__(arg)#

将自身作为函数调用。

class VersionOrder(vstr: str)#

实现版本字符串之间的顺序关系。

版本字符串可以包含常用的字母数字字符 (A-Za-z0-9),并用点和下划线分隔成组件。 不允许空段(即两个连续的点、前导/尾随下划线)。 可选的 epoch 号(一个整数后跟 '!')可以放在实际版本字符串之前(这对于指示版本控制方案本身的变化很有用)。 版本比较不区分大小写。

Conda 支持六种类型的版本字符串:* 发行版本仅包含整数,例如 '1.0'、'2.3.5'。 * 预发布版本使用其他字母,例如 'a' 或 'rc',

例如 '1.0a1'、'1.2.beta3'、'2.3.5rc3'。

  • 开发版本由字符串 'dev' 指示,例如 '1.0dev42'、'2.3.5.dev12'。

  • 后发布版本由字符串 'post' 指示,例如 '1.0post1'、'2.3.5.post2'。

  • 标记版本具有指定特定感兴趣属性的后缀,例如 '1.1.parallel'。 标签可以添加到前面四种类型中的任何一种。 就排序而言,标签被视为预发布版本中的字符串。

  • 可选的本地版本字符串(用 '+' 分隔)可以附加到主(上游)版本字符串。 仅当主版本相等时才在比较中考虑它,但在其他方面以完全相同的方式处理。

为了获得可预测的版本排序,至关重要的是使给定包的版本号方案在一段时间内保持一致。 具体来说,* 版本字符串应始终具有相同数量的组件

(可选的标签后缀或本地版本字符串除外),

  • 指示非发行版本的字母/字符串应始终出现在相同的位置。

在比较之前,版本字符串按如下方式解析:* 它们首先被拆分为 epoch、版本号和本地版本

分别在 '!' 和 '+' 处编号。 如果没有 '!',则 epoch 设置为 0。如果没有 '+',则本地版本为空。

  • 然后版本部分在 '.' 和 '_' 处拆分为组件。

  • 每个组件再次拆分为数字和非数字的运行

  • 仅包含数字的子组件将转换为整数。

  • 字符串转换为小写,对 'dev' 和 'post' 进行特殊处理。

  • 当组件以字母开头时,会插入填充值 0 以使数字和字符串保持同步,从而得到 '1.1.a1' == 1.1.0a1'。

  • 本地版本部分重复相同的操作。

示例

1.2g.beta15.rc => [[0], [1], [2, 'g'], [0, 'beta', 15], [0, 'rc']] 1!2.15.1_ALPHA => [[1], [2], [15], [1, '_alpha']]

结果列表按字典顺序比较,其中以下规则应用于每对对应的子组件:* 整数按数值比较 * 字符串按字典顺序比较(不区分大小写) * 字符串小于整数,但 * 'dev' 版本小于所有其他对应版本的类型 * 'post' 版本大于所有其他对应版本的类型 * 如果子组件没有对应项,则缺失的对应项被视为整数 0

被视为整数 0,以确保 '1.1' == '1.1.0'。

结果顺序是

0.4

< 0.4.0 < 0.4.1.rc

== 0.4.1.RC # 不区分大小写的比较

< 0.4.1 < 0.5a1 < 0.5b3 < 0.5C1 # 不区分大小写的比较 < 0.5 < 0.9.6 < 0.960923 < 1.0 < 1.1dev1 # 特殊情况 'dev' < 1.1_ # 附加下划线是类似 openssl 版本的特殊情况 < 1.1a1 < 1.1.0dev1 # 特殊情况 'dev'

== 1.1.dev1 # 在字符串前插入 0

< 1.1.a1 < 1.1.0rc1 < 1.1.0

== 1.1

< 1.1.0post1 # 特殊情况 'post'

== 1.1.post1 # 在字符串前插入 0

< 1.1post1 # 特殊情况 'post' < 1996.07.12 < 1!0.4.1 # epoch 增加 < 1!3.1.1.6 < 2!0.4.1 # epoch 再次增加

某些包(最著名的是 openssl)具有不兼容的版本约定。 特别是,openssl 将字母解释为版本计数器,而不是预发布标识符。 对于 openssl,关系

1.0.1 < 1.0.1a => False # 对于 openssl 应该为 true

成立,而 Conda 包使用相反的顺序。 您可以通过在纯版本号后附加下划线来解决此问题

1.0.1_ < 1.0.1a => True # 确保 openssl 的正确排序

_cache_#
__str__() str#

返回 str(self)。

__repr__() str#

返回 repr(self)。

_eq(t1: list[str], t2: list[str]) bool#
__eq__(other: object) bool#

返回 self==value。

startswith(other: object) bool#
__ne__(other: object) bool#

返回 self!=value。

__lt__(other: object) bool#

返回 self<value。

__gt__(other: object) bool#

返回 self>value。

__le__(other: object) bool#

返回 self<=value。

__ge__(other: object) bool#

返回 self>=value。

VSPEC_TOKENS = '\\s*\\^[^$]*[$]|\\s*[()|,]|[^()|,]+'#
treeify(spec_str)#

示例

>>> treeify("1.2.3")
'1.2.3'
>>> treeify("1.2.3,>4.5.6")
(',', '1.2.3', '>4.5.6')
>>> treeify("1.2.3,4.5.6|<=7.8.9")
('|', (',', '1.2.3', '4.5.6'), '<=7.8.9')
>>> treeify("(1.2.3|4.5.6),<=7.8.9")
(',', ('|', '1.2.3', '4.5.6'), '<=7.8.9')
>>> treeify("((1.5|((1.6|1.7), 1.8), 1.9 |2.0))|2.1")
('|', '1.5', (',', ('|', '1.6', '1.7'), '1.8', '1.9'), '2.0', '2.1')
>>> treeify("1.5|(1.6|1.7),1.8,1.9|2.0|2.1")
('|', '1.5', (',', ('|', '1.6', '1.7'), '1.8', '1.9'), '2.0', '2.1')
untreeify(spec, _inand=False, depth=0)#

示例

>>> untreeify('1.2.3')
'1.2.3'
>>> untreeify((',', '1.2.3', '>4.5.6'))
'1.2.3,>4.5.6'
>>> untreeify(('|', (',', '1.2.3', '4.5.6'), '<=7.8.9'))
'(1.2.3,4.5.6)|<=7.8.9'
>>> untreeify((',', ('|', '1.2.3', '4.5.6'), '<=7.8.9'))
'(1.2.3|4.5.6),<=7.8.9'
>>> untreeify(('|', '1.5', (',', ('|', '1.6', '1.7'), '1.8', '1.9'), '2.0', '2.1'))
'1.5|((1.6|1.7),1.8,1.9)|2.0|2.1'
compatible_release_operator(x, y)#
version_relation_re#
regex_split_re#
OPERATOR_MAP#
OPERATOR_START#
class BaseSpec(spec_str, matcher, is_exact)#
property spec#
property raw_value#
property exact_value#
is_exact()#
__eq__(other)#

返回 self==value。

__ne__(other)#

返回 self!=value。

__hash__()#

返回 hash(self)。

__str__()#

返回 str(self)。

__repr__()#

返回 repr(self)。

abstract merge(other)#
regex_match(spec_str)#
operator_match(spec_str)#
any_match(spec_str)#
all_match(spec_str)#
exact_match(spec_str)#
always_true_match(spec_str)#
class VersionSpec(vspec)#

基类: BaseSpec

_cache_#
get_matcher(vspec)#
merge(other)#
union(other)#
VersionMatch#
class BuildNumberMatch(vspec)#

基类: BaseSpec

property exact_value: int | None#
_cache_#
get_matcher(vspec)#
merge(other)#
union(other)#
__str__()#

返回 str(self)。

__repr__()#

返回 repr(self)。