-
Notifications
You must be signed in to change notification settings - Fork 39
/
setup.py
63 lines (50 loc) · 1.72 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
import subprocess
from setuptools import setup
def check_output(args):
proc = subprocess.Popen(
args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, stderr = proc.communicate()
if proc.returncode:
raise RuntimeError(
'Failed to run %s\nrc=%s\nstdout=\n%sstderr=%s' %
(args, proc.returncode, stdout, stderr)
)
return stdout
def get_version(project_dir=os.curdir):
"""
Retrieves the version of the package, from the PKG-INFO file or generates
it with the version script
Returns:
str: Version for the package
Raises:
RuntimeError: If the version could not be retrieved
"""
if 'LAGO_VERSION' in os.environ and os.environ['LAGO_VERSION']:
return os.environ['LAGO_VERSION']
version = None
pkg_info_file = os.path.join(project_dir, 'PKG-INFO')
version_manager = os.path.join(project_dir, 'scripts/version_manager.py')
if os.path.exists(pkg_info_file):
with open(pkg_info_file) as info_fd:
for line in info_fd.readlines():
if line.startswith('Version: '):
version = line.split(' ', 1)[-1]
elif os.path.exists(version_manager):
version = check_output([version_manager, project_dir,
'version']).strip()
if version is None:
raise RuntimeError('Failed to get package version')
# py3 compatibility step
if not isinstance(version, str) and isinstance(version, bytes):
version = version.decode()
return version
if __name__ == '__main__':
os.environ['PBR_VERSION'] = get_version()
setup(
setup_requires=['pbr', 'dulwich'],
pbr=True,
)