Skip to content

Commit

Permalink
Bugfixes (#148)
Browse files Browse the repository at this point in the history
* fix updating annotation without type and keeping old labels instead of removing them

* fix parsing tags on incrementing inside promote

* fix tests
  • Loading branch information
aguschin authored Apr 29, 2022
1 parent 3aaed1c commit f971be5
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 30 deletions.
3 changes: 2 additions & 1 deletion gto/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def inner(ctx, *iargs, **ikwargs):
raise
with cli_echo():
echo(EMOJI_FAIL + color(str(e), col=typer.colors.RED))
raise typer.Exit(1)
raise typer.Exit(1) from e
except Exception as e: # pylint: disable=broad-except
error = str(type(e))
if ctx.obj["traceback"]:
Expand All @@ -344,6 +344,7 @@ def inner(ctx, *iargs, **ikwargs):
echo(
"Please report it here: <https://github.com/iterative/gto/issues>"
)
raise typer.Exit(1) from e
finally:
# TODO: analytics
error # pylint: disable=pointless-statement
Expand Down
9 changes: 4 additions & 5 deletions gto/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def add(
self.state[name].virtual = False
elif path:
self.state[name].virtual = True
self.state[name].labels = labels or self.state[name].labels
self.state[name].labels = sorted(set(self.state[name].labels).union(labels))
self.state[name].description = description or self.state[name].description
else:
self.state[name] = Artifact(
Expand Down Expand Up @@ -166,9 +166,8 @@ def get_history(self) -> Dict[str, Index]:
raise NotImplementedError

def add(self, name, type, path, must_exist, labels, description, update):
if labels is None:
labels = []
self.config.assert_type(type)
if type:
self.config.assert_type(type)
if must_exist:
if not path:
raise WrongArgs("`path` is required when `must_exist` is set to True")
Expand All @@ -182,7 +181,7 @@ def add(self, name, type, path, must_exist, labels, description, update):
type=type,
path=path,
must_exist=must_exist,
labels=labels,
labels=labels or [],
description=description,
update=update,
)
Expand Down
5 changes: 3 additions & 2 deletions gto/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ def name_tag(
raise MissingArg(arg="repo")
numbers = []
for tag in repo.tags:
parsed = parse_name(tag.name)
parsed = parse_name(tag.name, raise_on_fail=False)
if (
(parsed[NAME] == name)
parsed
and (parsed[NAME] == name)
and (parsed[ACTION] == Action.PROMOTE)
and (NUMBER in parsed)
):
Expand Down
4 changes: 3 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ def test_register(repo_with_artifact):
assert latest.name == vname2


def test_promote(repo_with_artifact):
def test_promote(repo_with_artifact: Tuple[git.Repo, str]):
repo, name = repo_with_artifact
stage = "staging"
repo.create_tag("v1.0.0")
repo.create_tag("wrong-tag-unrelated")
gto.api.promote(
repo.working_dir, name, stage, promote_ref="HEAD", name_version="v0.0.1"
)
Expand Down
37 changes: 19 additions & 18 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,11 @@ def test_commands(showcase):
"type": "new-type",
"path": "new/path",
"labels": [
"some-label",
"another-label"
"another-label",
"new-label",
"some-label"
],
"description": "some description"
"description": "new description"
}
"""

Expand All @@ -162,15 +163,28 @@ def test_annotate(empty_git_repo: Tuple[git.Repo, Callable]):
],
"",
)
_check_successful_cmd(
"annotate",
[
"-r",
repo.working_dir,
name,
"--label",
"new-label",
"--description",
"new description",
],
"",
)
artifact = get_index(repo.working_dir, file=True).get_index().state[name]
_check_obj(
artifact,
dict(
type="new-type",
path="new/path",
virtual=True,
labels=["some-label", "another-label"],
description="some description",
labels=["another-label", "new-label", "some-label"],
description="new description",
),
[],
)
Expand Down Expand Up @@ -232,16 +246,3 @@ def test_promote(repo_with_commit: Tuple[git.Repo, Callable]):
["-r", repo.working_dir, "nn2", "prod", "HEAD", "--version", "1.0.0"],
"❌ Version '1.0.0' is not valid. Example of valid version: 'v1.0.0'\n",
)

_check_successful_cmd(
"promote",
["-r", repo.working_dir, "x", "prod", "HEAD", "--simple"],
"Created git tag '[email protected]' that registers a new version\n"
"Created git tag 'x#prod' that promotes 'v0.0.1'\n",
)

_check_failing_cmd(
"promote",
["-r", repo.working_dir, "x", "prod", "HEAD", "--simple"],
"❌ Version is already in stage 'prod'\n",
)
12 changes: 9 additions & 3 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, Sequence
from typing import Any, Dict, Sequence, Set, Union

from pydantic import BaseModel

Expand All @@ -8,12 +8,18 @@
# assert a == b


def _check_obj(obj: BaseModel, values: Dict[str, Any], skip_keys: Sequence[str]):
def _check_obj(
obj: BaseModel, values: Dict[str, Any], skip_keys: Union[Set[str], Sequence[str]]
):
obj_values = obj.dict(exclude=set(skip_keys))
assert obj_values == values


def _check_dict(obj: Dict[str, Any], values: Dict[str, Any], skip_keys: Sequence[str]):
def _check_dict(
obj: Dict[str, Any],
values: Dict[str, Any],
skip_keys: Union[Set[str], Sequence[str]],
):
obj_values = {k: v for k, v in obj.items() if k not in skip_keys}
values = {k: v for k, v in values.items() if k not in skip_keys}
assert obj_values == values

0 comments on commit f971be5

Please sign in to comment.