Merge branch 'master' into refactor-remote-azure

This commit is contained in:
Ruslan Kuprieiev
2020-01-05 04:24:59 +02:00
committed by GitHub
11 changed files with 63 additions and 73 deletions
+1 -5
View File
@@ -194,11 +194,7 @@ class RemoteS3(RemoteBASE):
}
paginator = self.s3.get_paginator(self.list_objects_api)
for page in paginator.paginate(**kwargs):
contents = page.get("Contents", None)
if not contents:
continue
for item in contents:
yield item
yield from page.get("Contents", ())
def _list_paths(self, path_info, max_items=None):
return (
+1 -2
View File
@@ -260,8 +260,7 @@ class RemoteSSH(RemoteBASE):
def list_cache_paths(self):
with self.ssh(self.path_info) as ssh:
# If we simply return an iterator then with above closes instantly
for path in ssh.walk_files(self.path_info.path):
yield path
yield from ssh.walk_files(self.path_info.path)
def walk_files(self, path_info):
with self.ssh(path_info) as ssh:
+1 -2
View File
@@ -139,8 +139,7 @@ class SSHConnection:
for dname in dirs:
newpath = posixpath.join(directory, dname)
for entry in self.walk(newpath, topdown=topdown):
yield entry
yield from self.walk(newpath, topdown=topdown)
if not topdown:
yield directory, dirs, nondirs
+2 -4
View File
@@ -128,8 +128,7 @@ class GitTree(BaseTree):
yield os.path.normpath(tree.abspath), dirs, nondirs
for i in dirs:
for x in self._walk(tree[i], topdown=True):
yield x
yield from self._walk(tree[i], topdown=topdown)
if not topdown:
yield os.path.normpath(tree.abspath), dirs, nondirs
@@ -146,5 +145,4 @@ class GitTree(BaseTree):
if tree is None:
raise IOError(errno.ENOENT, "No such file")
for x in self._walk(tree, topdown):
yield x
yield from self._walk(tree, topdown=topdown)
+12 -10
View File
@@ -139,6 +139,7 @@ class TmpDir(pathlib.Path):
if commit:
self.scm.commit(commit)
# contexts
@contextmanager
def chdir(self):
old = os.getcwd()
@@ -148,6 +149,16 @@ class TmpDir(pathlib.Path):
finally:
os.chdir(old)
@contextmanager
def branch(self, name, new=False):
self._require("scm")
old = self.scm.active_branch()
try:
self.scm.checkout(name, create_new=new)
yield
finally:
self.scm.checkout(old)
# Introspection methods
def list(self):
return [p.name for p in self.iterdir()]
@@ -265,21 +276,12 @@ def erepo_dir(tmp_path_factory, monkeypatch):
_git_init()
path.dvc = Repo.init()
path.scm = path.dvc.scm
path.dvc_gen(REPO_TEMPLATE, commit="init repo")
path.scm.commit("init dvc")
rconfig = RemoteConfig(path.dvc.config)
rconfig.add("upstream", path.dvc.cache.local.cache_dir, default=True)
path.scm_add([path.dvc.config.config_file], commit="add remote")
path.dvc_gen("version", "master")
path.scm_add([".gitignore", "version.dvc"], commit="master")
path.scm.checkout("branch", create_new=True)
(path / "version").unlink() # For mac ???
path.dvc_gen("version", "branch")
path.scm_add([".gitignore", "version.dvc"], commit="branch")
path.scm.checkout("master")
path.dvc.close()
return path
+13 -7
View File
@@ -30,17 +30,19 @@ def run_dvc(*argv):
@pytest.mark.parametrize("remote_url", remote_params, indirect=True)
def test_get_url(remote_url, tmp_dir, dvc, repo_template):
def test_get_url(tmp_dir, dvc, remote_url):
run_dvc("remote", "add", "-d", "upstream", remote_url)
dvc.add("foo")
tmp_dir.dvc_gen("foo", "foo")
expected_url = URLInfo(remote_url) / "ac/bd18db4cc2f85cedef654fccc4a4d8"
assert api.get_url("foo") == expected_url
@pytest.mark.parametrize("remote_url", remote_params, indirect=True)
def test_get_url_external(remote_url, erepo_dir):
def test_get_url_external(erepo_dir, remote_url):
_set_remote_url_and_commit(erepo_dir.dvc, 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 = "file://{}".format(erepo_dir)
@@ -63,11 +65,15 @@ def test_open(remote_url, tmp_dir, dvc):
@pytest.mark.parametrize("remote_url", all_remote_params, indirect=True)
def test_open_external(remote_url, erepo_dir):
erepo_dir.scm.checkout("branch")
_set_remote_url_and_commit(erepo_dir.dvc, remote_url)
erepo_dir.scm.checkout("master")
_set_remote_url_and_commit(erepo_dir.dvc, remote_url)
with erepo_dir.chdir():
erepo_dir.dvc_gen("version", "master", commit="add version")
with erepo_dir.branch("branch", new="True"):
# NOTE: need file to be other size for Mac
erepo_dir.dvc_gen("version", "branchver", commit="add version")
erepo_dir.dvc.push(all_branches=True)
# Remove cache to force download
@@ -78,7 +84,7 @@ def test_open_external(remote_url, erepo_dir):
with api.open("version", repo=repo_url) as fd:
assert fd.read() == "master"
assert api.read("version", repo=repo_url, rev="branch") == "branch"
assert api.read("version", repo=repo_url, rev="branch") == "branchver"
@pytest.mark.parametrize("remote_url", all_remote_params, indirect=True)
+5 -6
View File
@@ -33,11 +33,11 @@ from tests.utils import spy
from tests.remotes import (
_should_test_aws,
_should_test_gcp,
_should_test_gdrive,
_should_test_hdfs,
_should_test_oss,
_should_test_ssh,
Azure,
GDrive,
TEST_CONFIG,
TEST_SECTION,
TEST_GCP_CREDS_FILE,
@@ -46,7 +46,6 @@ from tests.remotes import (
TEST_REMOTE,
get_aws_url,
get_gcp_url,
get_gdrive_url,
get_hdfs_url,
get_local_url,
get_oss_url,
@@ -208,7 +207,7 @@ class TestRemoteS3(TestDataCloudBase):
class TestRemoteGDrive(TestDataCloudBase):
def _should_test(self):
return _should_test_gdrive()
return GDrive.should_test()
def _setup_cloud(self):
self._ensure_should_run()
@@ -229,7 +228,7 @@ class TestRemoteGDrive(TestDataCloudBase):
self.assertIsInstance(self.cloud.get_remote(), self._get_cloud_class())
def _get_url(self):
return get_gdrive_url()
return GDrive.get_url()
def _get_cloud_class(self):
return RemoteGDrive
@@ -483,10 +482,10 @@ class TestRemoteS3CLI(TestDataCloudCLIBase):
class TestRemoteGDriveCLI(TestDataCloudCLIBase):
def _should_test(self):
return _should_test_gdrive()
return GDrive.should_test()
def _test(self):
url = get_gdrive_url()
url = GDrive.get_url()
self.main(["remote", "add", TEST_REMOTE, url])
self.main(
+7 -11
View File
@@ -77,13 +77,10 @@ def test_cache_type_is_properly_overridden(tmp_dir, erepo_dir):
def test_get_repo_rev(tmp_dir, erepo_dir):
with erepo_dir.chdir():
erepo_dir.scm.checkout("new_branch", create_new=True)
with erepo_dir.chdir(), erepo_dir.branch("branch", new=True):
erepo_dir.dvc_gen("file", "contents", commit="create file on branch")
erepo_dir.scm.checkout("master")
Repo.get(fspath(erepo_dir), "file", "file_imported", rev="new_branch")
Repo.get(fspath(erepo_dir), "file", "file_imported", rev="branch")
assert (tmp_dir / "file_imported").read_text() == "contents"
@@ -159,11 +156,10 @@ def test_get_to_dir(tmp_dir, erepo_dir, dname):
def test_get_from_non_dvc_master(tmp_dir, erepo_dir, caplog):
with erepo_dir.chdir():
erepo_dir.scm.checkout("new_branch", create_new=True)
erepo_dir.scm_gen(
{"some_file": "some_contents"}, commit="create some file"
)
erepo_dir.scm.checkout("master")
with erepo_dir.branch("branch", new=True):
erepo_dir.scm_gen(
{"some_file": "some_contents"}, commit="create some file"
)
erepo_dir.dvc.scm.repo.index.remove([".dvc"], r=True)
erepo_dir.dvc.scm.commit("remove .dvc")
@@ -175,7 +171,7 @@ def test_get_from_non_dvc_master(tmp_dir, erepo_dir, caplog):
caplog.clear()
dst = "file_imported"
with caplog.at_level(logging.INFO, logger="dvc"):
Repo.get(fspath(erepo_dir), "some_file", out=dst, rev="new_branch")
Repo.get(fspath(erepo_dir), "some_file", out=dst, rev="branch")
assert caplog.text == ""
assert (tmp_dir / dst).read_text() == "some_contents"
+2 -3
View File
@@ -107,10 +107,9 @@ def test_ignore_collecting_dvcignores(tmp_dir, dvc, dname):
def test_ignore_on_branch(tmp_dir, scm, dvc):
tmp_dir.scm_gen({"foo": "foo", "bar": "bar"}, commit="add files")
scm.checkout("branch", create_new=True)
tmp_dir.scm_gen(DvcIgnore.DVCIGNORE_FILE, "foo", commit="add ignore")
with tmp_dir.branch("branch", new=True):
tmp_dir.scm_gen(DvcIgnore.DVCIGNORE_FILE, "foo", commit="add ignore")
scm.checkout("master")
assert _files_set(".", dvc.tree) == {"./foo", "./bar"}
dvc.tree = scm.get_tree("branch")
+7 -8
View File
@@ -90,12 +90,10 @@ def test_import_non_cached(erepo_dir, tmp_dir, dvc, scm):
def test_import_rev(tmp_dir, scm, dvc, erepo_dir):
with erepo_dir.chdir():
erepo_dir.scm.checkout("new_branch", create_new=True)
with erepo_dir.chdir(), erepo_dir.branch("branch", new=True):
erepo_dir.dvc_gen("foo", "foo content", commit="create foo on branch")
erepo_dir.scm.checkout("master")
dvc.imp(fspath(erepo_dir), "foo", "foo_imported", rev="new_branch")
dvc.imp(fspath(erepo_dir), "foo", "foo_imported", rev="branch")
assert (tmp_dir / "foo_imported").read_text() == "foo content"
assert scm.repo.git.check_ignore("foo_imported")
@@ -188,12 +186,13 @@ def test_import_to_dir(dname, tmp_dir, dvc, erepo_dir):
def test_pull_non_workspace(tmp_dir, scm, dvc, erepo_dir):
with erepo_dir.chdir():
erepo_dir.dvc_gen("foo", "master content", commit="create foo")
erepo_dir.scm.checkout("new_branch", create_new=True)
erepo_dir.dvc_gen("foo", "branch content", commit="modify foo")
stage = dvc.imp(fspath(erepo_dir), "foo", "foo_imported", rev="new_branch")
with erepo_dir.branch("branch", new=True):
erepo_dir.dvc_gen("foo", "branch content", commit="modify foo")
stage = dvc.imp(fspath(erepo_dir), "foo", "foo_imported", rev="branch")
tmp_dir.scm_add([stage.relpath], commit="imported branch")
dvc.scm.tag("ref-to-branch")
scm.tag("ref-to-branch")
# Overwrite via import
dvc.imp(fspath(erepo_dir), "foo", "foo_imported", rev="master")
+12 -15
View File
@@ -54,13 +54,6 @@ def _should_test_aws():
return False
def _should_test_gdrive():
if os.getenv(RemoteGDrive.GDRIVE_USER_CREDENTIALS_DATA):
return True
return False
def _should_test_gcp():
do_test = env2bool("DVC_TEST_GCP", undefined=None)
if do_test is not None:
@@ -183,10 +176,6 @@ def get_aws_url():
return "s3://" + get_aws_storagepath()
def get_gdrive_url():
return "gdrive://root/" + str(uuid.uuid4())
def get_gcp_storagepath():
return TEST_GCP_REPO_BUCKET + "/" + str(uuid.uuid4())
@@ -222,8 +211,7 @@ class S3Mocked:
@contextmanager
def remote(cls):
with mock_s3():
remote = RemoteS3(None, {"url": cls.get_url()})
yield remote
yield RemoteS3(None, {"url": cls.get_url()})
@staticmethod
def put_objects(remote, objects):
@@ -243,8 +231,7 @@ class GCP:
@classmethod
@contextmanager
def remote(cls):
remote = RemoteGS(None, {"url": cls.get_url()})
yield remote
yield RemoteGS(None, {"url": cls.get_url()})
@staticmethod
def put_objects(remote, objects):
@@ -254,6 +241,16 @@ class GCP:
bucket.blob((remote.path_info / key).path).upload_from_string(body)
class GDrive:
@staticmethod
def should_test():
return os.getenv(RemoteGDrive.GDRIVE_USER_CREDENTIALS_DATA) is not None
@staticmethod
def get_url():
return "gdrive://root/" + str(uuid.uuid4())
class Azure:
@staticmethod
def should_test():