Changeset - 2cd418e377de
[Not reviewed]
stable
0 1 0
Mads Kiilerich (mads) - 20 months ago 2024-07-19 21:38:17
mads@kiilerich.com
Grafted from: 0971c3d37d65
vcs: replace imp with importlib

imp has been dropped in Python 3.12. Mercurial has been changed in a similar
way.
1 file changed with 5 insertions and 4 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/vcs/utils/fakemod.py
Show inline comments
 
import imp
 
import importlib
 

	
 

	
 
def create_module(name, path):
 
    """
 
    Returns module created *on the fly*. Returned module would have name same
 
    as given ``name`` and would contain code read from file at the given
 
    ``path`` (it may also be a zip or package containing *__main__* module).
 
    """
 
    module = imp.new_module(name)
 
    module.__file__ = path
 
    exec(compile(open(path, "rb").read(), path, 'exec'), module.__dict__)
 

	
 
    spec = importlib.util.spec_from_file_location('module_name', path)
 
    module = importlib.util.module_from_spec(spec)
 
    spec.loader.exec_module(module)
 
    return module
0 comments (0 inline, 0 general)