Skip to content

Commit 8149933

Browse files
committed
Use different import.
1 parent 3aa3309 commit 8149933

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lambda_local/main.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,17 @@ def load(request_id, path, function_name):
102102
file_directory = os.path.dirname(file_path)
103103
sys.path.append(file_directory)
104104

105-
mod = imp.load_source(mod_name, path)
105+
if sys.version_info.major == 2:
106+
mod = imp.load_source(mod_name, path)
107+
elif sys.version_info.major == 3 and sys.version_info.minor >= 5:
108+
import importlib
109+
spec = importlib.util.spec_from_file_location(mod_name, path)
110+
mod = importlib.util.module_from_spec(spec)
111+
sys.modules[mod_name] = mod
112+
spec.loader.exec_module(mod)
113+
else:
114+
raise Exception("unsupported python version")
115+
106116
func = getattr(mod, function_name)
107117
return func
108118

0 commit comments

Comments
 (0)