##// END OF EJS Templates
extensions: move the "import" logic out from "load"...
Jun Wu -
r30058:8f54f9b8 default
parent child Browse files
Show More
@@ -80,6 +80,26 b' def _importh(name):'
80 mod = getattr(mod, comp)
80 mod = getattr(mod, comp)
81 return mod
81 return mod
82
82
83 def _importext(name, path=None, reportfunc=None):
84 if path:
85 # the module will be loaded in sys.modules
86 # choose an unique name so that it doesn't
87 # conflicts with other modules
88 mod = loadpath(path, 'hgext.%s' % name)
89 else:
90 try:
91 mod = _importh("hgext.%s" % name)
92 except ImportError as err:
93 if reportfunc:
94 reportfunc(err, "hgext.%s" % name, "hgext3rd.%s" % name)
95 try:
96 mod = _importh("hgext3rd.%s" % name)
97 except ImportError as err:
98 if reportfunc:
99 reportfunc(err, "hgext3rd.%s" % name, name)
100 mod = _importh(name)
101 return mod
102
83 def _reportimporterror(ui, err, failed, next):
103 def _reportimporterror(ui, err, failed, next):
84 # note: this ui.debug happens before --debug is processed,
104 # note: this ui.debug happens before --debug is processed,
85 # Use --config ui.debug=1 to see them.
105 # Use --config ui.debug=1 to see them.
@@ -98,21 +118,7 b' def load(ui, name, path):'
98 if shortname in _extensions:
118 if shortname in _extensions:
99 return _extensions[shortname]
119 return _extensions[shortname]
100 _extensions[shortname] = None
120 _extensions[shortname] = None
101 if path:
121 mod = _importext(name, path, bind(_reportimporterror, ui))
102 # the module will be loaded in sys.modules
103 # choose an unique name so that it doesn't
104 # conflicts with other modules
105 mod = loadpath(path, 'hgext.%s' % name)
106 else:
107 try:
108 mod = _importh("hgext.%s" % name)
109 except ImportError as err:
110 _reportimporterror(ui, err, "hgext.%s" % name, "hgext3rd.%s" % name)
111 try:
112 mod = _importh("hgext3rd.%s" % name)
113 except ImportError as err:
114 _reportimporterror(ui, err, "hgext3rd.%s" % name, name)
115 mod = _importh(name)
116
122
117 # Before we do anything with the extension, check against minimum stated
123 # Before we do anything with the extension, check against minimum stated
118 # compatibility. This gives extension authors a mechanism to have their
124 # compatibility. This gives extension authors a mechanism to have their
General Comments 0
You need to be logged in to leave comments. Login now