Skip to content

Commit

Permalink
Ensure we can find spec from JuliaModule
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesCranmer committed Nov 5, 2023
1 parent c4bc980 commit 764aa33
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/julia/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def __try_getattr(self, name):
if self._julia.isamodule(jl_fullname):
realname = self._julia.fullname(self._julia.eval(jl_fullname))
if self._julia.isdefined(realname):
return self.__loader__.load_module("julia." + realname)
return self.__loader__.create_module(_find_spec_from_fullname("julia." + realname))
# Otherwise, it may be, e.g., "Main.anonymous", created by
# Module().

Expand Down Expand Up @@ -225,14 +225,17 @@ def __setattr__(self, name, value):
class JuliaImporter(MetaPathFinder):

def find_spec(self, fullname, path=None, target=None):
if fullname.startswith("julia."):
filename = fullname.split(".", 2)[1]
filepath = os.path.join(os.path.dirname(__file__), filename)
if os.path.isfile(filepath + ".py") or os.path.isdir(filepath):
return
return ModuleSpec(fullname, JuliaModuleLoader(), origin=filepath)
return _find_spec_from_fullname(fullname)


def _find_spec_from_fullname(fullname):
if fullname.startswith("julia."):
filename = fullname.split(".", 2)[1]
filepath = os.path.join(os.path.dirname(__file__), filename)
if os.path.isfile(filepath + ".py") or os.path.isdir(filepath):
return
return ModuleSpec(fullname, JuliaModuleLoader(), origin=filepath)

class JuliaModuleLoader(Loader):
@property
def julia(self):
Expand Down

0 comments on commit 764aa33

Please sign in to comment.