2023-07-21 14:54:09 +01:00
|
|
|
# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK
|
2023-07-04 13:11:06 +01:00
|
|
|
"""Contains default jupyter notebooks which demonstrate PrimAITE functionality."""
|
2023-07-17 19:28:43 +01:00
|
|
|
|
2023-06-07 22:40:16 +01:00
|
|
|
import importlib.util
|
|
|
|
|
import os
|
|
|
|
|
import subprocess
|
|
|
|
|
import sys
|
2023-07-18 10:21:06 +01:00
|
|
|
from logging import Logger
|
2023-06-07 22:40:16 +01:00
|
|
|
|
2023-07-21 14:00:50 +01:00
|
|
|
from primaite import getLogger, PRIMAITE_PATHS
|
2023-06-07 22:40:16 +01:00
|
|
|
|
2023-07-18 10:21:06 +01:00
|
|
|
_LOGGER: Logger = getLogger(__name__)
|
2023-06-07 22:40:16 +01:00
|
|
|
|
2023-07-14 12:01:38 +01:00
|
|
|
|
|
|
|
|
def start_jupyter_session() -> None:
|
2023-07-07 10:28:00 +01:00
|
|
|
"""
|
|
|
|
|
Starts a new Jupyter notebook session in the app notebooks directory.
|
2023-06-07 22:40:16 +01:00
|
|
|
|
|
|
|
|
Currently only works on Windows OS.
|
|
|
|
|
|
|
|
|
|
.. todo:: Figure out how to get this working for Linux and MacOS too.
|
|
|
|
|
"""
|
2023-06-09 16:44:49 +01:00
|
|
|
if importlib.util.find_spec("jupyter") is not None:
|
|
|
|
|
jupyter_cmd = "python3 -m jupyter lab"
|
|
|
|
|
if sys.platform == "win32":
|
|
|
|
|
jupyter_cmd = "jupyter lab"
|
|
|
|
|
|
|
|
|
|
working_dir = os.getcwd()
|
2023-07-21 14:00:50 +01:00
|
|
|
os.chdir(PRIMAITE_PATHS.user_notebooks_path)
|
2023-06-09 16:44:49 +01:00
|
|
|
subprocess.Popen(jupyter_cmd)
|
|
|
|
|
os.chdir(working_dir)
|
2023-06-07 22:40:16 +01:00
|
|
|
else:
|
2023-06-09 16:44:49 +01:00
|
|
|
# Jupyter is not installed
|
|
|
|
|
_LOGGER.error("Cannot start jupyter lab as it is not installed")
|