Skip to main content
 首页 » 编程设计

python之setuptools 在哪里找到包的版本

2024年10月01日7softidea

我试图了解什么版本 github package有。我正在本地构建它。在release process ,我发现这个:

VERSION=$(python setup.py --version) 

在我的 repo 中,每当我运行它时,我都会得到:

» python setup.py --version 
1.0.9.dev29 

但我不知道这是从哪里来的。版本 1.0.9.dev29 既不在 setup.cfg 中,也不在单独的 VERSION 文件中。 repo 中没有版本文件或类似文件。我不明白 setuptools 是如何导出这个版本 ID 的。 documentation不给出任何提示。

python setup.py --version 命令如何工作?

请您参考如下方法:

setup.py --version 列出从元数据中获取的包的版本。您的特定项目使用 pbr package处理元数据:

setup_requires=['pbr>=1.9', 'setuptools>=17.1', 'pytest-runner'], 

pbr(Python 构建合理性)通过查看当前的 git 历史记录在包构建时设置版本,请参阅 Version section pbr 文档:

Versions can be managed two ways - postversioning and preversioning. Postversioning is the default, and preversioning is enabled by setting version in the setup.cfg metadata section. In both cases version strings are inferred from git.

If the currently checked out revision is tagged, that tag is used as the version.

因此,当开发人员运行 setup.py 来构建发行版时,那时 pbr 查看 git 存储库元数据并提取一个版本号,并将其包含在构建的发行版中; tar.gz 源压缩包包含一个带有版本的 PKG-INFO 文件。