[PATCH] extensions: extract official descriptions at build time

Cédric Duval cedricduval at free.fr
Sun Jul 5 03:56:50 CDT 2009


# HG changeset patch
# User Cédric Duval <cedricduval at free.fr>
# Date 1246176984 -7200
# Node ID cc224a2eb698efb88687cf38cbfd714fa5e99855
# Parent  3e37e122ff7f4214fd8138f9854cf91c2ec74047
extensions: extract official descriptions at build time

A python module containing the descriptions of each official extension
is generated at build time, and updated in case any of the files from
which descriptions are extracted has been modified.

diff --git a/.hgignore b/.hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -24,6 +24,7 @@
 doc/*.[0-9].{x,ht}ml
 MANIFEST
 patches
+mercurial/extdoc_list.py
 mercurial/__version__.py
 Output/Mercurial-*.exe
 .DS_Store
diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -26,7 +26,11 @@
 all: build doc
 
 local:
-	$(PYTHON) setup.py $(PURE) build_py -c -d . build_ext -i build_mo
+	$(PYTHON) setup.py $(PURE) \
+	    build_extensions_list \
+	    build_py -c -d . \
+	    build_ext -i \
+	    build_mo
 	$(PYTHON) hg version
 
 build:
@@ -39,6 +43,7 @@
 	-$(PYTHON) setup.py clean --all # ignore errors from this command
 	find . -name '*.py[cdo]' -exec rm -f '{}' ';'
 	rm -f MANIFEST mercurial/__version__.py mercurial/*.so tests/*.err
+	rm -f mercurial/extdoc_list.py
 	rm -rf locale
 	$(MAKE) -C doc clean
 
@@ -63,7 +68,7 @@
 
 MANIFEST: MANIFEST-doc
 	hg manifest > MANIFEST
-	echo mercurial/__version__.py >> MANIFEST
+	echo mercurial/__version__.py mercurial/extdoc_list.py >> MANIFEST
 	cat doc/MANIFEST >> MANIFEST
 
 dist:	tests dist-notests
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -29,6 +29,7 @@
 import os, subprocess, time
 import shutil
 import tempfile
+from mercurial import extdoc
 from distutils.core import setup, Extension
 from distutils.dist import Distribution
 from distutils.command.install_data import install_data
@@ -161,6 +162,26 @@
                                    ('install_lib', 'install_dir'))
         install_data.finalize_options(self)
 
+class build_extensions_list(build):
+
+    description = "build the list of Mercurial extensions"
+    target = os.path.join('mercurial', 'extdoc_list.py')
+
+    def generate(self):
+        '''write the descriptions dict to the target file'''
+        descs = extdoc.extract('hgext', raw=True)
+        f = file(self.target, 'w')
+        f.write('# this file is autogenerated by setup.py\n\n')
+        f.write('descriptions = ' + repr(descs) + '\n')
+        f.close()
+
+    def run(self):
+        '''(re)generate target if some extension sources are more recent'''
+        deps = extdoc.files('hgext').values()
+        self.make_file(deps, self.target, self.generate, [])
+
+build.sub_commands.insert(0, ('build_extensions_list', None))
+
 class build_mo(build):
 
     description = "build translations (.mo files)"
@@ -221,6 +242,7 @@
                 yield module
 
 cmdclass = {'install_data': install_package_data,
+            'build_extensions_list': build_extensions_list,
             'build_mo': build_mo,
             'build_py': hg_build_py}
 



More information about the Mercurial-devel mailing list