Implement versioning of Python projects according to PEP 440

Hello dear reader, there is a cool PEP 440 and today I’ll try to explain how to implement such versioning for your project according to this one.

Actually, it’s very simple process. You just need to install a single Python package.

pip install --user bumpversion

After that, you need to create a config file inside your root directory of a project.

Now I’m going to explain step by step, what’s going out inside of this file.

  • I guess current_version is a self-explanatory attribute.
  • If commit is set to True , then every single bump of a project version will be created automatically a commit with a specific message.
  • tag is likewise commit
  • files is a list of project files that will be used for bump
  • Other stuff is used under the hood of the library, I won’t go into many details here, but you can parse & serialize a version string based on own needs, set dev, post-release etc.

Another step is set to the current_version all version strings inside files from .bumpversion.cfg. E.g. if you have got a version string 3.0.1 inside your setup.py then you need to set it to 3.0.0.a0 or vise-versa.

Scheme of versioning is the next:

X.Y.ZaN   # Alpha release
X.Y.ZbN # Beta release
X.Y.ZrcN # Release Candidate
X.Y.Z # Final release

And workflow will be like this:

bumpversion patch # 3.0.0.a0 → 3.0.1.a0
bumpversion n # 3.0.1.a0 → 3.0.1.a1
bumpversion release # 3.0.1.a1 → 3.0.1.b0
bumpversion release # 3.0.1.b0 → 3.0.1.rc0
bumpversion release # 3.0.1.rc0 → 3.0.1
bumpversion minor # 3.0.1 → 3.1.0.a0
bumpversion major # 3.1.0.a0 → 4.0.0.a0
bumpversion n # 4.0.0.a0 → 4.0.0.a1
bumpversion release --tag # 4.0.0.a1 → 4.0.0.b0

The last one command will create for us a tag v4.0.0.b0.

That’s it.

Software Engineer, LL.B., MSc in CS

Software Engineer, LL.B., MSc in CS