如何从来源使用pbr版本? [英] How can I use pbr version from source?
问题描述
我的目标:
我想在我的 GIT 存储库中,我在 pypi 存储库中的发行版以及使用的源中保持一致的版本 __version__
变量.
I want to keep coherent versions in my GIT repository, my distribution on pypi repository, and in my source using the __version__
variable.
详细信息:
我尝试使用 pbr 从git标签生成发行版本,因此这两个版本将保持一致.但是,我无法在我的源代码中找到如何使__version__
变量与它们保持一致. (有几种方式可以从源中获取版本,但是它将如何连接到git/distro?)
I tried to use pbr, which generates the distro version from git tags, so these two versions will be coherent. However, I cannot find out how to keep the __version__
variable coherent with them in my source. (There are several ways to fetch the version from source, but how will it be connected to git/distro?)
是否可以生成版本文件(以解析表单源)或直接修改__version__
变量?
Is it possible to generate a version file (to parse form source) or directly modify the __version__
variable?
推荐答案
最后,我在此中找到了解决方案帖子.
Finally, I have found the solution in this post.
import pkg_resources # part of setuptools
version = pkg_resources.require("MyProject")[0].version
更新
此帖子显示了另一个更强大的解决方案:
This post shows another, more robust solution:
from pbr.version import VersionInfo
package_name='MyProject'
info = VersionInfo(package_name)
version = info.version_string()
这篇关于如何从来源使用pbr版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!