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,10 +9,16 b'' | |||
|
8 | 9 | import glob |
|
9 | 10 | import os |
|
10 | 11 | import sys |
|
11 | import demandload | |
|
12 | 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 | 22 | def demandload(scope, modules): |
|
16 | 23 | """ fake demandload function that collects the required modules """ |
|
17 | 24 | for m in modules.split(): |
@@ -26,7 +33,7 b' def demandload(scope, modules):' | |||
|
26 | 33 | scope[module] = mod |
|
27 | 34 | requiredmodules[mod.__name__] = 1 |
|
28 | 35 | |
|
29 |
def |
|
|
36 | def scan(libpath,packagename): | |
|
30 | 37 | """ helper for finding all required modules of package <packagename> """ |
|
31 | 38 | # Use the package in the build directory |
|
32 | 39 | libpath = os.path.abspath(libpath) |
@@ -45,8 +52,6 b' def getmodules(libpath,packagename):' | |||
|
45 | 52 | pymodulefiles = glob.glob('*.py') |
|
46 | 53 | extmodulefiles = glob.glob('*.pyd') |
|
47 | 54 | os.chdir(cwd) |
|
48 | # Install a fake demandload module | |
|
49 | sys.modules['mercurial.demandload'] = sys.modules['mercurial.packagescan'] | |
|
50 | 55 | # Import all python modules and by that run the fake demandload |
|
51 | 56 | for m in pymodulefiles: |
|
52 | 57 | if m == '__init__.py': continue |
@@ -62,8 +67,9 b' def getmodules(libpath,packagename):' | |||
|
62 | 67 | fullname = packagename+'.'+mname |
|
63 | 68 | __import__(fullname,tmp,tmp) |
|
64 | 69 | requiredmodules[fullname] = 1 |
|
65 | includes = requiredmodules.keys() | |
|
66 | return includes | |
|
70 | ||
|
71 | def getmodules(): | |
|
72 | return requiredmodules.keys() | |
|
67 | 73 | |
|
68 | 74 | def importfrom(filename): |
|
69 | 75 | """ |
@@ -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,10 +55,9 b' try:' | |||
|
54 | 55 | self.includes = [] |
|
55 | 56 | else: |
|
56 | 57 | self.includes = self.includes.split(',') |
|
57 |
|
|
|
58 | 'mercurial') | |
|
59 |
self.includes += mercurial.packagescan.getmodules( |
|
|
60 | 'hgext') | |
|
58 | mercurial.packagescan.scan(self.build_lib,'mercurial') | |
|
59 | mercurial.packagescan.scan(self.build_lib,'hgext') | |
|
60 | self.includes += mercurial.packagescan.getmodules() | |
|
61 | 61 | build_exe.finalize_options(self) |
|
62 | 62 | except ImportError: |
|
63 | 63 | py2exe_for_demandload = None |
General Comments 0
You need to be logged in to leave comments.
Login now