MilesCranmer commited on
Commit
d7841a4
1 Parent(s): ae8fa7f

Allow user to disable juliacall extension

Browse files
Files changed (1) hide show
  1. pysr/julia_import.py +16 -9
pysr/julia_import.py CHANGED
@@ -31,18 +31,25 @@ else:
31
  ):
32
  os.environ[k] = os.environ.get(k, default)
33
 
34
- try:
35
- get_ipython = sys.modules["IPython"].get_ipython
 
36
 
37
- if "IPKernelApp" not in get_ipython().config:
38
- raise ImportError("console")
39
 
40
- print("Detected Jupyter notebook. Loading juliacall extension.")
 
 
41
 
42
- # TODO: Turn this off if juliacall does this automatically
43
- get_ipython().run_line_magic("load_ext", "juliacall")
44
- except Exception:
45
- pass
 
 
 
 
46
 
47
 
48
  from juliacall import Main as jl # type: ignore
 
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
37
 
38
+ if "IPKernelApp" not in get_ipython().config:
39
+ raise ImportError("console")
40
 
41
+ print(
42
+ "Detected Jupyter notebook. Loading juliacall extension. Set `PYSR_AUTOLOAD_EXTENSIONS=no` to disable."
43
+ )
44
 
45
+ # TODO: Turn this off if juliacall does this automatically
46
+ get_ipython().run_line_magic("load_ext", "juliacall")
47
+ except Exception:
48
+ pass
49
+ elif os.environ["PYSR_AUTOLOAD_EXTENSIONS"] not in {"no", "yes", ""}:
50
+ warnings.warn(
51
+ "PYSR_AUTOLOAD_EXTENSIONS environment variable is set to something other than 'yes' or 'no' or ''."
52
+ )
53
 
54
 
55
  from juliacall import Main as jl # type: ignore