MCPcopy
hub / github.com/huggingface/datasets / xjoin

Function xjoin

src/datasets/utils/file_utils.py:570–594  ·  view source on GitHub ↗

This function extends os.path.join to support the "::" hop separator. It supports both paths and urls. A shorthand, particularly useful where you have multiple hops, is to “chain” the URLs with the special separator "::". This is used to access files inside a zip file over http for exa

(a, *p)

Source from the content-addressed store, hash-verified

568
569
570def xjoin(a, *p):
571 """
572 This function extends os.path.join to support the "::" hop separator. It supports both paths and urls.
573
574 A shorthand, particularly useful where you have multiple hops, is to “chain” the URLs with the special separator "::".
575 This is used to access files inside a zip file over http for example.
576
577 Let's say you have a zip file at https://host.com/archive.zip, and you want to access the file inside the zip file at /folder1/file.txt.
578 Then you can just chain the url this way:
579
580 zip://folder1/file.txt::https://host.com/archive.zip
581
582 The xjoin function allows you to apply the join on the first path of the chain.
583
584 Example::
585
586 >>> xjoin("zip://folder1::https://host.com/archive.zip", "file.txt")
587 zip://folder1/file.txt::https://host.com/archive.zip
588 """
589 a, *b = str(a).split("::")
590 if is_local_path(a):
591 return os.path.join(a, *p)
592 else:
593 a = posixpath.join(a, *p)
594 return "::".join([a] + b)
595
596
597def xdirname(a):

Callers 11

test_xjoinFunction · 0.90
resolve_patternFunction · 0.85
_resolve_data_filesMethod · 0.85
get_moduleMethod · 0.85
globMethod · 0.85
joinpathMethod · 0.85
_iter_from_urlpathsMethod · 0.85

Calls 2

is_local_pathFunction · 0.85
splitMethod · 0.80