Mercurial > public > mercurial-scm > hg
comparison mercurial/packagescan.py @ 2323:c58a403aa830
setup.py: install packagescan before any mercurial modules is imported
Further the installation of packagescan over demandload is moved to the
packagescan module.
I added as well few more comments in the packagescan module to avoid
the wrong use of package scan in the future.
Reason:
mercurial.packagescan acts as fake mercurial.demandload during a py2exe
run. Unfortunatly the import of mercurial.version in setup.py is done
before mercurial.packagescan is installed. This results in few imports
without mercurial.packagescan in charge and therefore not all dependend
modules are detected when running mercurial.packagescan.getmodules
later e.g. winerror is missed.
author | Volker Kleinfeld <Volker.Kleinfeld@gmx.de> |
---|---|
date | Fri, 19 May 2006 08:54:28 -0700 |
parents | 7f12a63568ae |
children | c4ea7f927dab |
comparison
equal
deleted
inserted
replaced
2298:4be9a79b49b1 | 2323:c58a403aa830 |
---|---|
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 # |
6 # This software may be used and distributed according to the terms | 7 # This software may be used and distributed according to the terms |
7 # of the GNU General Public License, incorporated herein by reference. | 8 # of the GNU General Public License, incorporated herein by reference. |
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(): |
18 mod = None | 25 mod = None |
19 try: | 26 try: |
24 submodules = [] | 31 submodules = [] |
25 mod = __import__(module, scope, scope, submodules) | 32 mod = __import__(module, scope, scope, submodules) |
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) |
33 sys.path.insert(0,libpath) | 40 sys.path.insert(0,libpath) |
34 packdir = os.path.join(libpath,packagename) | 41 packdir = os.path.join(libpath,packagename) |
43 cwd = os.getcwd() | 50 cwd = os.getcwd() |
44 os.chdir(packdir) | 51 os.chdir(packdir) |
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 |
53 tmp = {} | 58 tmp = {} |
54 mname,ext = os.path.splitext(m) | 59 mname,ext = os.path.splitext(m) |
60 tmp = {} | 65 tmp = {} |
61 mname,ext = os.path.splitext(m) | 66 mname,ext = os.path.splitext(m) |
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 """ |
70 import module/package from a named file and returns the module. | 76 import module/package from a named file and returns the module. |
71 It does not check on sys.modules or includes the module in the scope. | 77 It does not check on sys.modules or includes the module in the scope. |