From 5b0b59ed56abcd08b5a3f7fcf1af8639f9ef0a7c Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Sat, 5 May 2012 12:01:18 -0700 Subject: 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 --- openstack/common/setup.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'openstack') diff --git a/openstack/common/setup.py b/openstack/common/setup.py index 2c16b5b..4017890 100644 --- a/openstack/common/setup.py +++ b/openstack/common/setup.py @@ -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 -- cgit