Skip to main content

Robustly generate exact git hashes for python packages

Project description

Robustly generate exact git hashes for python packages


pip install pygitversion


The point of pygitversion is to enable you to robustly create your package with exact git version information, rather than just a simple version specifier.

It does not replace the semantic version specifier of your package, but rather complements it. pygitversion provides the tools necessary to always have git information available in a Python package (whether the actual repo is available or not).

To use in your package, follow these steps:

  1. If pyproject.toml does not exist in your package, create it.

  2. Add the key [build-system] to pyproject.toml, and add requires = ['pygitversion','setuptools>40.8.0','wheel'] to the key.

  3. Ensure that contains the correct semantic __version__ specifier.

  4. In, add the following:

    import pygitversion
  5. Ensure the package has a, and that it includes <package>/GIT_INFO.

  6. The git version of the module may then be accessed by doing:

    import pygitversion
  7. It is recommended (but not necessary) that contain:

    import pygitversion
    GIT_VERSION = pygitversion.construct_version_info(__name__)

Cases Addressed

There are various ways a package can be installed, and pygitversion attempts to ensure that in each case, the git version is available. The following assumes the above steps have been followed in your package.

  1. Package cloned and installed via pip install .: a GIT_INFO file is created and installed due to That GIT_INFO file is found whenever the package is loaded.
  2. Package cloned and installed via pip install -e .: a GIT_INFO file is created in the repo, and sym-linked when the package is imported.
  3. Package installed directly from hosted source control via pip install git+git:...: Unsure?
  4. Package installed from PyPI (pip install <package>): the process of building the sdist and bdist to upload to PyPI inherently bundles the most current GIT_INFO file as part of the build, and this is installed with the package.


To run the all tests run:



0.1.0 (2019-09-04)

  • First release on PyPI.

Download files

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

Built Distribution

pygitversion-0.1.2-py2.py3-none-any.whl (5.5 kB view hashes)

Uploaded py2 py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page