Skip to content

Commit 180913a

Browse files
authored
Merge pull request #411 from fredroy/use_importlib
Replace deprecated imp by importlib
2 parents 8d8f510 + 8aac31e commit 180913a

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

bindings/Sofa/package/livecoding.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,25 @@
2525
#******************************************************************************/
2626

2727
import traceback
28-
import imp
2928
import types
3029
import gc
3130
import os
3231

32+
import importlib.util
33+
import importlib.machinery
34+
35+
def load_source(modname, filename):
36+
loader = importlib.machinery.SourceFileLoader(modname, filename)
37+
spec = importlib.util.spec_from_file_location(modname, filename, loader=loader)
38+
module = importlib.util.module_from_spec(spec)
39+
# The module is always executed and not cached in sys.modules.
40+
# Uncomment the following line to cache the module.
41+
# sys.modules[module.__name__] = module
42+
loader.exec_module(module)
43+
return module
44+
3345
def mimport(modulename, filename):
34-
f = open(filename, 'r')
35-
return imp.load_module(modulename, f, filename, (modulename, 'r', imp.PY_SOURCE))
46+
return load_source(modulename,filename)
3647

3748
def mreload(modulepath):
3849
try:

0 commit comments

Comments
 (0)