Skip to content

Commit

Permalink
Merge pull request #171 from liormizr/fix_glob_duble_path_issue
Browse files Browse the repository at this point in the history
fix_glob_duble_path_issue
  • Loading branch information
liormizr authored Apr 17, 2024
2 parents c0d77d2 + 542babb commit 928b5ce
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion s3path/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from . import accessor

__version__ = '0.5.5'
__version__ = '0.5.6'
__all__ = (
'register_configuration_parameter',
'StatResult',
Expand Down
2 changes: 2 additions & 0 deletions s3path/current_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,8 @@ def _deep_cached_dir_scan(self):
target_path_parts = key_parts[:self._target_level]
target_path = ''
for part in target_path_parts:
if not part:
continue
target_path += f'{self._path._flavour.sep}{part}'
if target_path in cache:
continue
Expand Down
2 changes: 2 additions & 0 deletions s3path/old_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,8 @@ def _deep_cached_dir_scan(self):
target_path_parts = key_parts[:self._target_level]
target_path = ''
for part in target_path_parts:
if not part:
continue
target_path += f'{self._path._flavour.sep}{part}'
if target_path in cache:
continue
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
long_description = fh.read()
setup(
name='s3path',
version='0.5.5',
version='0.5.6',
url='https://github.com/liormizr/s3path',
author='Lior Mizrahi',
author_email='[email protected]',
Expand Down
30 changes: 30 additions & 0 deletions tests/test_path_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,40 @@ def test_glob_issue_160(s3_mock):
assert sum(1 for _ in path.rglob('output/')) == 4


def test_glob_issue_160_weird_behavior(s3_mock):
s3 = boto3.resource('s3')
s3.create_bucket(Bucket='my-bucket')

first_dir = S3Path.from_uri(f"s3://my-bucket/first_dir/")
new_file = first_dir / "some_dir" / "empty.txt"
new_file.touch()
print()
print(f'Globing: {first_dir=}, pattern: "*"')
assert list(first_dir.glob("*")) == [S3Path('/my-bucket/first_dir/some_dir/')]

second_dir = S3Path.from_uri(f"s3://my-bucket/first_dir/second_dir/")
new_file = second_dir / "some_dir" / "empty.txt"
new_file.touch()
print()
print(f'Globing: {second_dir=}, pattern: "*"')
assert list(second_dir.glob("*")) == [S3Path('/my-bucket/first_dir/second_dir/some_dir/')]

third_dir = S3Path.from_uri(f"s3://my-bucket/first_dir/second_dir/third_dir/")
new_file = third_dir / "some_dir" / "empty.txt"
new_file.touch()
print()
print(f'Globing: {third_dir=}, pattern: "*"')
assert list(third_dir.glob("*")) == [S3Path('/my-bucket/first_dir/second_dir/third_dir/some_dir/')]


def test_glob_issue_160_old_algo(s3_mock, enable_old_glob):
test_glob_issue_160(s3_mock)


def test_glob_issue_160_weird_behavior_old_algo(s3_mock, enable_old_glob):
test_glob_issue_160_weird_behavior(s3_mock)


def test_rglob(s3_mock):
s3 = boto3.resource('s3')
s3.create_bucket(Bucket='test-bucket')
Expand Down

0 comments on commit 928b5ce

Please sign in to comment.