pulumi/scripts/get-py-version
Joe Duffy 19e6c9c2bc
Fix Python versions (again) (#1106)
This change actually makes our Python version numbers conformant
to PEP440.  Previously we were including the Git commit hash in the
alpha "version number" part, which is incorrect.  This simply led to
warnings upon publication and installation, but that warning very
clearly states that support for invalid versions will stop at some
point.  This change puts any "informative" parts, like the Git hash,
inside of a local version tag, where such things are permitted.

Also move away from the inline sed silliness so that we can more
easily share this logic across all of our repos.
2018-04-02 10:31:05 -07:00

22 lines
792 B
Bash
Executable file

#!/bin/bash
set -o nounset -o errexit -o pipefail
SCRIPT_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# To generate a Python version, we will need to mangle it
# slightly. Namely, we must perform the following translations:
#
# 1) Skip the leading "v" (i.e., "1.3.11", not "v1.3.11").
# 2) Change "-dev-<xyz>" into an alpha release "a<xyz>".
# 3) Change "-rc-<xyz>" into a release candidate "rc<xyz>".
# 4) Change "-<commitish><dirty>" into a local version label;
# e.g. "+37bc2f9-dirty" rather than "-37bc2f9-dirty".
#
# This ensures conformance with PEP440:
# https://www.python.org/dev/peps/pep-0440/#version-scheme.
echo $($SCRIPT_ROOT/get-version "$@") | \
sed 's/v//' | \
sed 's/-dev-/a/' | \
sed 's/-rc-/rc/' | \
sed 's/-/+/'