Skip to content

Commit

Permalink
add python 3.11 for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
liormizr committed Dec 7, 2023
1 parent 36fec3e commit 7881864
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
# python-version: [3.8, 3.9, "3.10", 3.11, 3.12]
python-version: [3.12]
python-version: [3.11, 3.12]
steps:
- uses: actions/checkout@v2

Expand Down
68 changes: 63 additions & 5 deletions s3path/accessor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from os import stat_result
from threading import Lock
from itertools import chain
from functools import lru_cache
from collections import namedtuple
from io import UnsupportedOperation
Expand All @@ -9,8 +11,6 @@
from botocore.docs.docstring import LazyLoadedDocstring
import smart_open

from .config import S3ConfigurationMap


class StatResult(namedtuple('BaseStatResult', 'size, last_modified, version_id', defaults=(None,))):
"""
Expand All @@ -35,9 +35,6 @@ def st_version_id(self) -> str:
return self.version_id


configuration_map = S3ConfigurationMap()


def stat(path, *, follow_symlinks=True):
if not follow_symlinks:
raise NotImplementedError(
Expand Down Expand Up @@ -492,3 +489,64 @@ def is_symlink(self, *args, **kwargs):

def stat(self):
return self._stat


class _S3ConfigurationMap:
def __init__(self):
self.arguments = None
self.resources = None
self.general_options = None
self.setup_lock = Lock()
self.is_setup = False

def __repr__(self):
return f'{type(self).__name__}' \
f'(arguments={self.arguments}, resources={self.resources}, is_setup={self.is_setup})'

@property
def default_resource(self):
return boto3.resource('s3')

def set_configuration(self, path, *, resource=None, arguments=None, glob_new_algorithm=None):
self._delayed_setup()
path_name = str(path)
if arguments is not None:
self.arguments[path_name] = arguments
if resource is not None:
self.resources[path_name] = resource
if glob_new_algorithm is not None:
self.general_options[path_name] = {'glob_new_algorithm': glob_new_algorithm}
self.get_configuration.cache_clear()

@lru_cache()
def get_configuration(self, path):
self._delayed_setup()
resources = arguments = None
for path in chain([path], path.parents):
path_name = str(path)
if resources is None and path_name in self.resources:
resources = self.resources[path_name]
if arguments is None and path_name in self.arguments:
arguments = self.arguments[path_name]
return resources, arguments

@lru_cache()
def get_general_options(self, path):
self._delayed_setup()
for path in chain([path], path.parents):
path_name = str(path)
if path_name in self.general_options:
return self.general_options[path_name]
return

def _delayed_setup(self):
""" Resolves a circular dependency between us and PureS3Path """
with self.setup_lock:
if not self.is_setup:
self.arguments = {'/': {}}
self.resources = {'/': self.default_resource}
self.general_options = {'/': {'glob_new_algorithm': True}}
self.is_setup = True


configuration_map = _S3ConfigurationMap()
63 changes: 0 additions & 63 deletions s3path/config.py

This file was deleted.

1 change: 0 additions & 1 deletion s3path/flavour.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def __getattr__(name):
def __getattr__(name):
return getattr(_posix_flavour, name)


def parse_parts(parts):
drv, root, parsed = _posix_flavour.parse_parts(parts)
for part in parsed[1:]:
Expand Down

0 comments on commit 7881864

Please sign in to comment.