comparison mercurial/packagescan.py @ 3105:ef4e5d05bac4

Merge with mainline
author Matt Mackall <mpm@selenic.com>
date Sun, 17 Sep 2006 16:02:09 -0500
parents 799811087044
children eb0b4a2d70a9
comparison
equal deleted inserted replaced
3104:e6818b0b8154 3105:ef4e5d05bac4
24 def demandload(scope, modules): 24 def demandload(scope, modules):
25 """ fake demandload function that collects the required modules 25 """ fake demandload function that collects the required modules
26 foo import foo 26 foo import foo
27 foo bar import foo, bar 27 foo bar import foo, bar
28 foo.bar import foo.bar 28 foo.bar import foo.bar
29 foo@bar import foo as bar
29 foo:bar from foo import bar 30 foo:bar from foo import bar
30 foo:bar,quux from foo import bar, quux 31 foo:bar,quux from foo import bar, quux
31 foo.bar:quux from foo.bar import quux""" 32 foo.bar:quux from foo.bar import quux"""
32 33
33 for m in modules.split(): 34 for m in modules.split():
36 module, fromlist = m.split(':') 37 module, fromlist = m.split(':')
37 fromlist = fromlist.split(',') 38 fromlist = fromlist.split(',')
38 except: 39 except:
39 module = m 40 module = m
40 fromlist = [] 41 fromlist = []
42 as_ = None
43 if '@' in module:
44 module, as_ = module.split('@')
41 mod = __import__(module, scope, scope, fromlist) 45 mod = __import__(module, scope, scope, fromlist)
42 if fromlist == []: 46 if fromlist == []:
43 # mod is only the top package, but we need all packages 47 # mod is only the top package, but we need all packages
44 comp = module.split('.') 48 comp = module.split('.')
45 i = 1 49 i = 1
46 mn = comp[0] 50 mn = comp[0]
47 while True: 51 while True:
48 # mn and mod.__name__ might not be the same 52 # mn and mod.__name__ might not be the same
49 scope[mn] = mod 53 if not as_:
54 as_ = mn
55 scope[as_] = mod
50 requiredmodules[mod.__name__] = 1 56 requiredmodules[mod.__name__] = 1
51 if len(comp) == i: break 57 if len(comp) == i: break
52 mod = getattr(mod,comp[i]) 58 mod = getattr(mod,comp[i])
53 mn = string.join(comp[:i+1],'.') 59 mn = string.join(comp[:i+1],'.')
54 i += 1 60 i += 1