[PATCH]Support for py2exe

Volker Kleinfeld volker.kleinfeld at gmx.de
Mon Aug 22 03:54:26 CDT 2005


> Looks good except for Windows line-ending.

Hi,
fixed the line ending.

Volker

-- 
Lust, ein paar Euro nebenbei zu verdienen? Ohne Kosten, ohne Risiko!
Satte Provisionen für GMX Partner: http://www.gmx.net/de/go/partner
-------------- next part --------------
# HG changeset patch
# User Volker.Kleinfeld at gmx.de
# Node ID 0f228e63d465b26f799b62674a1abc1cef46c9c6
# Parent  4cabedfab66eaaff5e2f36739ca6823c4402a4c8
Support for py2exe on windows added.

diff -r 4cabedfab66e -r 0f228e63d465 setup.py
--- a/setup.py	Fri Aug 19 14:41:29 2005
+++ b/setup.py	Sun Aug 21 18:31:16 2005
@@ -10,6 +10,20 @@
 from distutils.command.install_data import install_data
 
 import mercurial.version
+
+includes = []
+# py2exe needs to be installed to work
+try:
+    import py2exe 
+    import mercurial.packagescan 
+
+    # Due to the use of demandload py2exe is not finding the modules
+    # getModules creates a list of modules in the mercurial package.
+    # This works only if the *.pyd files are in the mercurial dir.
+    includes = mercurial.packagescan.getModules('mercurial')
+except: pass
+print "Found the following modules:",includes
+
 
 # specify version string, otherwise 'hg identify' will be used:
 version = ''
@@ -37,6 +51,8 @@
                        glob.glob('templates/map-*') +
                        glob.glob('templates/*.tmpl'))],
           cmdclass = { 'install_data' : install_package_data },
-          scripts=['hg', 'hgmerge'])
+          scripts=['hg', 'hgmerge'],
+          console = ['hg'],
+          options = {'py2exe':{'includes':includes}})
 finally:
     mercurial.version.forget_version()
diff -r 4cabedfab66e -r 0f228e63d465 mercurial/packagescan.py
--- /dev/null	Fri Aug 19 14:41:29 2005
+++ b/mercurial/packagescan.py	Sun Aug 21 18:31:16 2005
@@ -0,0 +1,49 @@
+# packagescan.py - Helper module for identifing used modules. Used for the py2exe distutil.
+#
+# Copyright 2005 Volker Kleinfeld <Volker.Kleinfeld at gmx.de>
+#
+# This software may be used and distributed according to the terms
+# of the GNU General Public License, incorporated herein by reference.
+
+import glob
+import os
+import sys
+import demandload
+
+required_modules = {} # Will contain the modules imported by demandload
+def demandload(scope, modules):
+    """ Fake demandload function that collects the required modules. """
+    for m in modules.split():
+        mod = None
+        mod = __import__(m,scope,scope)
+        scope[m] = mod
+        required_modules[mod.__name__] = 1
+
+def getModules(packageName):
+    """ Helper for finding all required modules of package <packageName>. """
+    # Fetch the python modules in the mercurial package
+    tmp = {}
+    packageFile = __import__(packageName,tmp,tmp)
+    cwd = os.getcwd()
+    packdir = os.path.dirname(packageFile.__file__)
+    os.chdir(packdir)
+    pyModuleFiles = glob.glob('*.py')
+    extModuleFiles = glob.glob('*.pyd')
+    os.chdir(cwd)
+    # Install the fake demandload module
+    sys.modules['mercurial.demandload'] = sys.modules['mercurial.packagescan']
+    # Import all python modules and by that run the fake demandload
+    for m in pyModuleFiles:
+        if m == '__init__.py': continue
+        tmp = {}
+        fullName = packageName+'.'+m[:-3] # Take of .py
+        __import__(fullName,tmp,tmp)
+        required_modules[fullName] = 1
+    # Import all extension modules and by that run the fake demandload
+    for m in extModuleFiles:
+        tmp = {}
+        fullName = packageName+'.'+m[:-4] # Take of .pyd
+        __import__(fullName,tmp,tmp)
+        required_modules[fullName] = 1
+    includes = required_modules.keys()
+    return includes


More information about the Mercurial mailing list