def test_get_url_requires_dvc(tmp_dir, scm): tmp_dir.scm_gen({"foo": "foo"}, commit="initial") with pytest.raises(OutputNotFoundError, match="output 'foo'"): api.get_url("foo", repo=os.fspath(tmp_dir)) with pytest.raises(OutputNotFoundError, match="output 'foo'"): api.get_url("foo", repo=f"file://{tmp_dir}")
def test_get_url_git_only_repo_throws_exception(tmp_dir, scm): tmp_dir.scm_gen({"foo": "foo"}, commit="initial") with pytest.raises(UrlNotDvcRepoError) as exc_info: api.get_url("foo", fspath(tmp_dir)) # On windows, `exc_info` has path escaped, eg: `C:\\\\Users\\\\travis` assert fspath(tmp_dir) in str(exc_info).replace("\\\\", "\\")
def test_get_url_requires_dvc(tmp_dir, scm): tmp_dir.scm_gen({"foo": "foo"}, commit="initial") with pytest.raises(UrlNotDvcRepoError, match="not a DVC repository"): api.get_url("foo", repo=fspath(tmp_dir)) with pytest.raises(UrlNotDvcRepoError): api.get_url("foo", repo="file://{}".format(tmp_dir))
def test_get_url_external(remote_url, erepo_dir): _set_remote_url_and_commit(erepo_dir.dvc, remote_url) # Using file url to force clone to tmp repo repo_url = "file://{}".format(erepo_dir) expected_url = URLInfo(remote_url) / "ac/bd18db4cc2f85cedef654fccc4a4d8" assert api.get_url("foo", repo=repo_url) == expected_url
def test_get_url_external(repo_dir, dvc_repo, erepo, remote_url): _set_remote_url_and_commit(erepo.dvc, remote_url) # Using file url to force clone to tmp repo repo_url = "file://" + erepo.dvc.root_dir expected_url = URLInfo(remote_url) / "ac/bd18db4cc2f85cedef654fccc4a4d8" assert api.get_url(repo_dir.FOO, repo=repo_url) == expected_url
def test_get_url_subrepos(tmp_dir, scm, local_cloud): subrepo = tmp_dir / "subrepo" make_subrepo(subrepo, scm, config=local_cloud.config) with subrepo.chdir(): subrepo.dvc_gen( {"dir": {"foo": "foo"}, "bar": "bar"}, commit="add files" ) subrepo.dvc.push() path = os.path.relpath(local_cloud.config["url"]) expected_url = os.path.join(path, "ac", "bd18db4cc2f85cedef654fccc4a4d8") assert api.get_url(os.path.join("subrepo", "dir", "foo")) == expected_url expected_url = os.path.join(path, "37", "b51d194a7513e45b56f6524f2d51f2") assert api.get_url("subrepo/bar") == expected_url
def __init__(self, config): s3 = boto3.client("s3") remote_path = api.get_url(config["model_path"], repo=config["dvc_repo"]) o = urlparse(remote_path) bucket, key = o.netloc, o.path.lstrip('/') s3.download_file(bucket, key, "/tmp/trained_model.pkl") self.model = load(open("/tmp/trained_model.pkl", "rb"))
def test_get_url_granular(tmp_dir, dvc, s3): tmp_dir.add_remote(config=s3.config) tmp_dir.dvc_gen( {"dir": {"foo": "foo", "bar": "bar", "nested": {"file": "file"}}} ) expected_url = URLInfo(s3.url) / "5f/c28ea78987408341668eba6525ebd1.dir" assert api.get_url("dir") == expected_url expected_url = URLInfo(s3.url) / "ac/bd18db4cc2f85cedef654fccc4a4d8" assert api.get_url("dir/foo") == expected_url expected_url = URLInfo(s3.url) / "37/b51d194a7513e45b56f6524f2d51f2" assert api.get_url("dir/bar") == expected_url expected_url = URLInfo(s3.url) / "8c/7dd922ad47494fc02c388e12c00eac" assert api.get_url(os.path.join("dir", "nested", "file")) == expected_url
def test_get_url(repo_dir, dvc_repo, remote): remote_url = remote.get_url() run_dvc("remote", "add", "-d", "upstream", remote_url) dvc_repo.add(repo_dir.FOO) expected_url = URLInfo(remote_url) / "ac/bd18db4cc2f85cedef654fccc4a4d8" assert api.get_url(repo_dir.FOO) == expected_url
def test_get_url_external(tmp_dir, erepo_dir, cloud): erepo_dir.add_remote(config=cloud.config) with erepo_dir.chdir(): erepo_dir.dvc_gen("foo", "foo", commit="add foo") # Using file url to force clone to tmp repo repo_url = f"file://{erepo_dir}" expected_url = URLInfo(cloud.url) / "ac/bd18db4cc2f85cedef654fccc4a4d8" assert api.get_url("foo", repo=repo_url) == expected_url
def test_get_url_external(erepo_dir, remote_url, setup_remote): setup_remote(erepo_dir.dvc, url=remote_url) with erepo_dir.chdir(): erepo_dir.dvc_gen("foo", "foo", commit="add foo") # Using file url to force clone to tmp repo repo_url = f"file://{erepo_dir}" expected_url = URLInfo(remote_url) / "ac/bd18db4cc2f85cedef654fccc4a4d8" assert api.get_url("foo", repo=repo_url) == expected_url
def test_get_url(repo_dir, dvc_repo, remote): remote_url = remote.get_url() run_dvc("remote", "add", "-d", "upstream", remote_url) dvc_repo.add(repo_dir.FOO) assert api.get_url(repo_dir.FOO) == "%s/%s" % ( remote_url, "ac/bd18db4cc2f85cedef654fccc4a4d8", )
def _show_url(self): from dvc.api import get_url try: url = get_url(self.args.path, repo=self.args.url, rev=self.args.rev) logger.info(url) except DvcException: logger.exception("failed to show URL") return 1 return 0
def test_get_url_granular(tmp_dir, dvc, cloud): tmp_dir.add_remote(config=cloud.config) tmp_dir.dvc_gen( {"dir": { "foo": "foo", "bar": "bar", "nested": { "file": "file" } }}) expected_url = (cloud / "5f" / "c28ea78987408341668eba6525ebd1.dir").url assert api.get_url("dir") == expected_url expected_url = (cloud / "ac" / "bd18db4cc2f85cedef654fccc4a4d8").url assert api.get_url("dir/foo") == expected_url expected_url = (cloud / "37" / "b51d194a7513e45b56f6524f2d51f2").url assert api.get_url("dir/bar") == expected_url expected_url = (cloud / "8c" / "7dd922ad47494fc02c388e12c00eac").url assert api.get_url(os.path.join("dir", "nested", "file")) == expected_url
def _show_url(self): from dvc.api import get_url from dvc.ui import ui try: url = get_url(self.args.path, repo=self.args.url, rev=self.args.rev) ui.write(url, force=True) except DvcException: logger.exception("failed to show URL") return 1 return 0
def test_get_url(self, tmp_dir, dvc, remote): tmp_dir.dvc_gen("foo", "foo") expected_url = (remote / "ac/bd18db4cc2f85cedef654fccc4a4d8").url assert api.get_url("foo") == expected_url
def test_get_url(tmp_dir, dvc, remote): tmp_dir.dvc_gen("foo", "foo") expected_url = URLInfo(remote.url) / "ac/bd18db4cc2f85cedef654fccc4a4d8" assert api.get_url("foo") == expected_url
def test_get_url(tmp_dir, dvc, remote_url): run_dvc("remote", "add", "-d", "upstream", remote_url) tmp_dir.dvc_gen("foo", "foo") expected_url = URLInfo(remote_url) / "ac/bd18db4cc2f85cedef654fccc4a4d8" assert api.get_url("foo") == expected_url
def test_get_url(remote_url, tmp_dir, dvc, repo_template): run_dvc("remote", "add", "-d", "upstream", remote_url) dvc.add("foo") expected_url = URLInfo(remote_url) / "ac/bd18db4cc2f85cedef654fccc4a4d8" assert api.get_url("foo") == expected_url