##// END OF EJS Templates
vcs: replace imp with importlib...
Mads Kiilerich -
r8779:2cd418e3 stable
parent child Browse files
Show More
@@ -1,13 +1,14 b''
1 import imp
1 import importlib
2
2
3
3
4 def create_module(name, path):
4 def create_module(name, path):
5 """
5 """
6 Returns module created *on the fly*. Returned module would have name same
6 Returns module created *on the fly*. Returned module would have name same
7 as given ``name`` and would contain code read from file at the given
7 as given ``name`` and would contain code read from file at the given
8 ``path`` (it may also be a zip or package containing *__main__* module).
8 ``path`` (it may also be a zip or package containing *__main__* module).
9 """
9 """
10 module = imp.new_module(name)
10
11 module.__file__ = path
11 spec = importlib.util.spec_from_file_location('module_name', path)
12 exec(compile(open(path, "rb").read(), path, 'exec'), module.__dict__)
12 module = importlib.util.module_from_spec(spec)
13 spec.loader.exec_module(module)
13 return module
14 return module
General Comments 0
You need to be logged in to leave comments. Login now