From 7695cb6419238c9d48c878c094b722fa82633599 Mon Sep 17 00:00:00 2001 From: Shane McDonald Date: Tue, 25 Jul 2017 10:54:42 -0400 Subject: [PATCH] Fix version when installing from sdist When installing an sdist, setup.py is invoked on the machine you're installing on. We extract the version from a git tag, but the repo is not included in the sdist. The git describe --long command will silently fail and cause the installed package to report version 0.0.0.0. --- .gitignore | 1 + MANIFEST.in | 1 + Makefile | 8 ++++++-- setup.py | 11 ++++++++--- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 8bab4577ad..ee2a0211ce 100644 --- a/.gitignore +++ b/.gitignore @@ -107,6 +107,7 @@ local/ *.mo requirements/vendor .i18n_built +VERSION # AWX python libs populated by requirements.txt awx/lib/.deps_built diff --git a/MANIFEST.in b/MANIFEST.in index 81483cee39..b65d4b5b3a 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -22,6 +22,7 @@ include tools/scripts/failure-event-handler include tools/scripts/tower-python include awx/playbooks/library/mkfifo.py include tools/sosreport/* +include VERSION include COPYING include Makefile prune awx/public diff --git a/Makefile b/Makefile index a36cfee834..c4ab38102a 100644 --- a/Makefile +++ b/Makefile @@ -86,7 +86,7 @@ UI_RELEASE_FLAG_FILE = awx/ui/.release_built reprepro setup_tarball virtualbox-ovf virtualbox-centos-7 \ virtualbox-centos-6 clean-bundle setup_bundle_tarball \ ui-docker-machine ui-docker ui-release ui-devel \ - ui-test ui-deps ui-test-ci ui-test-saucelabs jlaska + ui-test ui-deps ui-test-ci ui-test-saucelabs jlaska VERSION # remove ui build artifacts clean-ui: @@ -117,6 +117,7 @@ clean: clean-ui clean-dist rm -rf requirements/vendor rm -rf tmp rm -rf $(I18N_FLAG_FILE) + rm -f VERSION mkdir tmp rm -rf build $(NAME)-$(VERSION) *.egg-info find . -type f -regex ".*\.py[co]$$" -delete @@ -535,7 +536,7 @@ dev_build: release_build: $(PYTHON) setup.py release_build -dist/$(SDIST_TAR_FILE): ui-release +dist/$(SDIST_TAR_FILE): ui-release VERSION BUILD="$(BUILD)" $(PYTHON) setup.py $(SDIST_COMMAND) dist/$(WHEEL_FILE): ui-release @@ -621,3 +622,6 @@ clean-elk: psql-container: docker run -it --net tools_default --rm postgres:9.4.1 sh -c 'exec psql -h "postgres" -p "5432" -U postgres' + +VERSION: + echo $(RELEASE_VERSION) > $@ diff --git a/setup.py b/setup.py index 5aa7b36447..9dde802e7c 100755 --- a/setup.py +++ b/setup.py @@ -7,7 +7,6 @@ import os import glob import sys import subprocess -import re from setuptools import setup from distutils.command.sdist import sdist @@ -26,8 +25,14 @@ else: def get_version(): - ver = subprocess.Popen("git describe --long | cut -f1-1 -d -", shell=True, stdout=subprocess.PIPE).stdout.read().strip() - return re.sub(r'-([0-9]+)-.*', r'.\1', ver) + current_dir = os.path.dirname(os.path.abspath(__file__)) + version_file = os.path.join(current_dir, 'VERSION') + if os.path.isfile(version_file): + with open(version_file, 'r') as file: + version = file.read().strip() + else: + version = subprocess.Popen("git describe --long | cut -d - -f 1-1", shell=True, stdout=subprocess.PIPE).stdout.read().strip() + return version if os.path.exists("/etc/debian_version"):