python - 符合 PEP440 和 git 描述部署包中可用的信息

标签 python git continuous-integration

我想使用符合 PEP440 的版本标识,但要包含 git 信息:

$ git describe --long
4.1-202-gab0f789

在 PEP 440 中有一章关于 dvcs但我不清楚 .devN 后缀如何保存非数字哈希,如上所示:ab0f789。我需要一种方法从我的生产脚本中请求 4.1-202-gab0f789 信息,那么我可以在 setup.py 中的什么地方放置项目元数据?

最佳答案

该部分告诉您不要使用散列:

As hashes cannot be ordered reliably such versions are not permitted in the public version field.

强调我的。

他们提供 .devN作为备选。如果你打算从 git 存储库发布开发者版本,给它们编号,所以 .dev0 , .dev1等。您可以使用标签来跟踪这些版本并将它们追溯到特定的修订版。

但是如果您继续阅读,有一种方法可以将散列添加为 local version number :

Identifying hash information may also be included in local version labels.

添加 + ,然后是您的哈希值(前缀为 g 以确保不会将全数字哈希值作为数字进行比较):

4.1.dev0+gab0f789

然而,本地版本号只能在创建本地非索引包或安装项目时使用。不要将版本与 +<hash> 放在一起例如在 PyPI 上。但是,如果您从持续集成服务器生成包供开发人员测试,本地版本号就可以了。

setuptools-scm project使用那个确切的方案在基于非标签 git 提交的版本中包含 git 哈希。

关于python - 符合 PEP440 和 git 描述部署包中可用的信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35522047/

相关文章:

Git rebase when rebasing master with a feature - 了解 rebase 图

python - 从文件到列表

python - 使用 Graphene 和 SQLAlchemy 通过 GraphQL API 更新记录

git-svn 忽略大型二进制文件

git - 在 Visual Studio Online 中使用自定义 NuGet 源

gruntjs - Grunt 构建在 travis 中失败 - "Cannot find any-promise implementation"

continuous-integration - "hudson.util.IOException2: Failed to create a temp file"

continuous-integration - Gitlab CI 不执行 npm 脚本

python - Sklearn imputer vs df.fillna 用列的平均值替换 nan 值

python - 点数未定义的 matplotlibs ginput()