Skip to content

Commit

Permalink
Only overwrite seval on recent Julia versions
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesCranmer committed Feb 10, 2024
1 parent 83ef326 commit b96e8d3
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions pysr/julia_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import sys
import warnings

# Check if JuliaCall is already loaded, and if so, warn the user
# about the relevant environment variables. If not loaded,
# set up sensible defaults.
if "juliacall" in sys.modules:
warnings.warn(
"juliacall module already imported. "
Expand Down Expand Up @@ -31,6 +34,7 @@
):
os.environ[k] = os.environ.get(k, default)

# Next, automatically load the juliacall extension if we're in a Jupyter notebook
if os.environ.get("PYSR_AUTOLOAD_EXTENSIONS", "yes") in {"yes", ""}:
try:
get_ipython = sys.modules["IPython"].get_ipython
Expand All @@ -54,10 +58,11 @@

from juliacall import Main as jl # type: ignore

# Finally, overwrite the seval function to use Meta.parseall
# instead of Meta.parse.
if jl.seval('VERSION >= v"1.9.0-DEV.0"'):
# TODO: Overwrite this once PythonCall.jl is updated:
def seval(s: str):
return jl.eval(jl.Meta.parseall(s))

# TODO: Overwrite this once PythonCall.jl is updated:
def seval(s: str):
return jl.eval(jl.Meta.parseall(s))


jl.seval = seval
jl.seval = seval

0 comments on commit b96e8d3

Please sign in to comment.