##// END OF EJS Templates
merge with crew.
Vadim Gelfer -
r2327:185cb7ff merge default
parent child Browse files
Show More
@@ -1,5 +1,6 b''
1 1 # packagescan.py - Helper module for identifing used modules.
2 2 # Used for the py2exe distutil.
3 # This module must be the first mercurial module imported in setup.py
3 4 #
4 5 # Copyright 2005 Volker Kleinfeld <Volker.Kleinfeld@gmx.de>
5 6 #
@@ -8,25 +9,58 b''
8 9 import glob
9 10 import os
10 11 import sys
11 import demandload
12 12 import ihooks
13 import types
14 import string
15
16 # Install this module as fake demandload module
17 sys.modules['mercurial.demandload'] = sys.modules[__name__]
13 18
14 requiredmodules = {} # Will contain the modules imported by demandload
19 # Requiredmodules contains the modules imported by demandload.
20 # Please note that demandload can be invoked before the
21 # mercurial.packagescan.scan method is invoked in case a mercurial
22 # module is imported.
23 requiredmodules = {}
15 24 def demandload(scope, modules):
16 """ fake demandload function that collects the required modules """
25 """ fake demandload function that collects the required modules
26 foo import foo
27 foo bar import foo, bar
28 foo.bar import foo.bar
29 foo:bar from foo import bar
30 foo:bar,quux from foo import bar, quux
31 foo.bar:quux from foo.bar import quux"""
32
17 33 for m in modules.split():
18 34 mod = None
19 35 try:
20 module, submodules = m.split(':')
21 submodules = submodules.split(',')
36 module, fromlist = m.split(':')
37 fromlist = fromlist.split(',')
22 38 except:
23 39 module = m
24 submodules = []
25 mod = __import__(module, scope, scope, submodules)
26 scope[module] = mod
40 fromlist = []
41 mod = __import__(module, scope, scope, fromlist)
42 if fromlist == []:
43 # mod is only the top package, but we need all packages
44 comp = module.split('.')
45 i = 1
46 mn = comp[0]
47 while True:
48 # mn and mod.__name__ might not be the same
49 scope[mn] = mod
27 50 requiredmodules[mod.__name__] = 1
51 if len(comp) == i: break
52 mod = getattr(mod,comp[i])
53 mn = string.join(comp[:i+1],'.')
54 i += 1
55 else:
56 # mod is the last package in the component list
57 requiredmodules[mod.__name__] = 1
58 for f in fromlist:
59 scope[f] = getattr(mod,f)
60 if type(scope[f]) == types.ModuleType:
61 requiredmodules[scope[f].__name__] = 1
28 62
29 def getmodules(libpath,packagename):
63 def scan(libpath,packagename):
30 64 """ helper for finding all required modules of package <packagename> """
31 65 # Use the package in the build directory
32 66 libpath = os.path.abspath(libpath)
@@ -45,8 +79,6 b' def getmodules(libpath,packagename):'
45 79 pymodulefiles = glob.glob('*.py')
46 80 extmodulefiles = glob.glob('*.pyd')
47 81 os.chdir(cwd)
48 # Install a fake demandload module
49 sys.modules['mercurial.demandload'] = sys.modules['mercurial.packagescan']
50 82 # Import all python modules and by that run the fake demandload
51 83 for m in pymodulefiles:
52 84 if m == '__init__.py': continue
@@ -62,8 +94,9 b' def getmodules(libpath,packagename):'
62 94 fullname = packagename+'.'+mname
63 95 __import__(fullname,tmp,tmp)
64 96 requiredmodules[fullname] = 1
65 includes = requiredmodules.keys()
66 return includes
97
98 def getmodules():
99 return requiredmodules.keys()
67 100
68 101 def importfrom(filename):
69 102 """
@@ -13,6 +13,8 b' import glob'
13 13 from distutils.core import setup, Extension
14 14 from distutils.command.install_data import install_data
15 15
16 # mercurial.packagescan must be the first mercurial module imported
17 import mercurial.packagescan
16 18 import mercurial.version
17 19
18 20 # py2exe needs to be installed to work
@@ -36,7 +38,6 b' try:'
36 38 # Due to the use of demandload py2exe is not finding the modules.
37 39 # packagescan.getmodules creates a list of modules included in
38 40 # the mercurial package plus depdent modules.
39 import mercurial.packagescan
40 41 from py2exe.build_exe import py2exe as build_exe
41 42
42 43 class py2exe_for_demandload(build_exe):
@@ -54,12 +55,10 b' try:'
54 55 self.includes = []
55 56 else:
56 57 self.includes = self.includes.split(',')
57 self.includes += mercurial.packagescan.getmodules(self.build_lib,
58 'mercurial')
59 self.includes += mercurial.packagescan.getmodules(self.build_lib,
60 'mercurial/hgweb')
61 self.includes += mercurial.packagescan.getmodules(self.build_lib,
62 'hgext')
58 mercurial.packagescan.scan(self.build_lib,'mercurial')
59 mercurial.packagescan.scan(self.build_lib,'mercurial/hgweb')
60 mercurial.packagescan.scan(self.build_lib,'hgext')
61 self.includes += mercurial.packagescan.getmodules()
63 62 build_exe.finalize_options(self)
64 63 except ImportError:
65 64 py2exe_for_demandload = None
General Comments 0
You need to be logged in to leave comments. Login now