Skip to content

Commit ef400c6

Browse files
committed
Fix importlib deprecated API
1 parent 69b734f commit ef400c6

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/julia/core.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import textwrap
2525
import warnings
2626
from ctypes import c_char_p, c_void_p
27+
from importlib.abc import Loader, MetaPathFinder
28+
from importlib.machinery import ModuleSpec
2729
from logging import getLogger # see `.logger`
2830
from types import ModuleType # this is python 3.3 specific
2931

@@ -220,27 +222,25 @@ def __setattr__(self, name, value):
220222

221223

222224
# add custom import behavior for the julia "module"
223-
class JuliaImporter(object):
225+
class JuliaImporter(MetaPathFinder):
224226

225-
# find_module was deprecated in v3.4
226-
def find_module(self, fullname, path=None):
227+
def find_spec(self, fullname, path=None, target=None):
227228
if fullname.startswith("julia."):
228229
filename = fullname.split(".", 2)[1]
229230
filepath = os.path.join(os.path.dirname(__file__), filename)
230231
if os.path.isfile(filepath + ".py") or os.path.isdir(filepath):
231232
return
232-
return JuliaModuleLoader()
233+
return ModuleSpec(fullname, JuliaModuleLoader())
233234

234235

235-
class JuliaModuleLoader(object):
236-
236+
class JuliaModuleLoader(Loader):
237237
@property
238238
def julia(self):
239239
self.__class__.julia = julia = Julia()
240240
return julia
241241

242-
# load module was deprecated in v3.4
243-
def load_module(self, fullname):
242+
def exec_module(self, module):
243+
fullname = module.__name__
244244
juliapath = remove_prefix(fullname, "julia.")
245245
if juliapath == 'Main':
246246
return sys.modules.setdefault(fullname,

0 commit comments

Comments
 (0)