How can I use pbr version from source?
Asked Answered
I

2

2

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?

Imperturbable answered 30/4, 2019 at 13:27 Comment(0)
I
1

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()
Imperturbable answered 2/5, 2019 at 8:46 Comment(0)
S
1

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

Shirl answered 22/10, 2019 at 20:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.