Skip to content

Commit

Permalink
feat: Add support for python3.13
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkheir committed Oct 30, 2024
1 parent ea880f4 commit 9627e66
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
13 changes: 9 additions & 4 deletions s3path/current_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def register_configuration_parameter(
raise TypeError(f'parameters argument have to be a dict type. got {type(path)}')
if parameters is None and resource is None and glob_new_algorithm is None:
raise ValueError('user have to specify parameters or resource arguments')
if glob_new_algorithm is False and sys.version_info >= (3, 13):
raise ValueError('old glob algorithm can only be used by python versions below 3.13')
accessor.configuration_map.set_configuration(
path,
resource=resource,
Expand All @@ -57,11 +59,10 @@ class PureS3Path(PurePath):
S3 is not a file-system but we can look at it like a POSIX system.
"""
_flavour = flavour
__slots__ = ()

if sys.version_info >= (3, 13):
parser = _S3Flavour()

__slots__ = ()
parser = _flavour

def __init__(self, *args):
super().__init__(*args)
Expand Down Expand Up @@ -488,8 +489,10 @@ def glob(self, pattern: str, *, case_sensitive=None, recurse_symlinks=False): #
self._absolute_path_validation()
general_options = accessor.configuration_map.get_general_options(self)
glob_new_algorithm = general_options['glob_new_algorithm']
if sys.version_info >= (3, 13):
glob_new_algorithm = True
if not glob_new_algorithm:
yield from self._glob_py313(pattern)
yield from super().glob(pattern)
return
yield from self._glob(pattern)

Expand All @@ -500,6 +503,8 @@ def rglob(self, pattern: str, *, case_sensitive=None, recurse_symlinks=False):
self._absolute_path_validation()
general_options = accessor.configuration_map.get_general_options(self)
glob_new_algorithm = general_options['glob_new_algorithm']
if sys.version_info >= (3, 13):
glob_new_algorithm = True
if not glob_new_algorithm:
yield from super().rglob(pattern)
return
Expand Down
11 changes: 9 additions & 2 deletions tests/test_path_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,12 @@ def test_glob_nested_folders_issue_no_120(s3_mock):
assert list(path.glob("further/*")) == [S3Path('/my-bucket/s3path-test/nested/further/test.txt')]


@pytest.mark.skipif(sys.version_info >= (3, 13), reason="requires python3.12 or lower")
def test_glob_old_algo(s3_mock, enable_old_glob):
test_glob(s3_mock)


@pytest.mark.skipif(sys.version_info >= (3, 13), reason="requires python3.12 or lower")
def test_glob_nested_folders_issue_no_115_old_algo(s3_mock, enable_old_glob):
test_glob_nested_folders_issue_no_115(s3_mock)

Expand Down Expand Up @@ -245,14 +247,17 @@ def test_glob_nested_folders_issue_no_179(s3_mock):
S3Path('/my-bucket/s3path/nested/further/andfurther')]


@pytest.mark.skipif(sys.version_info >= (3, 13), reason="requires python3.12 or lower")
def test_glob_issue_160_old_algo(s3_mock, enable_old_glob):
test_glob_issue_160(s3_mock)


@pytest.mark.skipif(sys.version_info >= (3, 13), reason="requires python3.12 or lower")
def test_glob_issue_160_weird_behavior_old_algo(s3_mock, enable_old_glob):
test_glob_issue_160_weird_behavior(s3_mock)


@pytest.mark.skipif(sys.version_info >= (3, 13), reason="requires python3.12 or lower")
def test_glob_nested_folders_issue_no_179_old_algo(s3_mock, enable_old_glob):
test_glob_nested_folders_issue_no_179(s3_mock)

Expand Down Expand Up @@ -285,7 +290,8 @@ def test_rglob(s3_mock):
S3Path('/test-bucket/test_pathlib.py')]


def test_rglob_new_algo(s3_mock, enable_old_glob):
@pytest.mark.skipif(sys.version_info >= (3, 13), reason="requires python3.12 or lower")
def test_rglob_old_algo(s3_mock, enable_old_glob):
test_rglob(s3_mock)


Expand Down Expand Up @@ -313,7 +319,8 @@ def test_accessor_scandir(s3_mock):
S3Path('/test-bucket/test_pathlib.py')]


def test_accessor_scandir_new_algo(s3_mock, enable_old_glob):
@pytest.mark.skipif(sys.version_info >= (3, 13), reason="requires python3.12 or lower")
def test_accessor_scandir_old_algo(s3_mock, enable_old_glob):
test_accessor_scandir(s3_mock)


Expand Down
6 changes: 6 additions & 0 deletions tests/test_s3path_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,9 @@ def test_issue_123():
new_resource, _ = accessor.configuration_map.get_configuration(path)
assert new_resource is s3
assert new_resource is not old_resource


@pytest.mark.skipif(sys.version_info < (3, 13), reason="requires python3.13 or higher")
def test_register_configuration_parameter_old_algo():
with pytest.raises(ValueError):
register_configuration_parameter(PureS3Path('/'), glob_new_algorithm=False)

0 comments on commit 9627e66

Please sign in to comment.