Skip to main content

Use git repo data for building a version number according to PEP-440

Project description

Project Status: Active – The project has reached a stable, usable state and is being actively developed. PyPI PyPI License PyPI Python Version ReadTheDocs Build Coverage pre-commit.ci

Use git repo data (latest tag, current commit hash, etc) for building a version number according to PEP 440.

Features:

  • Can be installed & configured through both setup.py and PEP 518’s pyproject.toml

  • Does not require to change source code of the project

  • Tag-, file-, and callback-based versioning schemas are supported

  • Templates for tag, dev and dirty versions are separated

  • Templates support a lot of substitutions including git and environment information

  • Well-documented

See comparison between setuptools-git-versioning and other tools.

Limitations:

  • Currently the only supported VCS is Git

  • Only Git v2 is supported

  • Setuptools and scikit-build-core build backends are supported (no Poetry & others)

  • Currently does not support automatic exporting of package version to a file for runtime use (but you can use setuptools-git-versioning > file redirect instead)

Documentation

See https://setuptools-git-versioning.readthedocs.io/en/stable/

Install

pyproject.toml

Just add setuptools-git-versioning to build-sytem section of your pyproject.toml, add a section tool.setuptools-git-versioning with config options, and mark the project version as dynamic.

[build-system]
requires = [ "setuptools>=41", "wheel", "setuptools-git-versioning>=3.0,<4", ]
build-backend = "setuptools.build_meta"

[tool.setuptools-git-versioning]
enabled = true

[project]
dynamic = ["version"]

And check the package version generated (see command help):

$ python -m setuptools_git_versioning
0.0.1

# or

$ setuptools-git-versioning
0.0.1

When add a git tag:

$ git add .
$ git commit -m "Test tagged"
$ git tag 1.2.3

And now version is based on git tag:

$ setuptools-git-versioning
1.2.3

$ echo 1 > uncommitted.change
$ git add .
$ setuptools-git-versioning
1.2.3.post0+git.d2bc6516.dirty

$ git commit -m "Test committed"
$ setuptools-git-versioning
1.2.3.post1+git.d452190b

setup.py

Just add setuptools-git-versioning to setup_requires argument of setuptools.setup function call, and then add new argument setuptools_git_versioning with config options:

import setuptools

setuptools.setup(
    ...,
    setuptools_git_versioning={
        "enabled": True,
    },
    setup_requires=["setuptools-git-versioning>=3.0,<4"],
)

Commands are the same as above, plus python -m setup.py returns the same version.

scikit-build-core

If your project uses the scikit-build-core build backend, add setuptools-git-versioning to build-system.requires, mark the version field as dynamic, register the dynamic-metadata provider, and configure options under the usual [tool.setuptools-git-versioning] section:

[build-system]
requires = [ "scikit-build-core", "setuptools-git-versioning>=3.0,<4", ]
build-backend = "scikit_build_core.build"

[project]
name = "mypackage"
dynamic = ["version"]

[tool.scikit-build.metadata.version]
provider = "setuptools_git_versioning.scikit_metadata"

[tool.setuptools-git-versioning]
enabled = true

All options under [tool.setuptools-git-versioning] work exactly as the for setuptools backend. Inline configuration under [tool.scikit-build.metadata.version] is not supported.

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

setuptools_git_versioning-3.1.0.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

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

setuptools_git_versioning-3.1.0-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file setuptools_git_versioning-3.1.0.tar.gz.

File metadata

File hashes

Hashes for setuptools_git_versioning-3.1.0.tar.gz
Algorithm Hash digest
SHA256 612dfcf184addac9e1c2216f4f229724b2390e5bf613fb925ae80b84f2529172
MD5 ce99e1da1b47669e9fb7688f94bffdba
BLAKE2b-256 538cd315ac297c004cf15b506eb53d6b0b29e18eadfc44fde7b9b971a41f3206

See more details on using hashes here.

Provenance

The following attestation bundles were made for setuptools_git_versioning-3.1.0.tar.gz:

Publisher: release.yml on dolfinus/setuptools-git-versioning

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file setuptools_git_versioning-3.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for setuptools_git_versioning-3.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3a68f3fd58a2a5e86b0792435cfa9d8e569ab60ee5e4c29228c09da9b637bf18
MD5 d0a7e337ff815888dccac0174d32bc00
BLAKE2b-256 e35adf537a48d60fcb23c2e76bf0192a1d812f6f540e6cae698e402a3bbc27f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for setuptools_git_versioning-3.1.0-py3-none-any.whl:

Publisher: release.yml on dolfinus/setuptools-git-versioning

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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