-
Notifications
You must be signed in to change notification settings - Fork 1.3k
s3: support for directories #2619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e19a1c7
s3: list_objects -> list_objects_api
f7093ed
s3: use path_info for _list_paths
19d3ea2
s3: separate _list_paths from _list_objects
8fa2a06
s3: support max items for listing objects/paths
44b9566
s3: take into account directories on `exists`
2075bc3
s3: overwrite `isdir` method
0f1da32
s3: custom collect directory entry for s3
e46560a
s3: strip checksum when collecting directories
0c11c14
remote: change walk implementation to walk_files
c50cba4
s3: add comment about isdir logic
793de24
s3: use `dir_path` correctly on `isdir`
335ddcb
tests: add a few unit tests for S3
f188a81
s3: use path_info join instead of posixpath
2a1cd31
tests: use parametrize for s3 tests
c31d20c
remote: use posixpath accordingly
9c5484f
tests: remove undeeded AWS variables from S3 test
da28c50
tests: rearrange parametrize values for readability
1483579
tests: add encoding, use a single s3 instance, for loop instead of pa…
d4cd493
py2: fix encoding
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,85 @@ | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| import pytest | ||
| from moto import mock_s3 | ||
|
|
||
| from dvc.remote.s3 import RemoteS3 | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def remote(): | ||
| """Returns a RemoteS3 connected to a bucket with the following structure: | ||
|
|
||
| bucket | ||
| ├── data | ||
| │ ├── alice | ||
| │ ├── alpha | ||
| │ └── subdir | ||
| │ ├── 1 | ||
| │ ├── 2 | ||
| │ └── 3 | ||
| ├── empty_dir | ||
| ├── empty_file | ||
| └── foo | ||
| """ | ||
| with mock_s3(): | ||
| remote = RemoteS3(None, {"url": "s3://bucket", "region": "us-east-1"}) | ||
| s3 = remote.s3 | ||
|
|
||
| s3.create_bucket(Bucket="bucket") | ||
| s3.put_object(Bucket="bucket", Key="empty_dir/") | ||
| s3.put_object(Bucket="bucket", Key="empty_file", Body=b"") | ||
| s3.put_object(Bucket="bucket", Key="foo", Body=b"foo") | ||
| s3.put_object(Bucket="bucket", Key="data/alice", Body=b"alice") | ||
| s3.put_object(Bucket="bucket", Key="data/alpha", Body=b"alpha") | ||
| s3.put_object(Bucket="bucket", Key="data/subdir/1", Body=b"1") | ||
| s3.put_object(Bucket="bucket", Key="data/subdir/2", Body=b"2") | ||
| s3.put_object(Bucket="bucket", Key="data/subdir/3", Body=b"3") | ||
|
|
||
| yield remote | ||
|
|
||
|
|
||
| def test_isdir(remote): | ||
| test_cases = [ | ||
| (True, "data"), | ||
| (True, "data/"), | ||
| (True, "data/subdir"), | ||
| (True, "empty_dir"), | ||
| (False, "foo"), | ||
| (False, "data/alice"), | ||
| (False, "data/al"), | ||
| (False, "data/subdir/1"), | ||
| ] | ||
|
|
||
| for expected, path in test_cases: | ||
| assert remote.isdir(remote.path_info / path) == expected | ||
|
|
||
|
|
||
| def test_exists(remote): | ||
| test_cases = [ | ||
| (True, "data"), | ||
| (True, "data/"), | ||
| (True, "data/subdir"), | ||
| (True, "empty_dir"), | ||
| (True, "empty_file"), | ||
| (True, "foo"), | ||
| (True, "data/alice"), | ||
| (True, "data/subdir/1"), | ||
| (False, "data/al"), | ||
| (False, "foo/"), | ||
| ] | ||
|
|
||
| for expected, path in test_cases: | ||
| assert remote.exists(remote.path_info / path) == expected | ||
|
|
||
|
|
||
| def test_walk_files(remote): | ||
| files = [ | ||
| remote.path_info / "data/alice", | ||
| remote.path_info / "data/alpha", | ||
| remote.path_info / "data/subdir/1", | ||
| remote.path_info / "data/subdir/2", | ||
| remote.path_info / "data/subdir/3", | ||
| ] | ||
|
|
||
| assert list(remote.walk_files(remote.path_info / "data")) == files |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.