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 # This module must be the first mercurial module imported in setup.py |
4 # |
4 # |
5 # Copyright 2005 Volker Kleinfeld <Volker.Kleinfeld@gmx.de> |
5 # Copyright 2005, 2006 Volker Kleinfeld <Volker.Kleinfeld@gmx.de> |
6 # |
6 # |
7 # This software may be used and distributed according to the terms |
7 # This software may be used and distributed according to the terms |
8 # of the GNU General Public License, incorporated herein by reference. |
8 # of the GNU General Public License, incorporated herein by reference. |
9 import glob |
9 import glob |
10 import os |
10 import os |
37 module, fromlist = m.split(':') |
37 module, fromlist = m.split(':') |
38 fromlist = fromlist.split(',') |
38 fromlist = fromlist.split(',') |
39 except: |
39 except: |
40 module = m |
40 module = m |
41 fromlist = [] |
41 fromlist = [] |
42 as = None |
42 as_ = None |
43 if '@' in module: |
43 if '@' in module: |
44 module, as = module.split("@") |
44 module, as_ = module.split('@') |
45 mod = __import__(module, scope, scope, fromlist) |
45 mod = __import__(module, scope, scope, fromlist) |
46 if fromlist == []: |
46 if fromlist == []: |
47 # mod is only the top package, but we need all packages |
47 # mod is only the top package, but we need all packages |
48 comp = module.split('.') |
48 comp = module.split('.') |
49 i = 1 |
49 i = 1 |
50 mn = comp[0] |
50 mn = comp[0] |
51 while True: |
51 while True: |
52 # mn and mod.__name__ might not be the same |
52 # mn and mod.__name__ might not be the same |
53 if not as: |
53 if not as_: |
54 as = mn |
54 as_ = mn |
55 scope[as] = mod |
55 scope[as_] = mod |
56 requiredmodules[mod.__name__] = 1 |
56 requiredmodules[mod.__name__] = 1 |
57 if len(comp) == i: break |
57 if len(comp) == i: break |
58 mod = getattr(mod,comp[i]) |
58 mod = getattr(mod,comp[i]) |
59 mn = string.join(comp[:i+1],'.') |
59 mn = string.join(comp[:i+1],'.') |
60 i += 1 |
60 i += 1 |