Skip to main content

Thinly scoped and opinionated tool that computes a version number from git tags and trailers

Reason this release was yanked:

broken for python3.10

Project description

Opinionated version numbering CLIs, and library


This project aims at easing the burden of computing and managing a project's version numbers by leveraging git tags and commit trailers.

simple-git-versioning provides two CLIs: semver2 and pep440, one for each supported versioning sheme of the same name: SemVer2 and PEP440.

Integration with setuptools is supported.

Snippets to expose your project's version number programatically are provided in the Libraries section.

Installation

With pip:

pip install simple-git-versioning

Usage

By default, pep440 and semver2 will compute a version number of the form X.Y.Z. Every project starts at 0.0.0 on their initial commit, and each commit after that increments the number Z by one, unless they include a Version-Bump trailer (case-insensitive) with a value of:

  • major: X is incremented;
  • minor: Y is incremented;
  • patch: Z is incremented (same as the default).

Each tool then provides the ability to switch to a pre-release mode; or post-release, and/or dev release, etc. in the case of pep440.

CLIs

All CLIs provide comprehensive help messages, available via the --help option.

Libraries

Libraries that wish to expose their version number programatically may do so by including the following snippet:

PEP440

from importlib.metadata import PackageNotFoundError, version
from pathlib import Path

from versioning.pep440 import NoVersion, Project

try:
    __version__ = version("<your python package's name>")
except PackageNotFoundError:
    # package is not installed
    with Project(path=Path(__file__).parent) as project:
        try:
            __version__ = str(project.version())
        except NoVersion:
            __version__ = str(project.release(dev=0))

SemVer2

from importlib.metadata import PackageNotFoundError, version
from pathlib import Path

from versioning.semver2 import NoVersion, Project

try:
    __version__ = version("<your python package's name>")
except PackageNotFoundError:
    # package is not installed
    with Project(path=Path(__file__).parent) as project:
        try:
            __version__ = str(project.version())
        except NoVersion:
            __version__ = str(project.release(pre=("dev", 0))

setuptools

If you use setuptools as a build backend for your project, you can configure simple-git-versioning to derive a version automatically as follows:

In your pyproject.toml:

  • declare version as a dynamic metadata field;
  • add simple-git-versioning to your project's build-system.requires;
  • enable the setuptools integration in your pyproject.toml, and pick the versioning scheme you wish to apply.
[project]
name = ...
dynamic = ["version"]

[build-system]
requires = ["setuptools>=63", "simple-git-versioning[setuptools]"]
build-backend = "setuptools.build_meta"

[tool.simple-git-versioning.setuptools]
# scheme = "pep440" (default) or "semver2"

hatchling

If you use hatchling as a build backend for your project, you can configure simple-git-versioning to derive a version automatically as follows:

In your pyproject.toml:

  • declare version as a dynamic metadata field;
  • add simple-git-versioning to your project's build-system.requires;
  • enable the hatchling integration in your pyproject.toml, and pick the versioning scheme you wish to apply.
[project]
name = ...
dynamic = ["version"]

[build-system]
requires = ["hatchling", "simple-git-versioning[hatchling]"]
build-backend = "hatchling.build"

[tool.hatch.version]
source = "simple-git-versioning"
# scheme = "pep440" (default) or "semver2"

CI/CD

Maintainers may prefer to keep their CI/CD configuration agnostic to simple-git-versioning. In this case, they should instruct simple-git-versioning to switch to release mode by setting the SIMPLE_GIT_VERSIONING_RELEASE environment variable (to any value other than the empty string, 0, or false) and use their build frontend to extract the current (release) version:

SIMPLE_GIT_VERSIONING_RELEASE=1 pdm show --version

Without SIMPLE_GIT_VERSIONING_RELEASE, the version you would extract would have a dev suffix and a local segment identifying the current commit (e.g. 0.3.6.dev0+04aa73b).

uv version currently does not support computing dynamic versions, but it eventually should: https://github.com/astral-sh/uv/issues/14137.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple_git_versioning-0.3.24.tar.gz (115.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simple_git_versioning-0.3.24-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

Details for the file simple_git_versioning-0.3.24.tar.gz.

File metadata

  • Download URL: simple_git_versioning-0.3.24.tar.gz
  • Upload date:
  • Size: 115.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for simple_git_versioning-0.3.24.tar.gz
Algorithm Hash digest
SHA256 2273e936dcd80fd793454f5ab5930e0e6db3f04a8359e4fc952bf25860368d8a
MD5 076b7d6a9e9685383a7008f2491d2535
BLAKE2b-256 2de8a88a68882cb9cf6cca784144a09d0e56e0eb2d64c48a74be137579305754

See more details on using hashes here.

File details

Details for the file simple_git_versioning-0.3.24-py3-none-any.whl.

File metadata

  • Download URL: simple_git_versioning-0.3.24-py3-none-any.whl
  • Upload date:
  • Size: 20.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for simple_git_versioning-0.3.24-py3-none-any.whl
Algorithm Hash digest
SHA256 54b4876fa6fee6cabcae916b91dfed926ce53a183caed912a7fc53c0b049b5b9
MD5 c3dfff4625def2bfa57a2a071bce4b54
BLAKE2b-256 80cd145c3ada9a74098c5724cc3d123a55528ea09e479473dd4c77a1afadaac2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page