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.
This commit is contained in:
Shane McDonald
2017-07-25 10:54:42 -04:00
parent 0cf376ca6f
commit 7695cb6419
4 changed files with 16 additions and 5 deletions

View File

@@ -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"):