mirror of
https://github.com/jupyter/docker-stacks.git
synced 2025-10-15 22:12:57 +00:00

* Modify the custom Python kernel - to activate the custom environment - for the respective Jupyter Notebook and Jupyter Console Signed-off-by: Ayaz Salikhov <mathbunnyru@gmail.com> * Add DL3059 to hadolint ignore list Signed-off-by: Ayaz Salikhov <mathbunnyru@gmail.com> * Move hadolint ignore to a single line * Use python heredoc * Remove unused print * Fix style * Do not hardcode CONDA_DIR * Update custom_environment.dockerfile * Use indent=1 * Implement activate_notebook_custom_env.py as a separate script * Do not call Python manually --------- Signed-off-by: Ayaz Salikhov <mathbunnyru@gmail.com> Co-authored-by: Olivier Benz <olivier.benz@b-data.ch>
25 lines
701 B
Python
Executable File
25 lines
701 B
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) Jupyter Development Team.
|
|
# Distributed under the terms of the Modified BSD License.
|
|
import json
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
env_name = sys.argv[1]
|
|
CONDA_DIR = os.environ["CONDA_DIR"]
|
|
|
|
file = Path.home() / f".local/share/jupyter/kernels/{env_name}/kernel.json"
|
|
content = json.loads(file.read_text())
|
|
content["env"] = {
|
|
"XML_CATALOG_FILES": "",
|
|
"PATH": f"{CONDA_DIR}/envs/{env_name}/bin:$PATH",
|
|
"CONDA_PREFIX": f"{CONDA_DIR}/envs/{env_name}",
|
|
"CONDA_PROMPT_MODIFIER": f"({env_name}) ",
|
|
"CONDA_SHLVL": "2",
|
|
"CONDA_DEFAULT_ENV": env_name,
|
|
"CONDA_PREFIX_1": CONDA_DIR,
|
|
}
|
|
|
|
file.write_text(json.dumps(content, indent=1))
|