Skip to content

Commit

Permalink
Add guard to avoid overwriting releases
Browse files Browse the repository at this point in the history
Only bleeding builds will be overwritten by default.
  • Loading branch information
berland committed Jan 24, 2024
1 parent 990ea75 commit f36325e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
3 changes: 3 additions & 0 deletions komodo/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ def _main(args):
if args.download and not args.build:
sys.exit(0)

if (Path(args.prefix) / args.release).exists() and "bleeding" not in args.release:
raise RuntimeError("Only bleeding builds can be overwritten")

# append root to the temporary build dir, as we want a named root/
# directory as the distribution root, organised under the distribution name
tmp_prefix = abs_prefix / args.release / "root"
Expand Down
51 changes: 51 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,57 @@ def test_minimal_main(args, tmpdir):
assert not os.path.exists(os.path.join(release_path, "local.csh"))


def test_no_overwrite_by_default(tmpdir):
sys.argv = [
"kmd",
"--workspace",
str(tmpdir),
os.path.join(_get_test_root(), "data/cli/minimal_release.yml"),
os.path.join(_get_test_root(), "data/cli/minimal_repository.yml"),
"--prefix",
"prefix",
"--release",
"existing_release",
"--extra-data-dirs", # Required to find test_python_builtin.sh.
os.path.join(_get_test_root(), "data/cli"),
]
cli_main()
with pytest.raises(
RuntimeError, match="Downloading to non-empty directory downloads"
):
cli_main()

# Try another rerun after we have removed the downloads and remainder from
# failed build above:
shutil.rmtree(tmpdir / "downloads")
shutil.rmtree(tmpdir / ".existing_release")
with pytest.raises(RuntimeError, match="Only bleeding builds can be overwritten"):
cli_main()


def test_bleeding_overwrite_by_default(tmpdir):
sys.argv = [
"kmd",
"--workspace",
str(tmpdir),
os.path.join(_get_test_root(), "data/cli/minimal_release.yml"),
os.path.join(_get_test_root(), "data/cli/minimal_repository.yml"),
"--prefix",
"prefix",
"--release",
"some_bleeding_release",
"--extra-data-dirs", # Required to find test_python_builtin.sh.
os.path.join(_get_test_root(), "data/cli"),
]
cli_main()
# Remove non-interesting leftovers from first build:
shutil.rmtree(tmpdir / "downloads")
shutil.rmtree(tmpdir / ".some_bleeding_release")

# Assert that we can overwrite the build inside "some_bleeding_release"
cli_main()


def test_pyver_is_deprecated():
"""Pyver is not being used anywhere in the code and has been deprecated.
This test ensures that its use prints a message in stderr.
Expand Down

0 comments on commit f36325e

Please sign in to comment.