diff --git a/dvc/api.py b/dvc/api.py index d1312baaf3..98763d16a7 100644 --- a/dvc/api.py +++ b/dvc/api.py @@ -7,31 +7,44 @@ class UrlNotDvcRepoError(DvcException): - """Thrown if given URL is not a DVC repository. - - Args: - url (str): URL to the repository - """ + """Thrown if the given URL is not a DVC repository.""" def __init__(self, url): super().__init__("'{}' is not a DVC repository.".format(url)) def get_url(path, repo=None, rev=None, remote=None): - """Returns URL to the storage location of a data artifact tracked - by DVC, specified by its path in a repo. + """ + Returns the URL to the storage location of a data file or directory tracked + in a DVC repo. For Git repos, HEAD is used unless a rev argument is + supplied. The default remote is tried unless a remote argument is supplied. - NOTE: There's no guarantee that the file actually exists in that location. + Raises UrlNotDvcRepoError if repo is not a DVC project. + + NOTE: This function does not check for the actual existence of the file or + directory in the remote storage. """ with _make_repo(repo, rev=rev) as _repo: - _require_dvc(_repo) + if not isinstance(_repo, Repo): + raise UrlNotDvcRepoError(_repo.url) out = _repo.find_out_by_relpath(path) remote_obj = _repo.cloud.get_remote(remote) return str(remote_obj.checksum_to_path_info(out.checksum)) def open(path, repo=None, rev=None, remote=None, mode="r", encoding=None): - """Context manager to open a tracked file as a file object.""" + """ + Open file in the supplied path tracked in a repo (both DVC projects and + plain Git repos are supported). For Git repos, HEAD is used unless a rev + argument is supplied. The default remote is tried unless a remote argument + is supplied. It may only be used as a context manager: + + with dvc.api.open( + 'path/to/file', + repo='https://example.com/url/to/repo' + ) as fd: + # ... Handle file object fd + """ args = (path,) kwargs = { "repo": repo, @@ -63,7 +76,11 @@ def _open(path, repo=None, rev=None, remote=None, mode="r", encoding=None): def read(path, repo=None, rev=None, remote=None, mode="r", encoding=None): - """Returns the contents of a tracked file.""" + """ + Returns the contents of a tracked file (by DVC or Git). For Git repos, HEAD + is used unless a rev argument is supplied. The default remote is tried + unless a remote argument is supplied. + """ with open( path, repo=repo, rev=rev, remote=remote, mode=mode, encoding=encoding ) as fd: @@ -81,8 +98,3 @@ def _make_repo(repo_url=None, rev=None): pass # fallthrough to external_repo with external_repo(url=repo_url, rev=rev) as repo: yield repo - - -def _require_dvc(repo): - if not isinstance(repo, Repo): - raise UrlNotDvcRepoError(repo.url) diff --git a/dvc/command/metrics.py b/dvc/command/metrics.py index 6cb3887fd7..038e2f2669 100644 --- a/dvc/command/metrics.py +++ b/dvc/command/metrics.py @@ -187,8 +187,7 @@ def add_parser(subparsers, parent_parser): metrics_show_parser.add_argument( "targets", nargs="*", - help="Metric files or directories (see -R) to show " - "(leave empty to display all)", + help="Metric files or directories (see -R) to show", ) metrics_show_parser.add_argument( "-t", diff --git a/dvc/config.py b/dvc/config.py index 1d6118ec45..6d16181051 100644 --- a/dvc/config.py +++ b/dvc/config.py @@ -201,9 +201,8 @@ class Config(dict): validate (bool): optional flag to tell dvc if it should validate the config or just load it as is. 'True' by default. - Raises: - ConfigError: thrown when config has an invalid format. + ConfigError: thrown if config has an invalid format. """ APPNAME = "dvc" @@ -272,7 +271,7 @@ def load(self, validate=True): """Loads config from all the config files. Raises: - dvc.config.ConfigError: thrown if config has invalid format. + ConfigError: thrown if config has an invalid format. """ conf = {} for level in self.LEVELS: @@ -332,7 +331,7 @@ def _map_dirs(conf, func): @contextmanager def edit(self, level="repo"): if level in {"repo", "local"} and self.dvc_dir is None: - raise ConfigError("Not inside a dvc repo") + raise ConfigError("Not inside a DVC repo") conf = self.load_one(level) yield conf diff --git a/dvc/scm/__init__.py b/dvc/scm/__init__.py index 62f106314d..15a75796ff 100644 --- a/dvc/scm/__init__.py +++ b/dvc/scm/__init__.py @@ -4,8 +4,8 @@ from dvc.scm.git import Git -# just a sugar to point that this is an actual implementation for a dvc -# project under no SCM control +# Syntactic sugar to signal that this is an actual implementation for a DVC +# project under no SCM control. class NoSCM(Base): pass