Skip to content

Commit

Permalink
Add option to overwrite a release
Browse files Browse the repository at this point in the history
  • Loading branch information
berland committed Jan 24, 2024
1 parent f36325e commit 067f828
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
18 changes: 16 additions & 2 deletions komodo/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,14 @@ 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")
if (
not args.overwrite
and (Path(args.prefix) / args.release).exists()
and "bleeding" not in args.release
):
raise RuntimeError(
"Only bleeding builds can be overwritten unless --overwrite is supplied"
)

# append root to the temporary build dir, as we want a named root/
# directory as the distribution root, organised under the distribution name
Expand Down Expand Up @@ -388,6 +394,14 @@ def parse_args(args: List[str]) -> argparse.Namespace:
"to the `prefix` location."
),
)
optional_args.add_argument(
"--overwrite",
action="store_true",
help=(
"If set, any existing release will be overwritten. "
"If `bleeding` is part of the release name, this is impliclity true."
),
)
optional_args.add_argument(
"--cmake",
type=str,
Expand Down
24 changes: 24 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,30 @@ def test_bleeding_overwrite_by_default(tmpdir):
cli_main()


def test_overwrite_if_option_is_set(tmpdir):
sys.argv = [
"kmd",
"--workspace",
str(tmpdir),
"--overwrite",
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_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_release")

# Assert that we can overwrite the build inside "some_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 067f828

Please sign in to comment.