forked from david-caro/python-foreman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·61 lines (45 loc) · 1.4 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
#!/usr/bin/env python
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():
"""
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
"""
version = None
if os.path.exists('PKG-INFO'):
with open('PKG-INFO') as info_fd:
for line in info_fd.readlines():
if line.startswith('Version: '):
version = line.split(' ', 1)[-1]
elif os.path.exists('scripts/generate_version.sh'):
version = check_output(['scripts/generate_version.sh']).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
os.environ['PBR_VERSION'] = get_version()
setup(
setup_requires=['pbr'],
pbr=True,
)