Skip to content

Commit

Permalink
Parse complex tags correctly (#372)
Browse files Browse the repository at this point in the history
close #371
  • Loading branch information
aguschin authored Jun 28, 2023
1 parent 66b875f commit faf17cc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
6 changes: 3 additions & 3 deletions gto/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ def name_tag(
if action not in TagTemplates:
raise UnknownAction(action=action)

artifact = name_to_tag(artifact)

tag = TagTemplates[action].format(artifact=artifact, version=version, stage=stage)
tag = TagTemplates[action].format(
artifact=name_to_tag(artifact), version=version, stage=stage
)
if simple:
return tag
if repo is None:
Expand Down
32 changes: 28 additions & 4 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ def repo_with_artifact(init_showcase_semver):
) as f:
f.write("rf: \n type: model\n path: models/random-forest.pkl\n")
repo.index.add(["artifacts.yaml"])
repo.index.commit("Added index")
repo.index.commit("Commit 1")
with open(
os.path.join(repo.working_dir, "artifacts.yaml"), "w", encoding="utf8"
) as f:
f.write("rf: \n type: model\n path: models/random-forest.pklx\n")
repo.index.add(["artifacts.yaml"])
repo.index.commit("Added index")
repo.index.commit("Commit 2")
return repo, "new-artifact"


Expand Down Expand Up @@ -149,8 +149,16 @@ def test_register_deregister(repo_with_artifact):
assert len(gto.api._show_versions(repo.working_dir, name, ref="HEAD")) == 0


def test_assign(repo_with_artifact: Tuple[git.Repo, str]):
repo, name = repo_with_artifact
@pytest.mark.parametrize(
"name",
(
"model",
"folder:artifact",
"some/folder:some/artifact",
),
)
def test_assign(repo_with_artifact: Tuple[git.Repo, str], name):
repo, _ = repo_with_artifact
stage = "staging"
repo.create_tag("v1.0.0")
repo.create_tag("wrong-tag-unrelated")
Expand Down Expand Up @@ -184,6 +192,22 @@ def test_assign(repo_with_artifact: Tuple[git.Repo, str]):
),
{"created_at", "assignments", "unassignments", "tag", "activated_at"},
)
event = gto.api.assign(
repo.working_dir,
name,
stage,
ref="HEAD^1",
name_version="v0.0.2",
message=message,
author=author,
author_email=author_email,
)
assignments = gto.api.find_versions_in_stage(repo.working_dir, name, stage)
assert len(assignments) == 1
assignments = gto.api.find_versions_in_stage(
repo.working_dir, name, stage, versions_per_stage=-1
)
assert len(assignments) == 2


def test_assign_skip_registration(repo_with_artifact: Tuple[git.Repo, str]):
Expand Down

0 comments on commit faf17cc

Please sign in to comment.