Load a CWL document from an HTTP(S) URL, local path, or local file URI.
Local file URIs may use an empty authority or localhost. Percent-encoded
paths are decoded before opening; relative references use the file URI.
As for other sources, URI fragments do not select a process: the complete
document is loaded.
| Parameters: |
-
path
(str)
–
HTTP(S) URL, local file path, or local file URI.
-
cwl_version
(str, default:
__TARGET_CWL_VERSION__
)
–
Target CWL version. Defaults to v1.2.
-
sort
(bool, default:
True
)
–
Whether to order processes by their dependencies.
-
session
(Session, default:
_global_session
)
–
HTTP session used to retrieve remote documents.
|
| Returns: |
-
Process | list[Process]
–
The parsed process, or a list of processes for a multi-process document.
|
Source code in src/cwl_loader/__init__.py
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438 | def load_cwl_from_location(
path: str,
cwl_version: str = __TARGET_CWL_VERSION__,
sort: bool = True,
session: requests.Session = _global_session,
) -> Process | list[Process]:
"""Load a CWL document from an HTTP(S) URL, local path, or local file URI.
Local file URIs may use an empty authority or localhost. Percent-encoded
paths are decoded before opening; relative references use the file URI.
As for other sources, URI fragments do not select a process: the complete
document is loaded.
Args:
path: HTTP(S) URL, local file path, or local file URI.
cwl_version: Target CWL version. Defaults to ``v1.2``.
sort: Whether to order processes by their dependencies.
session: HTTP session used to retrieve remote documents.
Returns:
The parsed process, or a list of processes for a multi-process document.
"""
logger.debug(f"Loading CWL document from {path}...")
document_uri = path
source_path = _local_source_path(path, session)
if source_path is not None:
document_uri = source_path.resolve().as_uri()
def _load_cwl_from_stream(stream: TextIO) -> Process | list[Process]:
"""Load a stream using the resolved source URI and requested options."""
logger.debug(f"Reading stream from {path}...")
loaded = load_cwl_from_stream(
content=stream,
uri=document_uri,
cwl_version=cwl_version,
sort=sort,
session=session,
)
logger.debug(f"Stream from {path} successfully load!")
return loaded
if source_path is None:
response = session.get(path, stream=True)
response.raise_for_status()
# Read first 2 bytes to check for gzip
magic = response.raw.read(2)
remaining = response.raw.read() # Read rest of the stream
combined = BytesIO(magic + remaining)
buffer = GzipFile(fileobj=combined) if magic == b"\x1f\x8b" else combined
return _load_cwl_from_stream(TextIOWrapper(buffer, encoding=__DEFAULT_ENCODING__))
if source_path.is_file():
with source_path.open(encoding=__DEFAULT_ENCODING__) as f:
return _load_cwl_from_stream(f)
else:
raise ValueError(f"Invalid source {path}: not a URL or existing file path")
|