Skip to content

Commit

Permalink
reuse numpy for .pyf()
Browse files Browse the repository at this point in the history
  • Loading branch information
briangu committed Dec 19, 2023
1 parent 4bcf424 commit 7fe50fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
3 changes: 3 additions & 0 deletions examples/math/trig.kg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.pyf("numpy";"cos")

.p(cos(30))
19 changes: 11 additions & 8 deletions klongpy/sys_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,17 @@ def _import_module(klong, x, from_list=None):
print(f".py: {e}")
raise RuntimeError(f"module could not be imported: {x}")
else:
spec = importlib.util.find_spec(x)
if spec is not None:
try:
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
except Exception as e:
print(f".py: {e}")
raise RuntimeError(f"module could not be imported: {x}")
if x in sys.modules:
module = sys.modules[x]
else:
spec = importlib.util.find_spec(x)
if spec is not None:
try:
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
except Exception as e:
print(f".py: {e}")
raise RuntimeError(f"module could not be imported: {x}")
try:
klong_exports = module.__dict__.get("klong_exports")
if klong_exports is None:
Expand Down

0 comments on commit 7fe50fd

Please sign in to comment.