MilesCranmer commited on
Commit
b96e8d3
·
unverified ·
1 Parent(s): 83ef326

Only overwrite seval on recent Julia versions

Browse files
Files changed (1) hide show
  1. pysr/julia_import.py +11 -6
pysr/julia_import.py CHANGED
@@ -2,6 +2,9 @@ import os
2
  import sys
3
  import warnings
4
 
 
 
 
5
  if "juliacall" in sys.modules:
6
  warnings.warn(
7
  "juliacall module already imported. "
@@ -31,6 +34,7 @@ else:
31
  ):
32
  os.environ[k] = os.environ.get(k, default)
33
 
 
34
  if os.environ.get("PYSR_AUTOLOAD_EXTENSIONS", "yes") in {"yes", ""}:
35
  try:
36
  get_ipython = sys.modules["IPython"].get_ipython
@@ -54,10 +58,11 @@ elif os.environ["PYSR_AUTOLOAD_EXTENSIONS"] not in {"no", "yes", ""}:
54
 
55
  from juliacall import Main as jl # type: ignore
56
 
 
 
 
 
 
 
57
 
58
- # TODO: Overwrite this once PythonCall.jl is updated:
59
- def seval(s: str):
60
- return jl.eval(jl.Meta.parseall(s))
61
-
62
-
63
- jl.seval = seval
 
2
  import sys
3
  import warnings
4
 
5
+ # Check if JuliaCall is already loaded, and if so, warn the user
6
+ # about the relevant environment variables. If not loaded,
7
+ # set up sensible defaults.
8
  if "juliacall" in sys.modules:
9
  warnings.warn(
10
  "juliacall module already imported. "
 
34
  ):
35
  os.environ[k] = os.environ.get(k, default)
36
 
37
+ # Next, automatically load the juliacall extension if we're in a Jupyter notebook
38
  if os.environ.get("PYSR_AUTOLOAD_EXTENSIONS", "yes") in {"yes", ""}:
39
  try:
40
  get_ipython = sys.modules["IPython"].get_ipython
 
58
 
59
  from juliacall import Main as jl # type: ignore
60
 
61
+ # Finally, overwrite the seval function to use Meta.parseall
62
+ # instead of Meta.parse.
63
+ if jl.seval('VERSION >= v"1.9.0-DEV.0"'):
64
+ # TODO: Overwrite this once PythonCall.jl is updated:
65
+ def seval(s: str):
66
+ return jl.eval(jl.Meta.parseall(s))
67
 
68
+ jl.seval = seval