Skip to content

Commit 3ae7c76

Browse files
feat: make it possible to normalize e.g. zarr2://./helloworld
1 parent dfe053e commit 3ae7c76

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

cloudfiles/paths.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,16 @@ def resolve_alias(cloudpath:str) -> Tuple[Optional[str],str]:
152152
## Other Path Library Functions
153153

154154
def normalize(path):
155-
proto = get_protocol(path)
155+
fmt, proto, endpoint, cloudpath, alias = extract_format_protocol(
156+
path, allow_defaults=False
157+
)
158+
156159
if proto is None:
157160
proto = "file"
158-
path = toabs(path)
159-
return f"file://{path}"
161+
cloudpath = toabs(cloudpath)
162+
fmt = f"{fmt}://" if fmt else ""
163+
path = f"{fmt}{proto}://{cloudpath}"
164+
160165
return path
161166

162167
def dirname(path):
@@ -269,7 +274,7 @@ def pop_protocol(cloudpath):
269274

270275
return (protocol, cloudpath)
271276

272-
def extract_format_protocol(cloudpath:str) -> tuple:
277+
def extract_format_protocol(cloudpath:str, allow_defaults=True) -> tuple:
273278
error = UnsupportedProtocolError(cloudpath_error(cloudpath))
274279

275280
alias, cloudpath = resolve_alias(cloudpath)
@@ -281,7 +286,9 @@ def extract_format_protocol(cloudpath:str) -> tuple:
281286
groups = m.groups()
282287
cloudpath = re.sub(CLOUDPATH_REGEXP, '', cloudpath, count=1)
283288

284-
fmt = m.group('fmt') or 'precomputed'
289+
fmt = m.group('fmt')
290+
if not fmt and allow_defaults:
291+
fmt = 'precomputed'
285292
proto = m.group('proto')
286293
endpoint = None
287294

0 commit comments

Comments
 (0)