Finn Årup Nielsen
Finn Årup Nielsen

Reputation: 6726

Update version number with versioneer and GitHub

I am using versioneer for several of GitHub-hosted Python projects. It seems that versioneer is installed and works ok, and I can call project.__version__.

However, I forgot the procedure on how to update the version number. Should anything in setup.cfg or setup.py be left untouched?

Is it only the git tag command that controls the version number? If I use GitHub's "Draft a new release" would the Python/versioneer version number automatically be updated? Is GitHub's releases the best way, or should I do, e.g., git tag v0.2 locally? I suppose that does not matter?

Upvotes: 3

Views: 5631

Answers (2)

Brandt
Brandt

Reputation: 5639

Yes, versioneer will get the version number from git tag + state of your repository. NO modifications to your setup files (or version.py for the matter) are necessary. (That's the beauty of versioneer.)

The document Oleksandr linked to has it all (https://github.com/python-versioneer/python-versioneer/blob/master/INSTALL.md)

For example, if you have just tagged your repo as v1.0, your code's version (e.g., import mylib; print(mylib.__version__), or python setup.py version from the terminal) will show a clean v1.0.

If you happen then to modify and/or commit something, the version will update accordingly. In the following, the current state of one of my repos: one commit, plus uncommited changes, on top of a 'v1.1' tag,

$ python setup.py version

/opt/miniconda3/envs/osh_devel/lib/python3.10/site-packages/setuptools/dist.py:506: UserWarning: Normalizing 'v1.1+1.g106ac16.dirty' to '1.1+1.g106ac16.dirty'
  warnings.warn(tmpl.format(**locals()))
running version
keywords are unexpanded, not using
got version from VCS {'version': 'v1.1+1.g106ac16.dirty', 'full-revisionid': '106ac1638a9a789fa8bdb6df42a608985b18e88c', 'dirty': True, 'error': None, 'date': '2022-03-25T17:01:46+0100'}
Version: v1.1+1.g106ac16.dirty
 full-revisionid: 106ac1638a9a789fa8bdb6df42a608985b18e88c
 dirty: True
 date: 2022-03-25T17:01:46+0100

Note about PyPI and pyproject.toml

After adding a pyproject.toml file to my library, versioneer stopped working, dropping the error message below whenever I tried to (devel) install:

$ pip install -e .

Obtaining file:///Users/chbrandt/Coisas/repos/stuff/osh
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error
  
  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [16 lines of output]
      Traceback (most recent call last):
        File "/opt/miniconda3/envs/osh_devel/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
          main()
        File "/opt/miniconda3/envs/osh_devel/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/opt/miniconda3/envs/osh_devel/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 130, in get_requires_for_build_wheel
          return hook(config_settings)
        File "/private/var/folders/b1/frq3gywj3ljfqrf1yc7zk06r0000gn/T/pip-build-env-6kvnzo67/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 177, in get_requires_for_build_wheel
          return self._get_build_requires(
        File "/private/var/folders/b1/frq3gywj3ljfqrf1yc7zk06r0000gn/T/pip-build-env-6kvnzo67/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 159, in _get_build_requires
          self.run_setup()
        File "/private/var/folders/b1/frq3gywj3ljfqrf1yc7zk06r0000gn/T/pip-build-env-6kvnzo67/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 174, in run_setup
          exec(compile(code, __file__, 'exec'), locals())
        File "setup.py", line 2, in <module>
          import versioneer
      ModuleNotFoundError: No module named 'versioneer'
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

Without pyproject.toml everything goes back to normal, working fine.

The issue happens because of an evolutin of python/setup framework as explained in this thread:

, right below, in the same thread, you'll see the solution.

Just add "versioneer-518" to pyproject's requires. E.g.:

pyproject.toml:

[build-system]
requires = ["setuptools>=42", "versioneer-518"]
build-backend = "setuptools.build_meta"

Upvotes: 3

Oleksandr Golovatyi
Oleksandr Golovatyi

Reputation: 76

According to https://github.com/warner/python-versioneer/blob/master/INSTALL.md the steps depend on if your project is distributed with PyPi or through github. But you need to create a new tag when new version needed.

Upvotes: 0

Related Questions