Skip to content

Commit 7a3d6c4

Browse files
committed
refactor: constructor, not cache, now sets board's cache dir
1 parent 97a8fa0 commit 7a3d6c4

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

pins/cache.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,8 @@ def hash_name(self, path, same_name):
9090
if self.hash_prefix is not None:
9191
# optionally make the name relative to a parent path
9292
# using the hash of parent path as a prefix, to flatten a bit
93-
suffix = Path(path).relative_to(Path(self.hash_prefix))
94-
# TODO(compat): R pins uses xxh128 hash here, but fsspec uses sha256
95-
prefix = hash_name(self.hash_prefix, False)
96-
97-
# TODO: hacky to automatically tack on protocol here
98-
# but this is what R pins boards do. Could make a bool arg?
99-
proto_name = protocol_to_string(self.fs.protocol)
100-
full_prefix = "_".join([proto_name, prefix])
101-
return str(full_prefix / suffix)
93+
hash = Path(path).relative_to(Path(self.hash_prefix))
94+
return hash
10295

10396
return path
10497
else:
@@ -122,14 +115,8 @@ def hash_name(self, path, same_name):
122115
raise NotImplementedError()
123116

124117
# change pin path of form <user>/<content> to <user>+<content>
125-
suffix = path.replace("/", "+", 1)
126-
prefix = hash_name(self.hash_prefix, False)
127-
128-
# TODO: hacky to automatically tack on protocol here
129-
# but this is what R pins boards do. Could make a bool arg?
130-
proto_name = protocol_to_string(self.fs.protocol)
131-
full_prefix = "_".join([proto_name, prefix])
132-
return str(full_prefix / Path(suffix))
118+
hash = path.replace("/", "+", 1)
119+
return hash
133120

134121
else:
135122
raise NotImplementedError()

pins/constructors.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,23 @@ def board(
117117
# wrap fs in cache ----
118118

119119
if cache is DEFAULT:
120-
cache_dir = get_cache_dir()
120+
base_cache_dir = get_cache_dir()
121121

122122
# manually create a subdirectory for rsc server
123123
if protocol == "rsc":
124+
# ensures each server_url is its own cache directory
124125
hash_prefix = storage_options["server_url"]
126+
board_cache = prefix_cache(fs, hash_prefix)
127+
cache_dir = os.path.join(base_cache_dir, board_cache)
128+
125129
fs = PinsRscCache(
126130
cache_storage=cache_dir, fs=fs, hash_prefix=hash_prefix, same_names=True
127131
)
128132
else:
133+
# ensures each subdir path is its own cache directory
134+
board_cache = prefix_cache(fs, path)
135+
cache_dir = os.path.join(base_cache_dir, board_cache)
136+
129137
fs = PinsCache(
130138
cache_storage=cache_dir, fs=fs, hash_prefix=path, same_names=True
131139
)
@@ -138,10 +146,10 @@ def board(
138146

139147
pickle_kwargs = {"allow_pickle_read": allow_pickle_read}
140148
# TODO: should use a registry or something
141-
if protocol == "rsc" and board_factory is None:
142-
board = BoardRsConnect(path, fs, versioned, **pickle_kwargs)
143-
elif board_factory is not None:
149+
if board_factory is not None:
144150
board = board_factory(path, fs, versioned, **pickle_kwargs)
151+
elif protocol == "rsc":
152+
board = BoardRsConnect(path, fs, versioned, **pickle_kwargs)
145153
else:
146154
board = BaseBoard(path, fs, versioned, **pickle_kwargs)
147155
return board

0 commit comments

Comments
 (0)