Skip to content

Commit

Permalink
keep a call to hash_name
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelizimm committed Dec 15, 2023
1 parent 0ea84ad commit 9cb6b34
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pins/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ def __init__(self, *args, hash_prefix=None, mapper=HashMapper, **kwargs):
self.hash_prefix = hash_prefix
self._mapper = mapper(hash_prefix)

def hash_name(self, path, *args, **kwargs):
return self._mapper(path)

def _open(self, path, *args, **kwargs):
# For some reason, the open method of SimpleCacheFileSystem doesn't
# call _make_local_details, so we need to patch in here.
Expand Down Expand Up @@ -179,6 +182,9 @@ def __init__(
self.hash_prefix = hash_prefix
self._mapper = mapper(hash_prefix)

def hash_name(self, path, *args, **kwargs):
return self._mapper(path)

def _open(self, path, mode="rb", **kwargs):
f = super()._open(path, mode=mode, **kwargs)
fn = self._check_file(path)
Expand Down
2 changes: 1 addition & 1 deletion pins/rsconnect/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from pathlib import Path

from fsspec import AbstractFileSystem
from fsspec.utils import isfilelike

from typing import Sequence

Expand All @@ -18,6 +17,7 @@
RsConnectApiRequestError,
RSC_CODE_OBJECT_DOES_NOT_EXIST,
)
from ..utils import isfilelike

# Misc ----

Expand Down
8 changes: 8 additions & 0 deletions pins/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,11 @@ def __call__(self, *args, **kwargs):
# which allows all the inspect machinery to give sphinx the __call__
# attribute we set in __init__.
raise NotImplementedError()


# based off fsspec.isfilelike
def isfilelike(file) -> bool:
for attr in ["read", "close", "tell"]:
if not hasattr(file, attr):
return False
return True

0 comments on commit 9cb6b34

Please sign in to comment.