Commit c5dcdbf9 authored by Denis Bilenko's avatar Denis Bilenko

hub.py: make _import("path/module.name") work (path is temporarily added to sys.path)

parent 7a8ee5c6
...@@ -233,13 +233,25 @@ def _import(path): ...@@ -233,13 +233,25 @@ def _import(path):
return path return path
if '.' not in path: if '.' not in path:
raise ImportError("Cannot import %r (required format: module.class)" % path) raise ImportError("Cannot import %r (required format: module.class)" % path)
module, item = path.rsplit('.', 1) if '/' in path:
x = __import__(module) package_path, path = path.rsplit('/', 1)
for attr in path.split('.')[1:]: sys.path = [package_path] + sys.path
x = getattr(x, attr, _NONE) else:
if x is _NONE: package_path = None
raise ImportError('Cannot import name %r from %r' % (attr, x)) try:
return x module, item = path.rsplit('.', 1)
x = __import__(module)
for attr in path.split('.')[1:]:
oldx = x
x = getattr(x, attr, _NONE)
if x is _NONE:
raise ImportError('Cannot import %r from %r' % (attr, oldx))
return x
finally:
try:
sys.path.remove(package_path)
except ValueError:
pass
def config(default, envvar): def config(default, envvar):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment