From d207df9e40a0c9deb8dee38d9b6b1b809d98ec18 Mon Sep 17 00:00:00 2001 From: Ross McFarland Date: Sun, 27 Mar 2022 07:34:08 -0700 Subject: [PATCH] Implement pep440 style public and local version numbers --- script/release | 3 +++ setup.py | 22 +++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/script/release b/script/release index 975aac2..ea2543b 100755 --- a/script/release +++ b/script/release @@ -16,6 +16,9 @@ if [ ! -f "$ACTIVATE" ]; then fi . "$ACTIVATE" +# Set so that setup.py will create a public release style version number +export OCTODNS_RELEASE=1 + VERSION="$(grep __VERSION__ "$ROOT/octodns/__init__.py" | sed -e "s/.* = '//" -e "s/'$//")" git tag -s "v$VERSION" -m "Release $VERSION" diff --git a/setup.py b/setup.py index 4e5d631..2aa6407 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,9 @@ #!/usr/bin/env python -try: - from StringIO import StringIO -except ImportError: - from io import StringIO +from io import StringIO +from os import environ from os.path import dirname, join +from subprocess import CalledProcessError, check_output import octodns try: @@ -55,6 +54,19 @@ def long_description(): return buf.getvalue() +def version(): + # pep440 style public & local version numbers + if environ.get('OCTODNS_RELEASE', False): + # public + return octodns.__VERSION__ + try: + sha = check_output(['git', 'rev-parse', 'HEAD']).decode('utf-8')[:8] + except (CalledProcessError, FileNotFoundError): + sha = 'unknown' + # local + return f'{octodns.__VERSION__}+{sha}' + + tests_require = ( 'pytest>=6.2.5', 'pytest-cov>=3.0.0', @@ -94,5 +106,5 @@ setup( python_requires='>=3.6', tests_require=tests_require, url='https://github.com/octodns/octodns', - version=octodns.__VERSION__, + version=version(), )