How can I use pbr version from source?

你。 提交于 2019-12-12 16:32:04

问题


My goal:

I want to keep coherent versions in my GIT repository, my distribution on pypi repository, and in my source using the __version__ variable.


Details:

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?)

Is it possible to generate a version file (to parse form source) or directly modify the __version__ variable?


回答1:


Finally, I have found the solution in this post.

import pkg_resources  # part of setuptools
version = pkg_resources.require("MyProject")[0].version



回答2:


Since Python 3.8 there is a solution directly in the standard library: __version__ = importlib.metadata.version('Example'). See Using importlib.metadata.



来源:https://stackoverflow.com/questions/55921981/how-can-i-use-pbr-version-from-source

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!