-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from typing import Any, Dict, Optional | ||
|
||
from dvc.repo import Repo | ||
|
||
|
||
def artifacts_show( # noqa, pylint: disable=redefined-builtin | ||
name: str, | ||
version: Optional[str] = None, | ||
stage: Optional[str] = None, | ||
repo: Optional[str] = None, | ||
) -> Dict[str, str]: | ||
""" | ||
Return path and Git revision for an artifact in a DVC project. | ||
The resulting path and revision can be used in conjunction with other dvc.api | ||
calls to open and read the artifact. | ||
Args: | ||
name (str): name of the artifact to open. | ||
version (str, optional): version of the artifact to open. Defaults to | ||
the latest version. | ||
stage (str, optional): name of the model registry stage. | ||
repo: (str, optional): path or URL for the DVC repo. | ||
Returns: | ||
Dictionary of the form: | ||
{ | ||
"rev": ..., | ||
"path": ..., | ||
} | ||
Raises: | ||
dvc.exceptions.ArtifactNotFoundError: The specified artifact was not found in | ||
the repo. | ||
""" | ||
if version and stage: | ||
raise ValueError("Artifact version and stage are mutually exclusive.") | ||
|
||
repo_kwargs: Dict[str, Any] = { | ||
"subrepos": True, | ||
"uninitialized": True, | ||
} | ||
with Repo.open(repo, **repo_kwargs) as _repo: | ||
rev = _repo.artifacts.get_rev(name, version=version, stage=stage) | ||
with _repo.switch(rev): | ||
path = _repo.artifacts.get_path(name) | ||
return {"rev": rev, "path": path} |