equal
deleted
inserted
replaced
69 except IOError as exc: |
69 except IOError as exc: |
70 if not exc.filename: |
70 if not exc.filename: |
71 exc.filename = path # python does not fill this |
71 exc.filename = path # python does not fill this |
72 raise |
72 raise |
73 |
73 |
|
74 def _importh(name): |
|
75 """import and return the <name> module""" |
|
76 mod = __import__(name) |
|
77 components = name.split('.') |
|
78 for comp in components[1:]: |
|
79 mod = getattr(mod, comp) |
|
80 return mod |
|
81 |
74 def load(ui, name, path): |
82 def load(ui, name, path): |
75 if name.startswith('hgext.') or name.startswith('hgext/'): |
83 if name.startswith('hgext.') or name.startswith('hgext/'): |
76 shortname = name[6:] |
84 shortname = name[6:] |
77 else: |
85 else: |
78 shortname = name |
86 shortname = name |
85 # the module will be loaded in sys.modules |
93 # the module will be loaded in sys.modules |
86 # choose an unique name so that it doesn't |
94 # choose an unique name so that it doesn't |
87 # conflicts with other modules |
95 # conflicts with other modules |
88 mod = loadpath(path, 'hgext.%s' % name) |
96 mod = loadpath(path, 'hgext.%s' % name) |
89 else: |
97 else: |
90 def importh(name): |
|
91 mod = __import__(name) |
|
92 components = name.split('.') |
|
93 for comp in components[1:]: |
|
94 mod = getattr(mod, comp) |
|
95 return mod |
|
96 try: |
98 try: |
97 mod = importh("hgext.%s" % name) |
99 mod = _importh("hgext.%s" % name) |
98 except ImportError as err: |
100 except ImportError as err: |
99 ui.debug('could not import hgext.%s (%s): trying %s\n' |
101 ui.debug('could not import hgext.%s (%s): trying %s\n' |
100 % (name, err, name)) |
102 % (name, err, name)) |
101 if ui.debugflag: |
103 if ui.debugflag: |
102 ui.traceback() |
104 ui.traceback() |
103 mod = importh(name) |
105 mod = _importh(name) |
104 |
106 |
105 # Before we do anything with the extension, check against minimum stated |
107 # Before we do anything with the extension, check against minimum stated |
106 # compatibility. This gives extension authors a mechanism to have their |
108 # compatibility. This gives extension authors a mechanism to have their |
107 # extensions short circuit when loaded with a known incompatible version |
109 # extensions short circuit when loaded with a known incompatible version |
108 # of Mercurial. |
110 # of Mercurial. |