##// END OF EJS Templates
setup.py: install packagescan before any mercurial modules is imported...
Volker Kleinfeld -
r2323:c58a403a default
parent child Browse files
Show More
@@ -1,5 +1,6 b''
1 # packagescan.py - Helper module for identifing used modules.
1 # packagescan.py - Helper module for identifing used modules.
2 # Used for the py2exe distutil.
2 # Used for the py2exe distutil.
3 # This module must be the first mercurial module imported in setup.py
3 #
4 #
4 # Copyright 2005 Volker Kleinfeld <Volker.Kleinfeld@gmx.de>
5 # Copyright 2005 Volker Kleinfeld <Volker.Kleinfeld@gmx.de>
5 #
6 #
@@ -8,10 +9,16 b''
8 import glob
9 import glob
9 import os
10 import os
10 import sys
11 import sys
11 import demandload
12 import ihooks
12 import ihooks
13
13
14 requiredmodules = {} # Will contain the modules imported by demandload
14 # Install this module as fake demandload module
15 sys.modules['mercurial.demandload'] = sys.modules[__name__]
16
17 # Requiredmodules contains the modules imported by demandload.
18 # Please note that demandload can be invoked before the
19 # mercurial.packagescan.scan method is invoked in case a mercurial
20 # module is imported.
21 requiredmodules = {}
15 def demandload(scope, modules):
22 def demandload(scope, modules):
16 """ fake demandload function that collects the required modules """
23 """ fake demandload function that collects the required modules """
17 for m in modules.split():
24 for m in modules.split():
@@ -26,7 +33,7 b' def demandload(scope, modules):'
26 scope[module] = mod
33 scope[module] = mod
27 requiredmodules[mod.__name__] = 1
34 requiredmodules[mod.__name__] = 1
28
35
29 def getmodules(libpath,packagename):
36 def scan(libpath,packagename):
30 """ helper for finding all required modules of package <packagename> """
37 """ helper for finding all required modules of package <packagename> """
31 # Use the package in the build directory
38 # Use the package in the build directory
32 libpath = os.path.abspath(libpath)
39 libpath = os.path.abspath(libpath)
@@ -45,8 +52,6 b' def getmodules(libpath,packagename):'
45 pymodulefiles = glob.glob('*.py')
52 pymodulefiles = glob.glob('*.py')
46 extmodulefiles = glob.glob('*.pyd')
53 extmodulefiles = glob.glob('*.pyd')
47 os.chdir(cwd)
54 os.chdir(cwd)
48 # Install a fake demandload module
49 sys.modules['mercurial.demandload'] = sys.modules['mercurial.packagescan']
50 # Import all python modules and by that run the fake demandload
55 # Import all python modules and by that run the fake demandload
51 for m in pymodulefiles:
56 for m in pymodulefiles:
52 if m == '__init__.py': continue
57 if m == '__init__.py': continue
@@ -62,8 +67,9 b' def getmodules(libpath,packagename):'
62 fullname = packagename+'.'+mname
67 fullname = packagename+'.'+mname
63 __import__(fullname,tmp,tmp)
68 __import__(fullname,tmp,tmp)
64 requiredmodules[fullname] = 1
69 requiredmodules[fullname] = 1
65 includes = requiredmodules.keys()
70
66 return includes
71 def getmodules():
72 return requiredmodules.keys()
67
73
68 def importfrom(filename):
74 def importfrom(filename):
69 """
75 """
@@ -13,6 +13,8 b' import glob'
13 from distutils.core import setup, Extension
13 from distutils.core import setup, Extension
14 from distutils.command.install_data import install_data
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 import mercurial.version
18 import mercurial.version
17
19
18 # py2exe needs to be installed to work
20 # py2exe needs to be installed to work
@@ -36,7 +38,6 b' try:'
36 # Due to the use of demandload py2exe is not finding the modules.
38 # Due to the use of demandload py2exe is not finding the modules.
37 # packagescan.getmodules creates a list of modules included in
39 # packagescan.getmodules creates a list of modules included in
38 # the mercurial package plus depdent modules.
40 # the mercurial package plus depdent modules.
39 import mercurial.packagescan
40 from py2exe.build_exe import py2exe as build_exe
41 from py2exe.build_exe import py2exe as build_exe
41
42
42 class py2exe_for_demandload(build_exe):
43 class py2exe_for_demandload(build_exe):
@@ -54,10 +55,9 b' try:'
54 self.includes = []
55 self.includes = []
55 else:
56 else:
56 self.includes = self.includes.split(',')
57 self.includes = self.includes.split(',')
57 self.includes += mercurial.packagescan.getmodules(self.build_lib,
58 mercurial.packagescan.scan(self.build_lib,'mercurial')
58 'mercurial')
59 mercurial.packagescan.scan(self.build_lib,'hgext')
59 self.includes += mercurial.packagescan.getmodules(self.build_lib,
60 self.includes += mercurial.packagescan.getmodules()
60 'hgext')
61 build_exe.finalize_options(self)
61 build_exe.finalize_options(self)
62 except ImportError:
62 except ImportError:
63 py2exe_for_demandload = None
63 py2exe_for_demandload = None
General Comments 0
You need to be logged in to leave comments. Login now