[PATCH 1 of 2 RFC] setup: add command to generate index of extensions
Yuya Nishihara
yuya at tcha.org
Sat Jun 4 12:19:19 UTC 2011
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1307185870 -32400
# Node ID 994c340d811360674aa046e4a4c923db615779b4
# Parent dbd460d16667f8c7a4499361538e94407462f3f7
setup: add command to generate index of extensions
It generates prebuilt index of all extensions, which will be used by
frozen exe when running 'hg help extensions'.
Now py2exe invokes this command automatically.
diff --git a/.hgignore b/.hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -35,6 +35,7 @@ tags
cscope.*
i18n/hg.pot
locale/*/LC_MESSAGES/hg.mo
+hgext/__index__.py
# files installed with a local --pure build
mercurial/base85.py
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -56,7 +56,7 @@ import os, subprocess, time
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.build_py import b
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 @@ class hgbuildpy(build_py):
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 @@ class hginstallscripts(install_scripts):
cmdclass = {'build_mo': hgbuildmo,
'build_ext': hgbuildext,
'build_py': hgbuildpy,
+ 'build_hgextindex': buildhgextindex,
'install_scripts': hginstallscripts}
packages = ['mercurial', 'mercurial.hgweb',
@@ -373,6 +402,8 @@ if py2exeloaded:
{'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
More information about the Mercurial-devel
mailing list