[PATCH V2] setup: build docs from setup.py

Kevin Bullock kbullock+mercurial at ringworld.org
Thu Sep 4 13:17:16 CDT 2014


# HG changeset patch
# User Kevin Bullock <kbullock at ringworld.org>
# Date 1404923562 18000
#      Wed Jul 09 11:32:42 2014 -0500
# Node ID f882f3877921866af3da9dcf4d8502379ef7b351
# Parent  c5df4af17110838b713d6c9ec3b824fb0b6c1b33
setup: build docs from setup.py

This patch enables the use of bdist_mpkg to build a Mercurial package
for Mac OS X that includes the documentation. I've been using a version
of this locally for several years to build my own packages before the
official Mac OS X versions appear, and these packages seem to be
indistinguishable from the official ones.

This version of the patch looks for docutils and only tries to build the
documentation if it's installed, so that `make install-bin` continues to
work in the absence of docutils.

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -168,6 +168,13 @@ def runhg(cmd, env):
         return ''
     return out
 
+try:
+    # Only include the docs if we can build them
+    from docutils import __version__ as docutilsver
+    builddocs = True
+except ImportError:
+    builddocs = False
+
 version = ''
 
 # Execute hg out of this directory with a custom environment which
@@ -232,8 +239,10 @@ class hgbuild(build):
     # thinking that those modules are global and, consequently, making
     # a mess, now that all module imports are global.
 
-                    ('build_ext', build.has_ext_modules),
-                   ] + build.sub_commands
+                    ('build_ext', build.has_ext_modules)]
+    if builddocs:
+        sub_commands.append(('build_doc', None))
+    sub_commands += build.sub_commands
 
 class hgbuildmo(build):
 
@@ -322,6 +331,19 @@ class hgbuildpy(build_py):
             else:
                 yield module
 
+class hgbuilddoc(Command):
+    description = 'Build documentation in doc/ (manpages)'
+    user_options = []
+
+    def initialize_options(self):
+        pass
+
+    def finalize_options(self):
+        pass
+
+    def run(self):
+        self.spawn(['make', '-C', 'doc'])
+
 class buildhgextindex(Command):
     description = 'generate prebuilt index of hgext (for frozen package)'
     user_options = []
@@ -425,6 +447,7 @@ cmdclass = {'build': hgbuild,
             'build_mo': hgbuildmo,
             'build_ext': hgbuildext,
             'build_py': hgbuildpy,
+            'build_doc': hgbuilddoc,
             'build_hgextindex': buildhgextindex,
             'install_scripts': hginstallscripts,
             'build_hgexe': buildhgexe,
@@ -498,6 +521,10 @@ datafiles = []
 setupversion = version
 extra = {}
 
+if builddocs:
+    datafiles += [('man/man1', ['doc/hg.1']),
+                  ('man/man5', ['doc/hgignore.5', 'doc/hgrc.5'])]
+
 if py2exeloaded:
     extra['console'] = [
         {'script':'hg',


More information about the Mercurial-devel mailing list