Spaces:
Sleeping
Sleeping
Allow user to disable juliacall extension
Browse files- 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 |
-
|
| 35 |
-
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
except Exception:
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|