2

I am trying to understand what version a github package has. I am building it locally. In the release process, I find this:

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

In my repo, whenever I run this I get:

» python setup.py --version
1.0.9.dev29

But I have no clue where this is coming from. The version 1.0.9.dev29 is neither in the setup.cfg, nor in a separate VERSION file. There is no version file or similar in the repo. I do not understand how setuptools is able to derive this version id. The documentation does not give any hints.

How does the python setup.py --version command work?

blueFast
  • 41,341
  • 63
  • 198
  • 344
  • 1
    Have you looked at `setup.py` yet? :-) – Martijn Pieters May 02 '17 at 06:55
  • @MartijnPieters: yes, and it has nothing related to the version (I had to reorg the links, they were wrong). I *do* think that --version gives me the version of the package, not of setuptools. – blueFast May 02 '17 at 06:57
  • 1
    It looks as though the package in question is using [pbr](https://docs.openstack.org/developer/pbr/); the answer to where the version comes from is probably in the pbr documentation somewhere. In particular: "In both cases version strings are inferred from git." So it looks as though the version is based on the most recent tagged git revision. – Mark Dickinson May 02 '17 at 07:05
  • Indeed, I got it wrong and `--version` produces the `version` field in the metadata. This specific project uses a third-party project called `pbr` to set that up. – Martijn Pieters May 02 '17 at 07:09
  • @MarkDickinson makes sense, can accept as answer. I do not know how you did infer that it was using pbr – blueFast May 02 '17 at 07:09
  • @delavnog: I got lucky: I looked at `jira/__init__.py` on GitHub (because that's one of the locations that one might expect to find version information) and noticed that the most recent commit to that file had a message "Adopted pbr and hacking". (The `from pbr.version` import was a bit of a giveaway, too.) – Mark Dickinson May 02 '17 at 07:15

2 Answers2

3

setup.py --version lists the version of a package taken from the metadata. Your specific project uses the pbr package to handle metadata:

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

pbr (Python Build Reasonableness) sets a version at package build time by looking at the current git history, see the Version section of the pbr documentation:

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.

So when the developer runs setup.py to build a distribution, at that time pbr looks at the git repository metadata and extracts a version number, and includes that in distributions that are built; the tar.gz source tarball includes a PKG-INFO file with the version.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
0

Per the accepted answer, the info is coming from your git repo, based on tags, using the pbr extension.

What's not included is how the actual string was determined. pbr uses an algorithm that is specified in the pbr documentation based on the latest tags that were created in the repo (I'm assuming searching the currently checked out branch, but not sure).

The 1.0.9.dev29 string likely means you have a 1.0.9 tag in the repo, with 29 commits that do not have a tag. By default, pbr will add a .devN postfix to a new commit without a tag, that increments with each new untagged commit.

If you add a 1.0.10 tag to the latest commit, that will be the new version, but if you add another commit without a tag, it will be 1.0.9.dev30.

See here for More info on the Semantic Versioning used by pbr

LightCC
  • 9,804
  • 5
  • 52
  • 92