diff options
author | Monty Taylor <mordred@inaugust.com> | 2012-05-05 12:01:18 -0700 |
---|---|---|
committer | Monty Taylor <mordred@inaugust.com> | 2012-05-06 11:42:56 -0700 |
commit | 03893be94bdb95b051a00412357adce6ddec1322 (patch) | |
tree | 05e789c9f8c91e174ae25b67fc6f1fafbb81f053 /setup.py | |
parent | 51c2ee33fe1388536526015acbef51cf5899b3d0 (diff) | |
download | pbr-03893be94bdb95b051a00412357adce6ddec1322.tar.gz |
Encapsulate common sdist actions into a cmdclass.
The pattern of running generate_authors and write_git_changelog
at sdist time is (and should be) repeated in all project's setup.py.
Instead of copying the creation of the two classes and injection
of them into a cmdclass dict, we can do it here and have it
be consistent.
Related to bug 986462.
Change-Id: I0b7b44d58685551482f874b2a6091dec29e6bed6
Diffstat (limited to 'setup.py')
-rw-r--r-- | setup.py | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -23,6 +23,8 @@ import os import re import subprocess +from setuptools.command import sdist + def parse_mailmap(mailmap='.mailmap'): mapping = {} @@ -144,3 +146,38 @@ def generate_authors(): if os.path.exists(old_authors): with open(old_authors, "r") as old_authors_fh: new_authors_fh.write('\n' + old_authors_fh.read()) + + +def get_cmdclass(): + """Return dict of commands to run from setup.py.""" + + cmdclass = dict() + + class LocalSDist(sdist.sdist): + """Builds the ChangeLog and Authors files from VC first.""" + + def run(self): + write_git_changelog() + generate_authors() + # sdist.sdist is an old style class, can't use super() + sdist.sdist.run(self) + + cmdclass['sdist'] = LocalSDist + + # If Sphinx is installed on the box running setup.py, + # enable setup.py to build the documentation, otherwise, + # just ignore it + try: + from sphinx.setup_command import BuildDoc + + class LocalBuildDoc(BuildDoc): + def run(self): + for builder in ['html', 'man']: + self.builder = builder + self.finalize_options() + BuildDoc.run(self) + cmdclass['build_sphinx'] = LocalBuildDoc + except ImportError: + pass + + return cmdclass |