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,25 +9,58 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 | 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 |
|
|
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 | def demandload(scope, modules): |
|
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 | for m in modules.split(): |
|
33 | for m in modules.split(): | |
18 | mod = None |
|
34 | mod = None | |
19 | try: |
|
35 | try: | |
20 |
module, |
|
36 | module, fromlist = m.split(':') | |
21 |
|
|
37 | fromlist = fromlist.split(',') | |
22 | except: |
|
38 | except: | |
23 | module = m |
|
39 | module = m | |
24 |
|
|
40 | fromlist = [] | |
25 |
mod = __import__(module, scope, scope, |
|
41 | mod = __import__(module, scope, scope, fromlist) | |
26 | scope[module] = mod |
|
42 | if fromlist == []: | |
27 | requiredmodules[mod.__name__] = 1 |
|
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 | |||
|
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 |
|
63 | def scan(libpath,packagename): | |
30 | """ helper for finding all required modules of package <packagename> """ |
|
64 | """ helper for finding all required modules of package <packagename> """ | |
31 | # Use the package in the build directory |
|
65 | # Use the package in the build directory | |
32 | libpath = os.path.abspath(libpath) |
|
66 | libpath = os.path.abspath(libpath) | |
@@ -45,8 +79,6 b' def getmodules(libpath,packagename):' | |||||
45 | pymodulefiles = glob.glob('*.py') |
|
79 | pymodulefiles = glob.glob('*.py') | |
46 | extmodulefiles = glob.glob('*.pyd') |
|
80 | extmodulefiles = glob.glob('*.pyd') | |
47 | os.chdir(cwd) |
|
81 | 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 |
|
82 | # Import all python modules and by that run the fake demandload | |
51 | for m in pymodulefiles: |
|
83 | for m in pymodulefiles: | |
52 | if m == '__init__.py': continue |
|
84 | if m == '__init__.py': continue | |
@@ -62,8 +94,9 b' def getmodules(libpath,packagename):' | |||||
62 | fullname = packagename+'.'+mname |
|
94 | fullname = packagename+'.'+mname | |
63 | __import__(fullname,tmp,tmp) |
|
95 | __import__(fullname,tmp,tmp) | |
64 | requiredmodules[fullname] = 1 |
|
96 | requiredmodules[fullname] = 1 | |
65 | includes = requiredmodules.keys() |
|
97 | ||
66 | return includes |
|
98 | def getmodules(): | |
|
99 | return requiredmodules.keys() | |||
67 |
|
100 | |||
68 | def importfrom(filename): |
|
101 | def importfrom(filename): | |
69 | """ |
|
102 | """ |
@@ -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,12 +55,10 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 |
|
|
58 | mercurial.packagescan.scan(self.build_lib,'mercurial') | |
58 | 'mercurial') |
|
59 | mercurial.packagescan.scan(self.build_lib,'mercurial/hgweb') | |
59 |
|
|
60 | mercurial.packagescan.scan(self.build_lib,'hgext') | |
60 | 'mercurial/hgweb') |
|
61 | self.includes += mercurial.packagescan.getmodules() | |
61 | self.includes += mercurial.packagescan.getmodules(self.build_lib, |
|
|||
62 | 'hgext') |
|
|||
63 | build_exe.finalize_options(self) |
|
62 | build_exe.finalize_options(self) | |
64 | except ImportError: |
|
63 | except ImportError: | |
65 | py2exe_for_demandload = None |
|
64 | py2exe_for_demandload = None |
General Comments 0
You need to be logged in to leave comments.
Login now