Skip to main content

gitversion Setuptools Extension

Version Downloads Status License Docs

Wait… Why? What??

PEP440 codifies a version scheme for Python packages. This setuptools extension will generate Developmental Release and Local Version Label segments that identify the revision that is being built. PEP440 defines the following format for Python package versions:

version         = [epoch "!"] public-version ["+" local-version]
epoch           = digit+
public-version  = release-segment [pre-segment] [post-segment] [dev-segment]
local-version   = (letter | digit)+ ["." (letter|digit)+]
release-segment = digit+ ("." digit+)*
pre-segment     = "a" digit+ | "b" digit+ | "rc" digit+
post-segment    = ".post" digit+
dev-segment     = ".dev" digit+

It also recommends that package indecies only accept final releases which are defined as having a version that consists of only a release segment and an optional epoch. So why did I go through all of the trouble to create an extension for managing versions that should not be submitted to a package index? If you develop Python packages that are used inside the walls of a business, then you probably know exactly why – using a local Python Package Index that holds non-public packages is commonplace. It is also common to stage pre-release packages and builds from a CI server in an internal index. This is where this extension comes into play. It provides a consistent way to manage package versions throughout all stages of development.

Let’s look at the state of this project as I am writing this document. The git history looks like the following:

* 3fdc192 - (HEAD, origin/initial-implementation, initial-implementation)
###### 9 more commits here
* 7ca1fd2 - (origin/master, master)
*   87d944e - Merge pull request #1 from dave-shawley/reorg (6 days ago)
|\
| * 04d0cca - (origin/reorg, reorg)
| ###### 9 more commits here
|/
* bd7ad3c - (tag: 0.0.0) SYN (4 months ago)

When I run setup.py git_version it sets the version to 0.0.0.post1.dev11. The 0.0.0 portion is the release segment that is passed to the setup function in setup.py. The extension finds that tag in the history and counts the number of merges that have occurred since that tag – this value becomes the post version segment. In this case there has only been a single merge. Then it counts the number of commits since the last merge occurred – this value becomes the development version segment.

How?

The easiest way to use this extension is to install it into your build environment and then use it from the command line when you generate and upload your distribution.

  1. pip install setupext-gitversion into your build environment

  2. Add the following lines to your setup.cfg:

[git_version]
version-file = LOCAL-VERSION
  1. Add the following line to your MANIFEST.in:

    include LOCAL-VERSION
  2. Modify your setup.py to append the contents of LOCAL-VERSION to your version keyword:

    version_suffix = ''
    try:
       with open('LOCAL-VERSION') as f:
          version_suffix = f.readline().strip()
    except IOError:
       pass
    
    setup(
       # normal keywords
       version='1.2.3' + version_suffix,
    )

    Where 1.2.3 is the tag of the last release package.

  3. Add git_version to your upload or distribution generation command. You want to use something like the following:

    setup.py git_version sdist upload
    setup.py git_version bdist_egg upload

And that’s it. That will embed SCM information into your package when your build a distribution. It is also smart enough to generate an empty suffix for a build from a tagged commit.

Ok… Where?

Source

https://github.com/dave-shawley/setupext-gitversion

Status

https://travis-ci.org/dave-shawley/setupext-gitversion

Download

https://pypi.python.org/pypi/setupext-gitversion

Documentation

http://setupext-gitversion.readthedocs.org/en/latest

Issues

https://github.com/dave-shawley/setupext-gitversion

Metadata

Release files for setupext-gitversion 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for setupext-gitversion 1.1.1
File Size Uploaded
setupext-gitversion-1.1.1.tar.gz 11.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for setupext-gitversion 1.1.1
File Interpreter ABI Platform
setupext_gitversion-1.1.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 20.9 kB

Release files / setupext-gitversion-1.1.1.tar.gz

Download URL setupext-gitversion-1.1.1.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f8b25e1fa6adc0cb4682fd32d734ba4df0ef660d7b49bd88a1587882e2b45aa8
BLAKE2b-256 checksum
How to use checksums
bf07a39d68aca8740b277733f99c452c274e2bffd1bb0d2f648ff5d71be54fa4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / setupext_gitversion-1.1.1-py2.py3-none-any.whl

Download URL setupext_gitversion-1.1.1-py2.py3-none-any.whl
Size 9.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
ae51ccabf6cbe6cf0b8104a195af128b574622a2e47dd2a9bd0ce3cca5ac101b
BLAKE2b-256 checksum
How to use checksums
259819adf5657f12e61778b67e58445251bc856b5d3ba69bb4d3600590636381
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

1.1.0

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page