Skip to content

Commit

Permalink
feat: make it possible to normalize e.g. zarr2://./helloworld
Browse files Browse the repository at this point in the history
  • Loading branch information
william-silversmith committed Jun 27, 2024
1 parent dfe053e commit 3ae7c76
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions cloudfiles/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,16 @@ def resolve_alias(cloudpath:str) -> Tuple[Optional[str],str]:
## Other Path Library Functions

def normalize(path):
proto = get_protocol(path)
fmt, proto, endpoint, cloudpath, alias = extract_format_protocol(
path, allow_defaults=False
)

if proto is None:
proto = "file"
path = toabs(path)
return f"file://{path}"
cloudpath = toabs(cloudpath)
fmt = f"{fmt}://" if fmt else ""
path = f"{fmt}{proto}://{cloudpath}"

return path

def dirname(path):
Expand Down Expand Up @@ -269,7 +274,7 @@ def pop_protocol(cloudpath):

return (protocol, cloudpath)

def extract_format_protocol(cloudpath:str) -> tuple:
def extract_format_protocol(cloudpath:str, allow_defaults=True) -> tuple:
error = UnsupportedProtocolError(cloudpath_error(cloudpath))

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

fmt = m.group('fmt') or 'precomputed'
fmt = m.group('fmt')
if not fmt and allow_defaults:
fmt = 'precomputed'
proto = m.group('proto')
endpoint = None

Expand Down

0 comments on commit 3ae7c76

Please sign in to comment.