-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathsetup.py
145 lines (116 loc) · 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
from setuptools import setup
from setuptools import Command
from distutils.command.build import build
from distutils.util import get_platform
import sys
import os
import re
import time
class my_build(build):
user_options = build.user_options
description = "build everything needed to install"
def gen_rpm_spec(self):
f1 = open('gerrymander.spec.in', 'r')
f2 = open('gerrymander.spec', 'w')
for line in f1:
f2.write(line
.replace('@PY_VERSION@', self.distribution.get_version()))
f1.close()
f2.close()
def gen_authors(self):
f = os.popen("git log --pretty=format:'%aN <%aE>'")
authors = []
for line in f:
authors.append(" " + line.strip())
authors.sort(key=str.lower)
f1 = open('AUTHORS.in', 'r')
f2 = open('AUTHORS', 'w')
for line in f1:
f2.write(line.replace('@AUTHORS@', "\n".join(set(authors))))
f1.close()
f2.close()
def gen_changelog(self):
f1 = os.popen("git log '--pretty=format:%H:%ct %an <%ae>%n%n%s%n%b%n'")
f2 = open("ChangeLog", 'w')
for line in f1:
m = re.match(r'([a-f0-9]+):(\d+)\s(.*)', line)
if m:
t = time.gmtime(int(m.group(2)))
f2.write("%04d-%02d-%02d %s\n" % (t.tm_year, t.tm_mon, t.tm_mday, m.group(3)))
else:
if re.match(r'Signed-off-by', line):
continue
f2.write(" " + line.strip() + "\n")
f1.close()
f2.close()
def run(self):
if not os.path.exists("build"):
os.mkdir("build")
if os.path.exists(".git"):
try:
self.gen_rpm_spec()
self.gen_authors()
self.gen_changelog()
build.run(self)
except:
files = ["gerrymander.spec",
"AUTHORS",
"ChangeLog"]
for f in files:
if os.path.exists(f):
os.unlink(f)
else:
build.run(self)
class my_test(Command):
user_options = [
('build-base=', 'b',
"base directory for build library"),
('build-platlib=', None,
"build directory for platform-specific distributions"),
('plat-name=', 'p',
"platform name to build for, if supported "
"(default: %s)" % get_platform()),
]
description = "Run test suite."
def initialize_options(self):
self.build_base = 'build'
self.build_platlib = None
self.plat_name = None
def finalize_options(self):
if self.plat_name is None:
self.plat_name = get_platform()
plat_specifier = ".%s-%s" % (self.plat_name, sys.version[0:3])
if hasattr(sys, 'gettotalrefcount'):
plat_specifier += '-pydebug'
if self.build_platlib is None:
self.build_platlib = os.path.join(self.build_base,
'lib' + plat_specifier)
def run(self):
"""
Run test suite
"""
if "PYTHONPATH" in os.environ:
os.environ["PYTHONPATH"] = self.build_platlib + ":" + os.environ["PYTHONPATH"]
else:
os.environ["PYTHONPATH"] = self.build_platlib
self.spawn([sys.executable, "/usr/bin/nosetests"])
setup(
name="gerrymander",
version="1.5",
description="A client API and command line tool for gerrit",
long_description="Gerrymander provides a set of APIs and command "
"line tool for interacting with the gerrit code review system",
author="Daniel P. Berrange",
author_email="[email protected]",
license="ASL 2.0",
url="https://github.com/berrange/gerrymander",
scripts=([
"scripts/gerrymander",
]),
packages=["gerrymander"],
install_requires=["prettytable>=0.5"],
cmdclass = {
'build': my_build,
'test': my_test
},
)