|
24 | 24 | import textwrap |
25 | 25 | import warnings |
26 | 26 | from ctypes import c_char_p, c_void_p |
| 27 | +from importlib.abc import Loader, MetaPathFinder |
| 28 | +from importlib.machinery import ModuleSpec |
27 | 29 | from logging import getLogger # see `.logger` |
28 | 30 | from types import ModuleType # this is python 3.3 specific |
29 | 31 |
|
@@ -220,27 +222,25 @@ def __setattr__(self, name, value): |
220 | 222 |
|
221 | 223 |
|
222 | 224 | # add custom import behavior for the julia "module" |
223 | | -class JuliaImporter(object): |
| 225 | +class JuliaImporter(MetaPathFinder): |
224 | 226 |
|
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): |
227 | 228 | if fullname.startswith("julia."): |
228 | 229 | filename = fullname.split(".", 2)[1] |
229 | 230 | filepath = os.path.join(os.path.dirname(__file__), filename) |
230 | 231 | if os.path.isfile(filepath + ".py") or os.path.isdir(filepath): |
231 | 232 | return |
232 | | - return JuliaModuleLoader() |
| 233 | + return ModuleSpec(fullname, JuliaModuleLoader()) |
233 | 234 |
|
234 | 235 |
|
235 | | -class JuliaModuleLoader(object): |
236 | | - |
| 236 | +class JuliaModuleLoader(Loader): |
237 | 237 | @property |
238 | 238 | def julia(self): |
239 | 239 | self.__class__.julia = julia = Julia() |
240 | 240 | return julia |
241 | 241 |
|
242 | | - # load module was deprecated in v3.4 |
243 | | - def load_module(self, fullname): |
| 242 | + def exec_module(self, module): |
| 243 | + fullname = module.__name__ |
244 | 244 | juliapath = remove_prefix(fullname, "julia.") |
245 | 245 | if juliapath == 'Main': |
246 | 246 | return sys.modules.setdefault(fullname, |
|
0 commit comments