Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove imp module from kernel.py #1361

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions ck/ck/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import sys
import json
import os
import imp # Needed to load CK Python modules from CK repositories
import importlib # Needed to load CK Python modules from CK repositories

initialized = False # True if initialized
# Needed to suppress all output (useful for CK-based web services)
Expand Down Expand Up @@ -4093,17 +4093,14 @@ def load_module_from_path(i):
xcfg = i.get('cfg', None)

# Find module
try:
x = imp.find_module(n, [p])
except ImportError as e: # pragma: no cover
return {'return': 1, 'error': 'can\'t find module code (path='+p+', name='+n+', err='+format(e)+')'}
x = importlib.machinery.PathFinder().find_spec(n, [p])
if not x:
return {'return': 1, 'error': 'can\'t find module code (path='+p+', name='+n+')'}

ff = x[0]
full_path = x[1]
full_path = x.origin

# Check if code has been already loaded
if full_path in work['cached_module_by_path'] and work['cached_module_by_path_last_modification'][full_path] == os.path.getmtime(full_path):
ff.close()
# Code already loaded
return work['cached_module_by_path'][full_path]

Expand Down Expand Up @@ -4131,12 +4128,11 @@ def load_module_from_path(i):
ruid = 'rt-'+r['data_uid']

try:
c = imp.load_module(ruid, ff, full_path, x[2])
c = importlib.util.module_from_spec(x)
x.loader.exec_module(c)
except ImportError as e: # pragma: no cover
return {'return': 1, 'error': 'can\'t load module code (path='+p+', name='+n+', err='+format(e)+')'}

x[0].close()

# Initialize module with this CK instance
c.ck = sys.modules[__name__]
if xcfg != None:
Expand Down
Loading