58
62
'tools/pip-requires']):
60
64
for line in get_reqs_from_files(requirements_files):
65
# For the requirements list, we need to inject only the portion
66
# after egg= so that distutils knows the package it's looking for
68
# -e git://github.com/openstack/nova/master#egg=nova
61
69
if re.match(r'\s*-e\s+', line):
62
70
requirements.append(re.sub(r'\s*-e\s+.*#egg=(.*)$', r'\1',
73
# http://github.com/openstack/nova/zipball/master#egg=nova
74
elif re.match(r'\s*https?:', line):
75
requirements.append(re.sub(r'\s*https?:.*#egg=(.*)$', r'\1',
77
# -f lines are for index locations, and don't get used here
64
78
elif re.match(r'\s*-f\s+', line):
80
# argparse is part of the standard library starting with 2.7
81
# adding it to the requirements list screws distro installs
82
elif line == 'argparse' and sys.version_info >= (2, 7):
67
85
requirements.append(line)
72
90
def parse_dependency_links(requirements_files=['requirements.txt',
73
91
'tools/pip-requires']):
74
92
dependency_links = []
93
# dependency_links inject alternate locations to find packages listed
75
95
for line in get_reqs_from_files(requirements_files):
96
# skip comments and blank lines
76
97
if re.match(r'(\s*#)|(\s*$)', line):
99
# lines with -e or -f need the whole line, minus the flag
78
100
if re.match(r'\s*-[ef]\s+', line):
79
101
dependency_links.append(re.sub(r'\s*-[ef]\s+', '', line))
102
# lines that are only urls can go in unmolested
103
elif re.match(r'\s*https?:', line):
104
dependency_links.append(line)
80
105
return dependency_links
134
159
new_authors = 'AUTHORS'
135
160
if os.path.isdir('.git'):
136
161
# don't include jenkins email address in AUTHORS file
137
git_log_cmd = "git log --format='%aN <%aE>' | sort -u | " \
138
"grep -v " + jenkins_email
162
git_log_cmd = ("git log --format='%aN <%aE>' | sort -u | "
163
"grep -v " + jenkins_email)
139
164
changelog = _run_shell_command(git_log_cmd)
140
165
mailmap = parse_mailmap()
141
166
with open(new_authors, 'w') as new_authors_fh:
143
168
if os.path.exists(old_authors):
144
169
with open(old_authors, "r") as old_authors_fh:
145
170
new_authors_fh.write('\n' + old_authors_fh.read())
172
_rst_template = """%(heading)s
175
.. automodule:: %(module)s
183
"""Return dict of commands to run from setup.py."""
187
def _find_modules(arg, dirname, files):
188
for filename in files:
189
if filename.endswith('.py') and filename != '__init__.py':
190
arg["%s.%s" % (dirname.replace('/', '.'),
191
filename[:-3])] = True
193
class LocalSDist(sdist.sdist):
194
"""Builds the ChangeLog and Authors files from VC first."""
197
write_git_changelog()
199
# sdist.sdist is an old style class, can't use super()
200
sdist.sdist.run(self)
202
cmdclass['sdist'] = LocalSDist
204
# If Sphinx is installed on the box running setup.py,
205
# enable setup.py to build the documentation, otherwise,
208
from sphinx.setup_command import BuildDoc
210
class LocalBuildDoc(BuildDoc):
211
def generate_autoindex(self):
212
print "**Autodocumenting from %s" % os.path.abspath(os.curdir)
214
option_dict = self.distribution.get_option_dict('build_sphinx')
215
source_dir = os.path.join(option_dict['source_dir'][1], 'api')
216
if not os.path.exists(source_dir):
217
os.makedirs(source_dir)
218
for pkg in self.distribution.packages:
220
os.path.walk(pkg, _find_modules, modules)
221
module_list = modules.keys()
223
autoindex_filename = os.path.join(source_dir, 'autoindex.rst')
224
with open(autoindex_filename, 'w') as autoindex:
225
autoindex.write(""".. toctree::
229
for module in module_list:
230
output_filename = os.path.join(source_dir,
232
heading = "The :mod:`%s` Module" % module
233
underline = "=" * len(heading)
234
values = dict(module=module, heading=heading,
237
print "Generating %s" % output_filename
238
with open(output_filename, 'w') as output_file:
239
output_file.write(_rst_template % values)
240
autoindex.write(" %s.rst\n" % module)
243
if not os.getenv('SPHINX_DEBUG'):
244
self.generate_autoindex()
246
for builder in ['html', 'man']:
247
self.builder = builder
248
self.finalize_options()
249
self.project = self.distribution.get_name()
250
self.version = self.distribution.get_version()
251
self.release = self.distribution.get_version()
253
cmdclass['build_sphinx'] = LocalBuildDoc