@@ -74,11 +74,60 @@ def _join_paths(paths: Iterable[str]) -> str:
7474 """
7575 Filter out instances of '' and join the remaining strings with '/'.
7676
77- Because the root node of a zarr hierarchy is represented by an empty string,
77+ Parameters
78+ ----------
79+ paths : Iterable[str]
80+
81+ Returns
82+ -------
83+ str
84+
85+ Examples
86+ --------
87+ >>> _join_paths(["", "a", "b"])
88+ 'a/b'
89+ >>> _join_paths(["a", "b", "c"])
90+ 'a/b/c'
7891 """
7992 return "/" .join (filter (lambda v : v != "" , paths ))
8093
8194
95+ def _relativize_path (path : str , prefix : str ) -> str :
96+ """
97+ Make a "\" -delimited path relative to some prefix. If the prefix is '', then the path is
98+ returned as-is. Otherwise, the prefix is removed from the path as well as the separator
99+ string "\" .
100+
101+ If ``prefix`` is not the empty string and``path`` does not start with ``prefix``
102+ followed by a "/" character, then an error is raised.
103+
104+ Parameters
105+ ----------
106+ path : str
107+ The path to make relative to the prefix.
108+ prefix : str
109+ The prefix to make relative to.
110+
111+ Returns
112+ -------
113+ str
114+
115+ Examples
116+ --------
117+ >>> _relativize_paths("", "a/b")
118+ 'a/b'
119+ >>> _relativize_paths("a/b", "a/b/c")
120+ 'c'
121+ """
122+ if prefix == "" :
123+ return path
124+ else :
125+ _prefix = prefix + "/"
126+ if not path .startswith (_prefix ):
127+ raise ValueError (f"The first component of { path } does not start with { prefix } ." )
128+ return path .removeprefix (f"{ prefix } /" )
129+
130+
82131def _normalize_paths (paths : Iterable [str ]) -> tuple [str , ...]:
83132 """
84133 Normalize the input paths according to the normalization scheme used for zarr node paths.
0 commit comments