Python 发行版/版本号的标准排序顺序是什么?
Python 的 pip
和 easy_install
遵循一些规则按版本号对包进行排序。对 beta/release/bugfix 版本进行编号的规则是什么,以便这些工具知道哪个是最新的?
Python's pip
and easy_install
follow some rules to sort packages by their release numbers. What are the rules for numbering beta/release/bugfix releases so these tools will know which is the newest?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是很多人的痛点。
setuptools
和easy_install
有一些相当奇怪的规则,试图与每个人相处得很好。您可以在setuptools
的parse_version
方法中阅读完整规则,但摘要如下:版本号按点分解为多个段的元组。 4.5.6.7 被解析为一个等于
("4", "5", "6", "7")
的元组。破折号或字母数字之间的尾随零被抑制。 2.4.0与2.4相同; 2.4.05 与 2.4.5 相同。
字母数字部分是小写的。 2.4.a5 等于 2.4.A5。
按字母顺序位于“final”之前的字符串被假定为预发布版本,因此 2.4.5b 位于 2.4.5 之前,而不是之后。
按
最后,“pre”、“preview”和“rc”被视为“c”。 “dev”一词被替换为“@”,因此它出现在具有相同版本的其他任何内容之前。也就是说,
xyz-dev
保证出现在任何其他xyz
版本之前。有许多建议可以更好地组织事物,其中最受欢迎的可能是 PEP 386。
This is a sore point for many folks.
setuptools
andeasy_install
have some rather bizarre rules in an attempt to play nice with everybody. You can read the full rules insetuptools
'sparse_version
method, but here's the summary:Version numbers are broken up by dots into a tuple of that many segments. 4.5.6.7 is parsed into a tuple equal to
("4", "5", "6", "7")
.Trailing zeroes between dashes or alphanumerics are suppressed. 2.4.0 is the same as 2.4; 2.4.05 is the same as 2.4.5.
Alphanumeric parts are downcased. 2.4.a5 is equal to 2.4.A5.
Strings that come before "final" alphabetically are assumed to be pre-release versions, so 2.4.5b comes before, not after, 2.4.5.
Finally, "pre", "preview", and "rc" are treated as if they were "c". The word "dev" is replaced with "@", so that it comes before anything else with the same version. That is,
x.y.z-dev
is guaranteed to come before any otherx.y.z
version.There are a number of proposals to organize things a bit more, of which the most popular is probably PEP 386.
请参阅文档 或查看源代码:pkg_resources.py 函数 parse_version() 中的文档字符串。
See the documentation or look at the source: doc string in pkg_resources.py function parse_version().
在1.0之前使用1.0a1和1.0b2。
即将推出的标准:
当前安装工具:
http://peak.telecommunity.com/DevCenter/setuptools#指定您的项目版本
Use 1.0a1 and 1.0b2 before 1.0.
The upcoming standard:
Current setuptools:
http://peak.telecommunity.com/DevCenter/setuptools#specifying-your-project-s-version