# HG changeset patch # User Yuya Nishihara # Date 2011-06-04 11:11:10 # Node ID 3818c67a501edad38a9f2c35433c5de45c7e2d01 # Parent 3c7907dc95ca4f0e127631df180215d21af4d00a 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