Skip to main content

Package version query toolkit for Python

Project description

package version from PyPI build status from Travis CI build status from AppVeyor grade from Codacy test coverage from Codecov license

This script is motivated by wish to avoid hardcoding the version number when maintaining a Python package.

Instead of hardcoding:

__version__ = '1.5.0.dev2'

You can instead:

from version_query import generate_version_str

__version__ = generate_version_str()

how does it work

At development time, this will automatically infer the current version number based on:

  • tags

  • current commit SHA

  • index status

in your git repository. Therefore the package can be built and shipped to PyPI based only on status of the git repository.

If there is no git repository (this might be the case at installation time or at runtime) the script relies on package metadata from its PKG-INFO or metadata.json file.

One of PKG-INFO or metadata.json files is automatically-generated when building packages. Which one depends on your method of building, but in any case, one of them is packaged into source as well as binary distributions. One of them should be present for every Python 3 package.

how version is determined from git repository

First of all, a most recent (based on version precedence) version tag is found. Version tag is a git tag that starts with v or ver, followed by a valid version identifier.

Examples of valid version tags:

  • v1.0

  • v0.16.0

  • v1.0.dev3

The validity of the version identifier is determined by PEP 440.

If there are no version tags in the repo, the script simply assumes that initial commit has tag v0.1.0.dev0, and proceeds.

how version is incremented for a git repository

If current commit is not the one with the latest version tag, a suffix .dev# is appended to the version identifier, where # is the distance (number of commits) between the current commit and the latest version tag.

Additionally, the release number is incremented by 1. Release number here is defined as in major.minor.release, e.g. for version 1.2.3 release number is 3 and it would be assumed equal to 0 if not present.

Additionally, a plus (+) character and the first 8 characters of SHA of the latest commit are appended to version identifier, e.g. +a3014fe0.

Additionally, if there are any uncommitted changes in the repository (i.e. the repo is dirty), the suffix .dirty followed by current date and time in format YYYYMMDDhhmmss are appended to the identifier.

Example of how the final version identifier looks like, depending on various conditions of the repository:

  • Most recent version tag is v0.4.5, there were 2 commits since, latest having SHA starting with 812f12ea. Version identifier will be 0.4.6.dev2+812f12ea.

  • Most recent version tag is ver6.0, and there was 1 commit since having SHA starting with e10ac365. Version identifier will be 6.0.1.dev1+e10ac365.

  • Most recent version tag is v9, there were 40 commit since, latest having SHA starting with 1ad22355, the repository has uncommitted changes and version was queried at 19:52.20, 8th June 2017. the result is 9.0.1.dev40+1ad22355.dirty20170608195220.

how version is determined from PKG-INFO file

The version identifier is simply read from the package metadata file (i.e. the file named PKG-INFO) which should be present for any:

  • installed package

  • source distribution

  • binary distribution

  • source code folder of any package using setuptools, in which setup.py <build> was executed

limitations

Either git repository or PKG-INFO file must be present for the script to work.

The current implementation aims at, but is not yet fully compatible with:

Especially, in current implementation at most one of: alpha a / beta b / release candidate rc / development dev suffixes can be used in a version identifier.

And the format in which alpha a, beta b and release candidate rc suffixes are to be used does not match exactly the conditions defined in PEP.

requirements

Python version >= 3.4.

Python libraries as specified in requirements.txt.

Building and running tests additionally requires packages listed in test_requirements.txt.

Tested on Linux, OS X and Windows.

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

version-query-0.3.3.tar.gz (27.7 kB view details)

Uploaded Source

Built Distribution

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

version_query-0.3.3-py3-none-any.whl (24.5 kB view details)

Uploaded Python 3

File details

Details for the file version-query-0.3.3.tar.gz.

File metadata

  • Download URL: version-query-0.3.3.tar.gz
  • Upload date:
  • Size: 27.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for version-query-0.3.3.tar.gz
Algorithm Hash digest
SHA256 cc70dd4a67ad2bf9de5872efff24b28758c1276cf4fee597d20edcb668a520c2
MD5 48cbb8c46340db1caea94c383fbc1d79
BLAKE2b-256 fec90270bf7a659e9aecb299af128c1c7322a3f6f29aa839ad3c2f082433c0ab

See more details on using hashes here.

File details

Details for the file version_query-0.3.3-py3-none-any.whl.

File metadata

File hashes

Hashes for version_query-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 68edb37e4e3ee327222896a7053ee20711bfc85b3c6a1123ff76d4ee00d918fe
MD5 99529b54b51cfd4ed118fd5a420c3626
BLAKE2b-256 9d396fe1f792c60b9550fe0678cef229634cd90b183a881279ee5ee6fdd38ca9

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