setup: update get_version for python 3 (#38094)

This commit is contained in:
Frédéric Péters 2019-11-26 13:53:25 +01:00
parent 49407ef0e4
commit 32af20ac95
1 changed files with 25 additions and 12 deletions

View File

@ -10,21 +10,34 @@ from distutils.command.sdist import sdist
from setuptools.command.install_lib import install_lib as _install_lib
from setuptools import setup
VERSION = '1.20'
def get_version():
'''Use the VERSION, if absent generates a version with git describe, if not
tag exists, take 0.0- and add the length of the commit log.
'''
if os.path.exists('VERSION'):
version_file = open('VERSION', 'r')
version = version_file.read()
version_file.close()
return version
with open('VERSION', 'r') as v:
return v.read()
if os.path.exists('.git'):
p = subprocess.Popen(['git','describe','--match=v*'], stdout=subprocess.PIPE)
p = subprocess.Popen(
['git', 'describe', '--dirty=.dirty', '--match=v*'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
result = p.communicate()[0]
version = result.split()[0][1:]
version = version.replace('-','.')
return version
return VERSION
if p.returncode == 0:
result = result.decode('ascii').strip()[1:] # strip spaces/newlines and initial v
if '-' in result: # not a tagged version
real_number, commit_count, commit_hash = result.split('-', 2)
version = '%s.post%s+%s' % (real_number, commit_count, commit_hash)
else:
version = result
return version
else:
return '0.0.post%s' % len(
subprocess.check_output(
['git', 'rev-list', 'HEAD']).splitlines())
return '0.0'
def data_tree(destdir, sourcedir):
extensions = ['.css', '.png', '.jpeg', '.jpg', '.xml', '.html', '.js', '.ezt', '.gif', '.otf']
@ -76,7 +89,7 @@ class install_lib(_install_lib):
class eo_sdist(sdist):
def run(self):
print "creating VERSION file"
print("creating VERSION file")
if os.path.exists('VERSION'):
os.remove('VERSION')
version = get_version()
@ -84,7 +97,7 @@ class eo_sdist(sdist):
version_file.write(version)
version_file.close()
sdist.run(self)
print "removing VERSION file"
print("removing VERSION file")
if os.path.exists('VERSION'):
os.remove('VERSION')