1616from .errors import PinsError
1717from .drivers import load_data , save_data , default_title
1818from .utils import inform
19- from .config import get_allow_rsc_short_name , get_feature_preview
19+ from .config import get_allow_rsc_short_name
2020
2121
2222_log = logging .getLogger (__name__ )
@@ -155,12 +155,10 @@ def pin_meta(self, name, version: str = None) -> Meta:
155155 meta_name = self .meta_factory .get_meta_name (* components )
156156
157157 path_meta = self .construct_path ([* components , meta_name ])
158- f = self .fs . open (path_meta )
158+ f = self ._open_pin_meta (path_meta )
159159
160160 meta = self .meta_factory .read_pin_yaml (f , pin_name , selected_version )
161161
162- self ._touch_cache (path_meta )
163-
164162 return meta
165163
166164 def pin_list (self ):
@@ -213,11 +211,8 @@ def pin_read(self, name, version: Optional[str] = None, hash: Optional[str] = No
213211
214212 pin_name = self .path_to_pin (name )
215213
216- return load_data (
217- meta ,
218- self .fs ,
219- self .construct_path ([pin_name , meta .version .version ]),
220- allow_pickle_read = self .allow_pickle_read ,
214+ return self ._load_data (
215+ meta , self .construct_path ([pin_name , meta .version .version ])
221216 )
222217
223218 def pin_write (
@@ -493,7 +488,13 @@ def pin_browse(self, name, version=None, local=False):
493488
494489 raise NotImplementedError ()
495490
491+ # pin name internal methods -----------------------------------------------
492+ # these methods are responsible for validating pin names, and converting
493+ # names to their ultimate path on the file system.
494+
496495 def validate_pin_name (self , name : str ) -> None :
496+ """Raise an error if a pin name is not valid."""
497+
497498 if "/" in name :
498499 raise ValueError (f"Invalid pin name: { name } " )
499500
@@ -512,6 +513,8 @@ def construct_path(self, elements) -> str:
512513 def keep_final_path_component (self , path ):
513514 return path .split ("/" )[- 1 ]
514515
516+ # version ordering, creation ----------------------------------------------
517+
515518 def sort_pin_versions (self , versions ):
516519 # assume filesystem returned them with most recent last
517520 return sorted (versions , key = lambda v : v .version )
@@ -574,10 +577,29 @@ def _extract_search_meta(self, meta):
574577 d ["meta" ] = meta
575578 return d
576579
577- def _get_cache_path (self , pin_name , version ):
578- p_version = self .construct_path ([self .path_to_pin (pin_name ), version ])
579- hash = self .fs .hash_name (p_version , True )
580- return str (Path (self .fs .storage [- 1 ]) / hash )
580+ # data loading ------------------------------------------------------------
581+
582+ def _load_data (self , meta , pin_version_path ):
583+ """Return the data object stored by a pin (e.g. a DataFrame)."""
584+ return load_data (
585+ meta , self .fs , pin_version_path , allow_pickle_read = self .allow_pickle_read
586+ )
587+
588+ # filesystem and cache methods --------------------------------------------
589+
590+ def _open_pin_meta (self , path ):
591+ f = self .fs .open (path )
592+ self ._touch_cache (path )
593+
594+ return f
595+
596+ def _get_cache_path (self , pin_name , version = None , fname = None ):
597+ version_part = [version ] if version is not None else []
598+ fname_part = [fname ] if fname is not None else []
599+ p_version = self .construct_path (
600+ [self .path_to_pin (pin_name ), * version_part , * fname_part ]
601+ )
602+ return self .fs ._check_file (p_version )
581603
582604 def _touch_cache (self , path ):
583605 from pins .cache import touch_access_time
@@ -587,8 +609,7 @@ def _touch_cache(self, path):
587609 if not hasattr (self .fs , "cached_files" ):
588610 return
589611
590- hash = self .fs .hash_name (path , True )
591- path_to_hashed = Path (self .fs .storage [- 1 ]) / hash
612+ path_to_hashed = self .fs ._check_file (path )
592613 return touch_access_time (path_to_hashed )
593614
594615
@@ -611,9 +632,6 @@ class BoardManual(BaseBoard):
611632 0 1 a 3
612633 1 2 b 4
613634
614-
615-
616-
617635 """
618636
619637 # TODO(question): is this class worth it? Or should the user just use fsspec?
@@ -623,14 +641,14 @@ def __init__(self, *args, pin_paths: dict, **kwargs):
623641
624642 self .pin_paths = pin_paths
625643
626- def pin_read (self , * args , ** kwargs ):
627- if not get_feature_preview ():
628- raise NotImplementedError (
629- "pin_read with BoardManual is currently unimplemented. "
630- "See https://github.com/machow/pins-python/issues/59."
631- )
644+ # def pin_read(self, *args, **kwargs):
645+ # if not get_feature_preview():
646+ # raise NotImplementedError(
647+ # "pin_read with BoardManual is currently unimplemented. "
648+ # "See https://github.com/machow/pins-python/issues/59."
649+ # )
632650
633- return super ().pin_read (* args , ** kwargs )
651+ # return super().pin_read(*args, **kwargs)
634652
635653 def pin_list (self ):
636654 return list (self .pin_paths )
@@ -654,18 +672,20 @@ def pin_meta(self, name, version=None):
654672 return self .meta_factory .create_raw (path_to_pin , type = "file" , name = pin_name )
655673
656674 path_meta = self .construct_path ([pin_name , meta_name ])
657- f = self .fs . open (path_meta )
675+ f = self ._open_pin_meta (path_meta )
658676 meta = self .meta_factory .read_pin_yaml (f , pin_name , VersionRaw ("" ))
659677
678+ # TODO(#59,#83): handle caching, and then re-enable pin_read.
679+ # self._touch_cache(path_meta)
680+
660681 return meta
661682
662683 def pin_download (self , name , version = None , hash = None ) -> Sequence [str ]:
663684 meta = self .pin_meta (name , version )
664685
665686 if isinstance (meta , MetaRaw ):
666- return load_data (
667- meta , self .fs , None , allow_pickle_read = self .allow_pickle_read
668- )
687+
688+ return self ._load_data (meta , None )
669689
670690 raise NotImplementedError (
671691 "TODO: pin_download currently can only read a url to a single file."
@@ -686,6 +706,11 @@ def construct_path(self, elements):
686706 # boards forbid a final /, we need to strip it off to join elements
687707 pin_path = pin_path .rstrip ().rstrip ("/" )
688708
709+ # this is a bit hacky, but this board only aims at specific pins versions,
710+ # so the metadata has the version as "", so we need to remove it.
711+ if others [0 ] == "" :
712+ return super ().construct_path ([pin_path , * others [1 :]])
713+
689714 return super ().construct_path ([pin_path , * others ])
690715
691716
0 commit comments