diff --git a/komodoenv/__main__.py b/komodoenv/__main__.py index 7dd6634..8d2a5fa 100644 --- a/komodoenv/__main__.py +++ b/komodoenv/__main__.py @@ -202,7 +202,8 @@ def main() -> None: release = root / args.release if not (release / "enable").is_file(): - sys.exit(f"'{release !s}' is not a valid komodo release!") + msg = f"'{release !s}' is not a valid komodo release!" + raise ValueError(msg) if not args.track: release, track = resolve_release( @@ -211,7 +212,7 @@ def main() -> None: no_update=args.no_update, ) else: - track = (root / args.track).resolve() + track = root / args.track if not (release / "enable").is_file(): sys.exit(f"'{track !s}' is not a valid komodo release!") destination = Path(args.destination).absolute() diff --git a/komodoenv/update.py b/komodoenv/update.py index 60e3d5d..c055de4 100644 --- a/komodoenv/update.py +++ b/komodoenv/update.py @@ -179,8 +179,8 @@ class KomodoenvUpdateNamespace(Namespace): """ -def read_config() -> Dict[str, str]: - with open(Path(__file__).parents[2] / "komodoenv.conf", encoding="utf-8") as f: +def read_config(config_path: Path) -> Dict[str, str]: + with open(config_path, encoding="utf-8") as f: lines = f.readlines() config = {} for line in lines: @@ -463,7 +463,9 @@ def parse_args(args: List[str]) -> KomodoenvUpdateNamespace: def main() -> None: args = parse_args(sys.argv[1:]) - config = read_config() + # kmd_env/root/bin/komodoenv-update + # kmd_env/komodoenv.conf + config = read_config(Path(__file__).parents[2] / "komodoenv.conf") if not check_same_distro(config): return diff --git a/tests/test_integration.py b/tests/test_integration.py index 081bdff..bb440d0 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -2,6 +2,7 @@ from subprocess import PIPE, STDOUT, Popen, check_output from komodoenv.__main__ import main as _main +from komodoenv.update import read_config def bash(script): @@ -124,6 +125,21 @@ def test_autodetect(komodo_root, tmp_path): assert bash(script) == 0 +def test_manual_tracking(komodo_root, tmp_path): + script = f"""\ + source {komodo_root}/2030.01-py38/enable + {sys.executable} -m komodoenv --root={komodo_root} {tmp_path}/kenv --track stable + + source {tmp_path}/kenv/enable + [[ $(which python) == "{tmp_path}/kenv/root/bin/python" ]] + komodoenv-update + """ + assert bash(script) == 0 + assert ( + read_config(tmp_path / "kenv" / "komodoenv.conf")["tracked-release"] == "stable" + ) + + def main(*args): """Convenience function because it looks nicer""" sys.argv = ["komodoenv", *args] diff --git a/tests/test_main.py b/tests/test_main.py index 0a59868..f9e1cfd 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,3 +1,4 @@ +import sys from pathlib import Path import komodoenv.__main__ as main @@ -84,3 +85,20 @@ def test_resolve_no_update(komodo_root, expect, name): ) assert release == tracked assert release == komodo_root / expect + + +def test_no_enable_file(tmp_path): + (tmp_path / "some_release").mkdir() + sys.argv = [ + "komodoenv", + "--root", + str(tmp_path), + "--release", + "some_release", + "--no-update", + "my_kenv", + ] + with pytest.raises( + ValueError, match="'*/some_release' is not a valid komodo release!" + ): + main.main()