MilesCranmer commited on
Commit
52f940c
1 Parent(s): 7c2bce0

Only load Julia extension on recent julia

Browse files
Files changed (1) hide show
  1. pysr/julia_import.py +19 -16
pysr/julia_import.py CHANGED
@@ -34,8 +34,25 @@ else:
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
41
 
@@ -50,24 +67,10 @@ if os.environ.get("PYSR_AUTOLOAD_EXTENSIONS", "yes") in {"yes", ""}:
50
  get_ipython().run_line_magic("load_ext", "juliacall")
51
  except Exception:
52
  pass
53
- elif os.environ["PYSR_AUTOLOAD_EXTENSIONS"] not in {"no", "yes", ""}:
54
  warnings.warn(
55
  "PYSR_AUTOLOAD_EXTENSIONS environment variable is set to something other than 'yes' or 'no' or ''."
56
  )
57
 
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
- jl.seval("using PythonCall: PythonCall, Py, pyconvert")
64
- jl.seval(
65
- """function PythonCall.pyjlmodule_seval(self::Module, expr::Py)
66
- e = Meta.parseall(strip(pyconvert(String, expr)))
67
- Py(Base.eval(self, e))
68
- end"""
69
- )
70
- # ^TODO: Overwrite this once PythonCall.jl is updated:
71
-
72
  jl.seval("using SymbolicRegression")
73
  SymbolicRegression = jl.SymbolicRegression
 
34
  ):
35
  os.environ[k] = os.environ.get(k, default)
36
 
37
+
38
+ from juliacall import Main as jl # type: ignore
39
+
40
+ # Overwrite the seval function to use Meta.parseall
41
+ # instead of Meta.parse.
42
+ jl.seval("using PythonCall: PythonCall, Py, pyconvert")
43
+ jl.seval(
44
+ """function PythonCall.pyjlmodule_seval(self::Module, expr::Py)
45
+ e = Meta.parseall(strip(pyconvert(String, expr)))
46
+ Py(Base.eval(self, e))
47
+ end"""
48
+ )
49
+ # ^TODO: Overwrite this once PythonCall.jl is updated:
50
+
51
+ jl_version = (jl.VERSION.major, jl.VERSION.minor, jl.VERSION.patch)
52
+
53
  # Next, automatically load the juliacall extension if we're in a Jupyter notebook
54
+ autoload_extensions = os.environ.get("PYSR_AUTOLOAD_EXTENSIONS", "yes")
55
+ if autoload_extensions in {"yes", ""} and jl_version >= (1, 9, 0):
56
  try:
57
  get_ipython = sys.modules["IPython"].get_ipython
58
 
 
67
  get_ipython().run_line_magic("load_ext", "juliacall")
68
  except Exception:
69
  pass
70
+ elif autoload_extensions not in {"no", "yes", ""}:
71
  warnings.warn(
72
  "PYSR_AUTOLOAD_EXTENSIONS environment variable is set to something other than 'yes' or 'no' or ''."
73
  )
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  jl.seval("using SymbolicRegression")
76
  SymbolicRegression = jl.SymbolicRegression