Skip to content

Commit

Permalink
Copy jupyter data and config dirs from the komodo release in komodoen…
Browse files Browse the repository at this point in the history
…v-update
  • Loading branch information
larsevj committed May 14, 2024
1 parent d1235f4 commit c539ebc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
4 changes: 3 additions & 1 deletion komodoenv/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ def main(args=None):
texts = {
"beta": blue(
"Komodoenv is still in beta. Be aware that issues might occur and "
"recreating environments once in a while is necessary.\n\n"
"recreating environments once in a while is necessary.\n"
"If you encounter issues with the Jupyter environment, try "
"running 'komodoenv-update' or sourcing the komodoenv again.\n\n"
"For progress on stabilising komodoenv, see: "
"https://github.com/equinor/komodoenv/milestone/1\n"
),
Expand Down
37 changes: 37 additions & 0 deletions komodoenv/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import platform
import re
import shutil
import subprocess
import sys
from argparse import ArgumentParser
from pathlib import Path
Expand Down Expand Up @@ -221,6 +222,38 @@ def check_same_distro(config: dict) -> bool:
return False


def copy_jupyter_dirs(config: dict) -> None:
"""
Notebook 7 does not play well with komodoenv, and so we need to copy the
data and config dirs from the komodo release.
"""
srcpath = Path(config["komodo-root"]) / config["current-release"] / "root"
if not srcpath.is_dir():
srcpath = Path(str(srcpath) + rhel_version_suffix()) / "root"
dstpath = Path(__file__).resolve().parents[1]
notebook_version = get_pkg_version(config, srcpath, "notebook")
if not (notebook_version and int(notebook_version[0]) >= 7):
return
src_share = srcpath / "share" / "jupyter"
src_etc = srcpath / "etc" / "jupyter"
dst_share = dstpath / "share"
dst_etc = dstpath / "etc"
if not (src_share.is_dir() or src_etc.is_dir()):
return
dst_etc.mkdir(exist_ok=True)
dst_share.mkdir(exist_ok=True)
try:
subprocess.run(
["rsync", "-a", "--ignore-existing", src_share, dst_share], check=True
)
subprocess.run(
["rsync", "-a", "--ignore-existing", src_etc, dst_etc], check=True
)
except subprocess.CalledProcessError as err:
print(f"An error occurred when fixing up jupyter environment: \n{err}")
print("Jupyter may not work as intended in the komodoenv.")


def get_pkg_version(
config: dict, srcpath: Path, package: str = "komodoenv"
) -> List[str]:
Expand Down Expand Up @@ -401,6 +434,8 @@ def main(args: List[str] = None):
if not check_same_distro(config):
return

copy_jupyter_dirs(config)

current = current_track(config)

if not should_update(config, current):
Expand Down Expand Up @@ -434,6 +469,8 @@ def main(args: List[str] = None):
update_bins(srcpath, dstpath)
update_enable_script(srcpath, dstpath)
create_pth(config, srcpath, dstpath)
# we run copy_jupyter_dirs before and after updating to make sure it is always run
copy_jupyter_dirs(config)


if __name__ == "__main__":
Expand Down

0 comments on commit c539ebc

Please sign in to comment.