Reversion 0.2

Reversion is a command line tool to easily update version numbers in project files.

To install it:

pip install reversion

Python 3 is required.

To use it, create a config file reversion.toml in the root directory of your project. It should look like this:

currentversion = "0.1"

[[place]]
file = "reversion/__init__.py"
# linematch is a regex; use single quotes so you don't have to escape backslash
line-regex = '__version__'

[[place]]
file = "docs/conf.py"
line-regex = 'release'

Each [[place]] table indicates where a copy of the version number is found.

Then run:

reversion +0.1

To check the config file and version number places without changing anything, run:

reversion --check

Specifying version number changes

At the command line, you can specify a few ways to change the version number:

  • Starts with a number - set a completely new version number:

    reversion 4.0
    
  • Starts with ~ - add a suffix to the current version:

    reversion ~.1
    # 4.0 -> 4.0.1
    
  • Starts with + - increment the current version:

    reversion +.1
    # 4.0 -> 4.1
    

    Any non-numeric parts have to match exactly, so you can do:

    reversion +..0beta1
    # 4.0.0beta1 -> 4.0.0beta2
    
  • The word final - strip any non-numeric version parts:

    reversion final
    # 4.0.0rc3 -> 4.0.0
    

You can also chain changes together. For instance, immediately after a major release, you may want to increment the version number and add a dev suffix:

reversion +1 ~.dev0
# 4.0.0 -> 5.0.0.dev0

The config file

The config file should be called reversion.toml, and be in the root directory of your project. reversion will look in the current directory when you invoke it.

The config file uses the TOML format.

Here’s reversion’s own config file:

currentversion = "0.2"

[[place]]
file = "reversion/__init__.py"
line-regex = '__version__'

[[place]]
file = "docs/conf.py"
line-regex = 'release'
currentversion

The current version number of the project. This is used to find the version number in files. Reversion will automatically update it along with the other version numbers.

Place sections

Each instance of the version number in your code should have a corresponding [[place]] section.

file

The file containing the version number. Paths are relative to the directory containing reversion.toml.

line-regex

A regular expression to find the line with the version number. Reversion will only see lines matching both this pattern and the current version number. You probably want to specify this using a single-quoted string - this is a literal string in TOML syntax, so you don’t need to escape backslashes.