Browse Source

include git commit count in version and update in setup.py

master
j 7 years ago
parent
commit
2a7e292dff
  1. 1
      .gitignore
  2. 24
      setup.py
  3. 33
      shared/people/__init__.py

1
.gitignore vendored

@ -9,3 +9,4 @@ build
dist
htmlcov
__pycache__
_version.py

24
setup.py

@ -1,14 +1,30 @@
#!/usr/bin/env python
import os
from io import open
from setuptools import find_packages, setup
import os
import re
import subprocess
def get_version(prefix):
import re
with open(os.path.join(prefix, '__init__.py')) as fd:
metadata = dict(re.findall("__([a-z]+)__ = '([^']+)'", fd.read()))
if os.path.exists('.git'):
parts = subprocess.check_output(['git', 'describe', '--tags']).decode().strip().split('-')
version = '{}.{}+{}'.format(*parts)
version_py = "__version__ = '{}'".format(version)
_version = os.path.join(prefix, '_version.py')
if not os.path.exists(_version) or open(_version).read().strip() != version_py:
with open(_version, 'w') as fd:
fd.write(version_py)
return version
else:
for f in ('_version.py', '__init__.py'):
f = os.path.join(prefix, f)
if os.path.exists(f):
with open(f) as fd:
metadata = dict(re.findall("__([a-z]+)__ = '([^']+)'", fd.read()))
if 'version' in metadata:
break
return metadata['version']

33
shared/people/__init__.py

@ -1,32 +1,11 @@
import subprocess
__version__ = '0.0'
try:
git_describe = subprocess.check_output(['git', 'describe', '--tags'], universal_newlines=True, stderr=subprocess.DEVNULL).strip()
# v0.2-69-g181f854
if git_describe[0] in "vr":
git_describe = git_describe[1:]
parts = git_describe.split("-")
VERSION = parts[0].split(".")[:3]
VERSION += [0] * (3 - len(VERSION))
git_version = parts[1:]
except subprocess.CalledProcessError:
# Not yet tagged
VERSION = [0, 0, 0]
git_version = []
try:
git_version = (
subprocess.check_output(['git', 'rev-list', '--count', 'HEAD'], universal_newlines=True).strip(),
subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'], universal_newlines=True).strip()
)
except subprocess.CalledProcessError:
git_version = []
# 1.3.0-64-g1f9a30
__version__ = '-'.join(map(str, ['.'.join(map(str, VERSION)), *git_version]))
VERSION.extend(git_version)
from ._version import __version__
except ImportError:
pass
VERSION = __version__.split('+')
VERSION = tuple(list(map(int, VERSION[0].split('.'))) + VERSION[1:])
default_app_config = 'people.apps.PeopleConfig'

Loading…
Cancel
Save