From 9cb6b3444310239882cdb887e3f9e8247c7ead4a Mon Sep 17 00:00:00 2001 From: isabelizimm Date: Fri, 15 Dec 2023 14:15:32 -0500 Subject: [PATCH] keep a call to hash_name --- pins/cache.py | 6 ++++++ pins/rsconnect/fs.py | 2 +- pins/utils.py | 8 ++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pins/cache.py b/pins/cache.py index b22c684..0f53af4 100644 --- a/pins/cache.py +++ b/pins/cache.py @@ -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. @@ -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) diff --git a/pins/rsconnect/fs.py b/pins/rsconnect/fs.py index 0dcf78d..d13fc1c 100644 --- a/pins/rsconnect/fs.py +++ b/pins/rsconnect/fs.py @@ -2,7 +2,6 @@ from pathlib import Path from fsspec import AbstractFileSystem -from fsspec.utils import isfilelike from typing import Sequence @@ -18,6 +17,7 @@ RsConnectApiRequestError, RSC_CODE_OBJECT_DOES_NOT_EXIST, ) +from ..utils import isfilelike # Misc ---- diff --git a/pins/utils.py b/pins/utils.py index b220411..b708a22 100644 --- a/pins/utils.py +++ b/pins/utils.py @@ -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