Skip to main content

Utility to aid in incrementing the semantic version of a Python package in an automated build

Project description

semantic_version_inator

Utility to aid in incrementing the semantic version of a Python package in an automated build.

How to use:

Set up CI/CD pipeline/workflow to set parameters: release_type and current_version

The release_type parameter should have a default value of PATCH, with an option to set as MINOR or MAJOR as appropriate. This param could be user selectable when manually triggering a build, or could be automated if a means of programatically determining type of release is possible.

The current_version parameter must be derrived from the latest published package version. One option is to download the latest (i.e. pip download) and parse the file name from the file.

Installing this package installs two console commands, each taking the two arguments noted above:

get_next_ver_file_name is a convenience function, intended to parse the current version from a pakcage file name, i.e. pkg_name-0.0.0-py3-none-any.whl:

example input:

get_next_ver_file_name pkg_name-0.0.0-py3-none-any.whl PATCH

example output:

0.0.1

get_next_ver is an alternative to the above in case the above does not handle a given package name well, or if the version is obtained independently of the current version package file name. It is intended to receive the current semantic version (not file name), i.e. 0.0.0:

example input:

get_next_ver 0.0.0 PATCH

example output:

0.0.1

Set the new version number as an environment variable, which setup.py can use, i.e.:

PKG_VERSION = "0.0.0"
try:
    new_ver = os.environ["new_ver"]
    if new_ver:
        PKG_VERSION = new_ver
    else:
        print("new_ver not found, using PKG_VERSION default:", PKG_VERSION)
except KeyError:
    print("new_ver not found, using PKG_VERSION default:", PKG_VERSION)

setup(
    ...
    version=PKG_VERSION,
    ...
)

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

semantic_version_inator-0.0.1-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file semantic_version_inator-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for semantic_version_inator-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 93402ccb13e03e6f069865638e4a3508397f9e3056c7a477abeb000591741969
MD5 35487474d8fbfd67ddf5cfda587dc74d
BLAKE2b-256 d52e9e3a72e78ff3efebc008d75a846f6950a783b3e74d3c914adce39871516c

See more details on using hashes here.

Supported by

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