Skip to content

Commit 60e5121

Browse files
authored
Merge branch 'master' into refactor-remote-azure
2 parents c4783f4 + b6c77f7 commit 60e5121

File tree

11 files changed

+63
-73
lines changed

11 files changed

+63
-73
lines changed

dvc/remote/s3.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,7 @@ def _list_objects(self, path_info, max_items=None):
194194
}
195195
paginator = self.s3.get_paginator(self.list_objects_api)
196196
for page in paginator.paginate(**kwargs):
197-
contents = page.get("Contents", None)
198-
if not contents:
199-
continue
200-
for item in contents:
201-
yield item
197+
yield from page.get("Contents", ())
202198

203199
def _list_paths(self, path_info, max_items=None):
204200
return (

dvc/remote/ssh/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,7 @@ def open(self, path_info, mode="r", encoding=None):
260260
def list_cache_paths(self):
261261
with self.ssh(self.path_info) as ssh:
262262
# If we simply return an iterator then with above closes instantly
263-
for path in ssh.walk_files(self.path_info.path):
264-
yield path
263+
yield from ssh.walk_files(self.path_info.path)
265264

266265
def walk_files(self, path_info):
267266
with self.ssh(path_info) as ssh:

dvc/remote/ssh/connection.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ def walk(self, directory, topdown=True):
139139

140140
for dname in dirs:
141141
newpath = posixpath.join(directory, dname)
142-
for entry in self.walk(newpath, topdown=topdown):
143-
yield entry
142+
yield from self.walk(newpath, topdown=topdown)
144143

145144
if not topdown:
146145
yield directory, dirs, nondirs

dvc/scm/git/tree.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ def _walk(self, tree, topdown=True):
128128
yield os.path.normpath(tree.abspath), dirs, nondirs
129129

130130
for i in dirs:
131-
for x in self._walk(tree[i], topdown=True):
132-
yield x
131+
yield from self._walk(tree[i], topdown=topdown)
133132

134133
if not topdown:
135134
yield os.path.normpath(tree.abspath), dirs, nondirs
@@ -146,5 +145,4 @@ def walk(self, top, topdown=True):
146145
if tree is None:
147146
raise IOError(errno.ENOENT, "No such file")
148147

149-
for x in self._walk(tree, topdown):
150-
yield x
148+
yield from self._walk(tree, topdown=topdown)

tests/dir_helpers.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ def scm_add(self, filenames, commit=None):
139139
if commit:
140140
self.scm.commit(commit)
141141

142+
# contexts
142143
@contextmanager
143144
def chdir(self):
144145
old = os.getcwd()
@@ -148,6 +149,16 @@ def chdir(self):
148149
finally:
149150
os.chdir(old)
150151

152+
@contextmanager
153+
def branch(self, name, new=False):
154+
self._require("scm")
155+
old = self.scm.active_branch()
156+
try:
157+
self.scm.checkout(name, create_new=new)
158+
yield
159+
finally:
160+
self.scm.checkout(old)
161+
151162
# Introspection methods
152163
def list(self):
153164
return [p.name for p in self.iterdir()]
@@ -265,21 +276,12 @@ def erepo_dir(tmp_path_factory, monkeypatch):
265276
_git_init()
266277
path.dvc = Repo.init()
267278
path.scm = path.dvc.scm
268-
path.dvc_gen(REPO_TEMPLATE, commit="init repo")
279+
path.scm.commit("init dvc")
269280

270281
rconfig = RemoteConfig(path.dvc.config)
271282
rconfig.add("upstream", path.dvc.cache.local.cache_dir, default=True)
272283
path.scm_add([path.dvc.config.config_file], commit="add remote")
273284

274-
path.dvc_gen("version", "master")
275-
path.scm_add([".gitignore", "version.dvc"], commit="master")
276-
277-
path.scm.checkout("branch", create_new=True)
278-
(path / "version").unlink() # For mac ???
279-
path.dvc_gen("version", "branch")
280-
path.scm_add([".gitignore", "version.dvc"], commit="branch")
281-
282-
path.scm.checkout("master")
283285
path.dvc.close()
284286

285287
return path

tests/func/test_api.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,19 @@ def run_dvc(*argv):
3030

3131

3232
@pytest.mark.parametrize("remote_url", remote_params, indirect=True)
33-
def test_get_url(remote_url, tmp_dir, dvc, repo_template):
33+
def test_get_url(tmp_dir, dvc, remote_url):
3434
run_dvc("remote", "add", "-d", "upstream", remote_url)
35-
dvc.add("foo")
35+
tmp_dir.dvc_gen("foo", "foo")
3636

3737
expected_url = URLInfo(remote_url) / "ac/bd18db4cc2f85cedef654fccc4a4d8"
3838
assert api.get_url("foo") == expected_url
3939

4040

4141
@pytest.mark.parametrize("remote_url", remote_params, indirect=True)
42-
def test_get_url_external(remote_url, erepo_dir):
42+
def test_get_url_external(erepo_dir, remote_url):
4343
_set_remote_url_and_commit(erepo_dir.dvc, remote_url)
44+
with erepo_dir.chdir():
45+
erepo_dir.dvc_gen("foo", "foo", commit="add foo")
4446

4547
# Using file url to force clone to tmp repo
4648
repo_url = "file://{}".format(erepo_dir)
@@ -63,11 +65,15 @@ def test_open(remote_url, tmp_dir, dvc):
6365

6466
@pytest.mark.parametrize("remote_url", all_remote_params, indirect=True)
6567
def test_open_external(remote_url, erepo_dir):
66-
erepo_dir.scm.checkout("branch")
67-
_set_remote_url_and_commit(erepo_dir.dvc, remote_url)
68-
erepo_dir.scm.checkout("master")
6968
_set_remote_url_and_commit(erepo_dir.dvc, remote_url)
7069

70+
with erepo_dir.chdir():
71+
erepo_dir.dvc_gen("version", "master", commit="add version")
72+
73+
with erepo_dir.branch("branch", new="True"):
74+
# NOTE: need file to be other size for Mac
75+
erepo_dir.dvc_gen("version", "branchver", commit="add version")
76+
7177
erepo_dir.dvc.push(all_branches=True)
7278

7379
# Remove cache to force download
@@ -78,7 +84,7 @@ def test_open_external(remote_url, erepo_dir):
7884
with api.open("version", repo=repo_url) as fd:
7985
assert fd.read() == "master"
8086

81-
assert api.read("version", repo=repo_url, rev="branch") == "branch"
87+
assert api.read("version", repo=repo_url, rev="branch") == "branchver"
8288

8389

8490
@pytest.mark.parametrize("remote_url", all_remote_params, indirect=True)

tests/func/test_data_cloud.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333
from tests.remotes import (
3434
_should_test_aws,
3535
_should_test_gcp,
36-
_should_test_gdrive,
3736
_should_test_hdfs,
3837
_should_test_oss,
3938
_should_test_ssh,
4039
Azure,
40+
GDrive,
4141
TEST_CONFIG,
4242
TEST_SECTION,
4343
TEST_GCP_CREDS_FILE,
@@ -46,7 +46,6 @@
4646
TEST_REMOTE,
4747
get_aws_url,
4848
get_gcp_url,
49-
get_gdrive_url,
5049
get_hdfs_url,
5150
get_local_url,
5251
get_oss_url,
@@ -208,7 +207,7 @@ def _get_cloud_class(self):
208207

209208
class TestRemoteGDrive(TestDataCloudBase):
210209
def _should_test(self):
211-
return _should_test_gdrive()
210+
return GDrive.should_test()
212211

213212
def _setup_cloud(self):
214213
self._ensure_should_run()
@@ -229,7 +228,7 @@ def _setup_cloud(self):
229228
self.assertIsInstance(self.cloud.get_remote(), self._get_cloud_class())
230229

231230
def _get_url(self):
232-
return get_gdrive_url()
231+
return GDrive.get_url()
233232

234233
def _get_cloud_class(self):
235234
return RemoteGDrive
@@ -483,10 +482,10 @@ def _test(self):
483482

484483
class TestRemoteGDriveCLI(TestDataCloudCLIBase):
485484
def _should_test(self):
486-
return _should_test_gdrive()
485+
return GDrive.should_test()
487486

488487
def _test(self):
489-
url = get_gdrive_url()
488+
url = GDrive.get_url()
490489

491490
self.main(["remote", "add", TEST_REMOTE, url])
492491
self.main(

tests/func/test_get.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,10 @@ def test_cache_type_is_properly_overridden(tmp_dir, erepo_dir):
7777

7878

7979
def test_get_repo_rev(tmp_dir, erepo_dir):
80-
with erepo_dir.chdir():
81-
erepo_dir.scm.checkout("new_branch", create_new=True)
80+
with erepo_dir.chdir(), erepo_dir.branch("branch", new=True):
8281
erepo_dir.dvc_gen("file", "contents", commit="create file on branch")
83-
erepo_dir.scm.checkout("master")
84-
85-
Repo.get(fspath(erepo_dir), "file", "file_imported", rev="new_branch")
8682

83+
Repo.get(fspath(erepo_dir), "file", "file_imported", rev="branch")
8784
assert (tmp_dir / "file_imported").read_text() == "contents"
8885

8986

@@ -159,11 +156,10 @@ def test_get_to_dir(tmp_dir, erepo_dir, dname):
159156

160157
def test_get_from_non_dvc_master(tmp_dir, erepo_dir, caplog):
161158
with erepo_dir.chdir():
162-
erepo_dir.scm.checkout("new_branch", create_new=True)
163-
erepo_dir.scm_gen(
164-
{"some_file": "some_contents"}, commit="create some file"
165-
)
166-
erepo_dir.scm.checkout("master")
159+
with erepo_dir.branch("branch", new=True):
160+
erepo_dir.scm_gen(
161+
{"some_file": "some_contents"}, commit="create some file"
162+
)
167163

168164
erepo_dir.dvc.scm.repo.index.remove([".dvc"], r=True)
169165
erepo_dir.dvc.scm.commit("remove .dvc")
@@ -175,7 +171,7 @@ def test_get_from_non_dvc_master(tmp_dir, erepo_dir, caplog):
175171
caplog.clear()
176172
dst = "file_imported"
177173
with caplog.at_level(logging.INFO, logger="dvc"):
178-
Repo.get(fspath(erepo_dir), "some_file", out=dst, rev="new_branch")
174+
Repo.get(fspath(erepo_dir), "some_file", out=dst, rev="branch")
179175

180176
assert caplog.text == ""
181177
assert (tmp_dir / dst).read_text() == "some_contents"

tests/func/test_ignore.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,9 @@ def test_ignore_collecting_dvcignores(tmp_dir, dvc, dname):
107107
def test_ignore_on_branch(tmp_dir, scm, dvc):
108108
tmp_dir.scm_gen({"foo": "foo", "bar": "bar"}, commit="add files")
109109

110-
scm.checkout("branch", create_new=True)
111-
tmp_dir.scm_gen(DvcIgnore.DVCIGNORE_FILE, "foo", commit="add ignore")
110+
with tmp_dir.branch("branch", new=True):
111+
tmp_dir.scm_gen(DvcIgnore.DVCIGNORE_FILE, "foo", commit="add ignore")
112112

113-
scm.checkout("master")
114113
assert _files_set(".", dvc.tree) == {"./foo", "./bar"}
115114

116115
dvc.tree = scm.get_tree("branch")

tests/func/test_import.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,10 @@ def test_import_non_cached(erepo_dir, tmp_dir, dvc, scm):
9090

9191

9292
def test_import_rev(tmp_dir, scm, dvc, erepo_dir):
93-
with erepo_dir.chdir():
94-
erepo_dir.scm.checkout("new_branch", create_new=True)
93+
with erepo_dir.chdir(), erepo_dir.branch("branch", new=True):
9594
erepo_dir.dvc_gen("foo", "foo content", commit="create foo on branch")
96-
erepo_dir.scm.checkout("master")
9795

98-
dvc.imp(fspath(erepo_dir), "foo", "foo_imported", rev="new_branch")
96+
dvc.imp(fspath(erepo_dir), "foo", "foo_imported", rev="branch")
9997

10098
assert (tmp_dir / "foo_imported").read_text() == "foo content"
10199
assert scm.repo.git.check_ignore("foo_imported")
@@ -188,12 +186,13 @@ def test_import_to_dir(dname, tmp_dir, dvc, erepo_dir):
188186
def test_pull_non_workspace(tmp_dir, scm, dvc, erepo_dir):
189187
with erepo_dir.chdir():
190188
erepo_dir.dvc_gen("foo", "master content", commit="create foo")
191-
erepo_dir.scm.checkout("new_branch", create_new=True)
192-
erepo_dir.dvc_gen("foo", "branch content", commit="modify foo")
193189

194-
stage = dvc.imp(fspath(erepo_dir), "foo", "foo_imported", rev="new_branch")
190+
with erepo_dir.branch("branch", new=True):
191+
erepo_dir.dvc_gen("foo", "branch content", commit="modify foo")
192+
193+
stage = dvc.imp(fspath(erepo_dir), "foo", "foo_imported", rev="branch")
195194
tmp_dir.scm_add([stage.relpath], commit="imported branch")
196-
dvc.scm.tag("ref-to-branch")
195+
scm.tag("ref-to-branch")
197196

198197
# Overwrite via import
199198
dvc.imp(fspath(erepo_dir), "foo", "foo_imported", rev="master")

0 commit comments

Comments
 (0)