initial-dev, ready to test

This commit is contained in:
Brennen Raimer
2024-05-13 14:49:19 -04:00
parent 40ba62ff6c
commit 6b7099a933
4 changed files with 520 additions and 1 deletions

50
jupyter_lab_config.py Normal file
View File

@@ -0,0 +1,50 @@
import logging
import platform
from itertools import product
from os import environ
from pathlib import Path
# generated if you run `jupyter lab --generate-config`, used for additional configuration
DEFAULT_CONFIG_FILE = Path.home() / ".jupyter/jupyter_lab_config.py"
# user's home will be the root path of jupyter's file explorer
c.ServerApp.root_dir = str(Path.home())
# find a chromium-based browser on the system to use.
if platform.system() == "Windows":
# prefers Microsoft Edge on Windows
cmds = (
"Microsoft/Edge/Application/msedge.exe",
"Google/Chrome/Application/chrome.exe",
)
path_elements = map(Path, (environ["ProgramFiles"], environ["ProgramFiles(x86)"]))
elif platform.system() == "Linux":
# prefers Google Chrome on Linux due to popularity of the browser
cmds = ("google-chrome", "microsoft-edge", "brave", "chromium")
path_elements = map(Path, environ["PATH"].split(":"))
elif platform.system() == "Darwin":
# also prefers Google Chrome on MacOS due to popularity of the browser
cmds = ("Contents/MacOS/Google Chrome", "Contents/MacOS/Microsoft Edge")
path_elements = [Path(f"/Applications/{Path(cmd).name}.app") for cmd in cmds]
# use the first chromium-based browser found as the browser to run Jupyter in app mode
for cmd, path_element in product(cmds, path_elements):
browser = path_element / cmd
if browser.exists():
c.ServerApp.browser = (
f'"{browser}" --start-maximized --profile-directory=Default --app=%s'
)
break
else:
logging.getLogger(__name__).warning(
"No Chromium-based browser was found on this system, therefore Jupyter will run "
+ "in a new tab of the system-default browser"
)
# read and exec default config file for additional config/overrides
if DEFAULT_CONFIG_FILE.exists():
with open(DEFAULT_CONFIG_FILE, "r") as config_file:
exec(config_file.read())