setup.py
changeset 14538 3818c67a501e
parent 14324 d3a49a52f117
child 14973 5656cb5b9028
child 15163 f4bc0b9e03a4
--- a/setup.py	Mon Jun 06 21:02:48 2011 +0200
+++ b/setup.py	Sat Jun 04 20:11:10 2011 +0900
@@ -56,7 +56,7 @@
 import shutil
 import tempfile
 from distutils import log
-from distutils.core import setup, Extension
+from distutils.core import setup, Command, Extension
 from distutils.dist import Distribution
 from distutils.command.build import build
 from distutils.command.build_ext import build_ext
@@ -64,7 +64,7 @@
 from distutils.command.install_scripts import install_scripts
 from distutils.spawn import spawn, find_executable
 from distutils.ccompiler import new_compiler
-from distutils.errors import CCompilerError
+from distutils.errors import CCompilerError, DistutilsExecError
 from distutils.sysconfig import get_python_inc
 from distutils.version import StrictVersion
 
@@ -260,6 +260,34 @@
             else:
                 yield module
 
+class buildhgextindex(Command):
+    description = 'generate prebuilt index of hgext (for frozen package)'
+    user_options = []
+    _indexfilename = 'hgext/__index__.py'
+
+    def initialize_options(self):
+        pass
+
+    def finalize_options(self):
+        pass
+
+    def run(self):
+        if os.path.exists(self._indexfilename):
+            os.unlink(self._indexfilename)
+
+        # here no extension enabled, disabled() lists up everything
+        code = ('import pprint; from mercurial import extensions; '
+                'pprint.pprint(extensions.disabled())')
+        out, err = runcmd([sys.executable, '-c', code], env)
+        if err:
+            raise DistutilsExecError(err)
+
+        f = open(self._indexfilename, 'w')
+        f.write('# this file is autogenerated by setup.py\n')
+        f.write('docs = ')
+        f.write(out)
+        f.close()
+
 class hginstallscripts(install_scripts):
     '''
     This is a specialization of install_scripts that replaces the @LIBDIR@ with
@@ -309,6 +337,7 @@
 cmdclass = {'build_mo': hgbuildmo,
             'build_ext': hgbuildext,
             'build_py': hgbuildpy,
+            'build_hgextindex': buildhgextindex,
             'install_scripts': hginstallscripts}
 
 packages = ['mercurial', 'mercurial.hgweb',
@@ -373,6 +402,8 @@
         {'script':'hg',
          'copyright':'Copyright (C) 2005-2010 Matt Mackall and others',
          'product_version':version}]
+    # sub command of 'build' because 'py2exe' does not handle sub_commands
+    build.sub_commands.insert(0, ('build_hgextindex', None))
 
 if os.name == 'nt':
     # Windows binary file versions for exe/dll files must have the