Skip to content Skip to sidebar Skip to footer

How Can I Use Pbr Version From Source?

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, w

Solution 1:

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

Solution 2:

Finally, I have found the solution in this post.

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

UPDATE

This post shows another, more robust solution:

from pbr.version import VersionInfo

package_name='MyProject'
info = VersionInfo(package_name)

version = info.version_string()

Post a Comment for "How Can I Use Pbr Version From Source?"