From 87d79a14b6cc917b02664b6b0c338a6a2bbce221 Mon Sep 17 00:00:00 2001 From: David de la Iglesia Castro Date: Tue, 26 Sep 2023 09:58:42 +0200 Subject: [PATCH] log_artifact: Use name validation from GTO. (#715) * log_artifact: Use name validation from GTO. The function we were using from `dvc.repo.artifacts` was dropped in https://github.com/iterative/dvc/pull/9770 deps: bump "dvc>3.22.1" * deps: Add `gto`. --- pyproject.toml | 3 ++- src/dvclive/live.py | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2ae3670b..9bccf826 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,10 +31,11 @@ classifiers = [ ] dynamic = ["version"] dependencies = [ - "dvc>=3.22.0", + "dvc>=3.22.1", "dvc-render>=0.6.0,<1.0", "dvc-studio-client>=0.15.0,<1", "funcy", + "gto", "ruamel.yaml", "scmrepo", ] diff --git a/src/dvclive/live.py b/src/dvclive/live.py index 2b19fe6e..8fa378e4 100644 --- a/src/dvclive/live.py +++ b/src/dvclive/live.py @@ -461,7 +461,8 @@ def log_artifact( raise InvalidDataTypeError(path, type(path)) if self._dvc_repo is not None: - from dvc.repo.artifacts import name_is_compatible + from gto.constants import assert_name_is_valid + from gto.exceptions import ValidationError if copy: path = clean_and_copy_into(path, self.artifacts_dir) @@ -471,14 +472,15 @@ def log_artifact( if any((type, name, desc, labels, meta)): name = name or Path(path).stem - if name_is_compatible(name): + try: + assert_name_is_valid(name) self._artifacts[name] = { k: v for k, v in locals().items() if k in ("path", "type", "desc", "labels", "meta") and v is not None } - else: + except ValidationError: logger.warning( "Can't use '%s' as artifact name (ID)." " It will not be included in the `artifacts` section.",