~corey.bryant/python-keystoneclient/1.6.0

« back to all changes in this revision

Viewing changes to keystoneclient/openstack/common/setup.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-06-22 12:58:18 UTC
  • mfrom: (1.1.11)
  • Revision ID: package-import@ubuntu.com-20120622125818-yy6uzmhxu12q20cr
Tags: 2012.2~f2~20120621.121-0ubuntu
New upstream release. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import os
23
23
import re
24
24
import subprocess
 
25
import sys
 
26
 
 
27
from setuptools.command import sdist
25
28
 
26
29
 
27
30
def parse_mailmap(mailmap='.mailmap'):
31
34
        for l in fp:
32
35
            l = l.strip()
33
36
            if not l.startswith('#') and ' ' in l:
34
 
                canonical_email, alias = l.split(' ')
 
37
                canonical_email, alias = [x for x in l.split(' ')
 
38
                                          if x.startswith('<')]
35
39
                mapping[alias] = canonical_email
36
40
    return mapping
37
41
 
58
62
                                           'tools/pip-requires']):
59
63
    requirements = []
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
 
67
        # such as:
 
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',
63
71
                                line))
 
72
        # such as:
 
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',
 
76
                                line))
 
77
        # -f lines are for index locations, and don't get used here
64
78
        elif re.match(r'\s*-f\s+', line):
65
79
            pass
 
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):
 
83
            pass
66
84
        else:
67
85
            requirements.append(line)
68
86
 
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
 
94
    # in requirements
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):
77
98
            continue
 
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
81
106
 
82
107
 
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())
 
171
 
 
172
_rst_template = """%(heading)s
 
173
%(underline)s
 
174
 
 
175
.. automodule:: %(module)s
 
176
  :members:
 
177
  :undoc-members:
 
178
  :show-inheritance:
 
179
"""
 
180
 
 
181
 
 
182
def get_cmdclass():
 
183
    """Return dict of commands to run from setup.py."""
 
184
 
 
185
    cmdclass = dict()
 
186
 
 
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
 
192
 
 
193
    class LocalSDist(sdist.sdist):
 
194
        """Builds the ChangeLog and Authors files from VC first."""
 
195
 
 
196
        def run(self):
 
197
            write_git_changelog()
 
198
            generate_authors()
 
199
            # sdist.sdist is an old style class, can't use super()
 
200
            sdist.sdist.run(self)
 
201
 
 
202
    cmdclass['sdist'] = LocalSDist
 
203
 
 
204
    # If Sphinx is installed on the box running setup.py,
 
205
    # enable setup.py to build the documentation, otherwise,
 
206
    # just ignore it
 
207
    try:
 
208
        from sphinx.setup_command import BuildDoc
 
209
 
 
210
        class LocalBuildDoc(BuildDoc):
 
211
            def generate_autoindex(self):
 
212
                print "**Autodocumenting from %s" % os.path.abspath(os.curdir)
 
213
                modules = {}
 
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:
 
219
                    if '.' not in pkg:
 
220
                        os.path.walk(pkg, _find_modules, modules)
 
221
                module_list = modules.keys()
 
222
                module_list.sort()
 
223
                autoindex_filename = os.path.join(source_dir, 'autoindex.rst')
 
224
                with open(autoindex_filename, 'w') as autoindex:
 
225
                    autoindex.write(""".. toctree::
 
226
   :maxdepth: 1
 
227
 
 
228
""")
 
229
                    for module in module_list:
 
230
                        output_filename = os.path.join(source_dir,
 
231
                                                       "%s.rst" % module)
 
232
                        heading = "The :mod:`%s` Module" % module
 
233
                        underline = "=" * len(heading)
 
234
                        values = dict(module=module, heading=heading,
 
235
                                      underline=underline)
 
236
 
 
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)
 
241
 
 
242
            def run(self):
 
243
                if not os.getenv('SPHINX_DEBUG'):
 
244
                    self.generate_autoindex()
 
245
 
 
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()
 
252
                    BuildDoc.run(self)
 
253
        cmdclass['build_sphinx'] = LocalBuildDoc
 
254
    except ImportError:
 
255
        pass
 
256
 
 
257
    return cmdclass