形式“package===version"的setuptools要求的目的是什么? [英] What is the purpose of setuptools requirements of the form "package===version"
问题描述
假设我有一个带有控制台脚本的包,例如
Say I have a package with a console script such as
from setuptools import setup
setup(
name='eg_package',
version='0.0.1',
description='Trivial test package',
packages=[
'eg_package',
],
entry_points={
'console_scripts': [
'foo = eg_package.main:main',
]
},
)
如果我使用 egg_info -b mytag
设置和显式构建标记,则生成的脚本具有 __requires__ = 'eg-package===0.0.1mytag'
,即具有 3="符号.当标签不是 Beta 版的 b1
等传统标签时,就会发生这种情况.
If I set and explicit build tag using egg_info -b mytag
the resulting script has __requires__ = 'eg-package===0.0.1mytag'
, i.e. with 3 "=" signs. This occurs when the tag is not something conventional like b1
for a beta release.
起初我认为这是一个错误,但 setuptools 文档表明它是一个有效的需求标识符.但是,它不适用于导致我们系统出现问题的旧版 setuptools.
At first I thought this was a bug but the setuptools documentation suggests it is a valid requirement identifier. However, it doesn't work with older versions of setuptools which is causing problems with our systems.
我的问题是 "==="
是什么意思,为什么现代 setuptools
使用它?
My question is what does "==="
mean and why does modern setuptools
use it?
推荐答案
pip
文档中的需求说明符部分 链接到 由setuptools
pkg_resources
实现的需求说明符的官方文档.它指定了形式语法,但没有说明语义.概述文档解释语义,但在~=
和 ===
显然是在 vv.7(安装 python 2.7.9)和 16 之间添加的东西.
Requirement specifier section in pip
docs links to the official docs for requirement specifiers implemented by setuptools
pkg_resources
. It specifies the formal syntax but says nothing on the semantics.
Overview docs explain semantics but say nothing on the ~=
and ===
stuff that were apparently added somewhere between vv.7 (installed with python 2.7.9) and 16.
当文档失败时,是时候查阅来源了.下载 setuptools hg repo 并注释 pkg_resources/__init__.py
最终将我们带到变更集 3125 并带有消息Implement PEP 440" by using the Packaging library.
When docs fail, it's time to consult the sources. Downloading the setuptools hg repo and annotating pkg_resources/__init__.py
ultimately brings us to changeset 3125 with the message "Implement PEP 440 by using the packaging library".
确实,PEP 440,版本说明符部分解释了语法和语义:
Indeed, PEP 440, Version Specifiers section explains the syntax and semantics:
通过检查提交中的其他文件和相关的packaging
包,我得出了以下明显的结论:
By examining other files in the commit and the related packaging
package, I came to these apparent conclusions:
~=
永远不会产生;当处理1时,它根据 PEP 中概述的规则充当过滤器.===
,在处理时,会发出信号以回退到旧的setuptools
版本语法和比较逻辑.只要生成的版本字符串不符合 PEP2,就会生成它.
~=
is never produced; when handled1, it acts as a filter according to the rules outlined in the PEP.===
, when handled, signals to fall back to the oldersetuptools
version syntax and comparison logic. It is produced whenever the resulting version string doesn't conform to the PEP2.
1在 pkg_resources._vendor.packaging.specifiers._compare_compatible()
中2pkg_resources.parse_version()
产生一个 pkg_resources.SetuptoolsLegacyVersion
而不是 pkg_resources.SetuptoolsVersion
1
In pkg_resources._vendor.packaging.specifiers._compare_compatible()
2pkg_resources.parse_version()
produces a pkg_resources.SetuptoolsLegacyVersion
rather than pkg_resources.SetuptoolsVersion
这篇关于形式“package===version"的setuptools要求的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!