Python Semantic Release

Python Semantic Release automatically versions code based on Git commit comments.

Install

pip install python-semantic-release

Basic setup

Create a setup.py file in the root of the project, if none exists.

from setuptools import setup

__version__ = "0.0.0"

setup(
	name="your-app-or-package-name",
	version=__version__,
)

Add this to your pyproject.toml file. If the file does not exist, create it.

[tool.semantic_release]
version_variable = "setup.py:__version__"

Advanced setup

Rather than store the version in a root-level setup.py, you can store your version in the source files of your project. This way, your program can access its own version. For example, the UI can display its version.

app/my_module/__init__.py

__version__ = "0.0.0"

setup.py

from setuptools import setup

from app.my_module import __version__

setup(
	name="my-name",
	version=__version__,
)

pyproject.toml

[tool.semantic_release]
version_variable = "app/my_module/__init__.py:__version__"

Run

Do a dry run.

semantic-release --noop version

Version normally.

semantic-release version

Create prerelease version.

semantic-release version --prerelease

Force major version, e.g., 1.0.0.

semantic-release version --major

Resources

Python Semantic Release
Interactive graph
On this page
Install
Basic setup
Advanced setup
Run
Resources