44from abc import ABC
55from collections .abc import MutableMapping , MutableSequence
66from pathlib import Path
7- from typing import Any , Optional , TypeAlias , cast
7+ from typing import Any , TypeAlias , cast
88from urllib .parse import unquote_plus , urlparse
99
1010import schema_salad .metaschema
11+ import schema_salad .runtime
1112from schema_salad .exceptions import ValidationException
1213from schema_salad .utils import yaml_no_ts
1314
@@ -19,11 +20,9 @@ class NoType(ABC):
1920 pass
2021
2122
22- LoadingOptions : TypeAlias = (
23- cwl_v1_0 .LoadingOptions | cwl_v1_1 .LoadingOptions | cwl_v1_2 .LoadingOptions
24- )
23+ LoadingOptions : TypeAlias = schema_salad .runtime .LoadingOptions
2524"""Type union for a CWL v1.x LoadingOptions object."""
26- Saveable : TypeAlias = cwl_v1_0 . Saveable | cwl_v1_1 . Saveable | cwl_v1_2 .Saveable
25+ Saveable : TypeAlias = schema_salad . runtime .Saveable
2726"""Type union for a CWL v1.x Saveable object."""
2827InputParameter : TypeAlias = (
2928 cwl_v1_0 .InputParameter | cwl_v1_1 .InputParameter | cwl_v1_2 .InputParameter
@@ -235,7 +234,7 @@ class NoType(ABC):
235234 | cwl_v1_2 .WorkflowStepInput
236235)
237236"""Type Union for a CWL v1.x LoadContents object."""
238- _Loader : TypeAlias = cwl_v1_0 . _Loader | cwl_v1_1 . _Loader | cwl_v1_2 ._Loader
237+ _Loader : TypeAlias = schema_salad . runtime ._Loader
239238"""Type union for a CWL v1.x _Loader."""
240239
241240
@@ -286,53 +285,16 @@ def load_document_by_uri(
286285 base_uri = path .resolve ().parent .as_uri ()
287286 id_ = path .resolve ().name .split ("#" )[1 ] if "#" in path .resolve ().name else None
288287
289- match loadingOptions :
290- case cwl_v1_0 .LoadingOptions ():
291- loadingOptions = cwl_v1_0 .LoadingOptions (
292- fileuri = real_uri , baseuri = base_uri , copyfrom = loadingOptions
293- )
294- return load_document_by_string (
295- loadingOptions .fetcher .fetch_text (real_uri ),
296- real_uri ,
297- loadingOptions ,
298- id_ ,
299- load_all ,
300- )
301- case cwl_v1_1 .LoadingOptions ():
302- loadingOptions = cwl_v1_1 .LoadingOptions (
303- fileuri = real_uri , baseuri = base_uri , copyfrom = loadingOptions
304- )
305- return load_document_by_string (
306- loadingOptions .fetcher .fetch_text (real_uri ),
307- real_uri ,
308- loadingOptions ,
309- id_ ,
310- load_all ,
311- )
312- case cwl_v1_2 .LoadingOptions ():
313- loadingOptions = cwl_v1_2 .LoadingOptions (
314- fileuri = real_uri , baseuri = base_uri , copyfrom = loadingOptions
315- )
316- return load_document_by_string (
317- loadingOptions .fetcher .fetch_text (real_uri ),
318- real_uri ,
319- loadingOptions ,
320- id_ ,
321- load_all ,
322- )
323- case None :
324- loadingOptions = cwl_v1_2 .LoadingOptions (fileuri = real_uri , baseuri = base_uri )
325- return load_document_by_string (
326- loadingOptions .fetcher .fetch_text (real_uri ),
327- real_uri ,
328- None ,
329- id_ ,
330- load_all ,
331- )
332- case _:
333- raise ValidationException (
334- f"Unsupported loadingOptions type: { type (loadingOptions )} "
335- )
288+ if loadingOptions is None :
289+ loadingOptions = LoadingOptions (fileuri = real_uri , baseuri = base_uri )
290+
291+ return load_document_by_string (
292+ loadingOptions .fetcher .fetch_text (real_uri ),
293+ real_uri ,
294+ loadingOptions ,
295+ id_ ,
296+ load_all ,
297+ )
336298
337299
338300def load_document (
@@ -344,7 +306,7 @@ def load_document(
344306) -> Any :
345307 """Load a CWL object from a serialized YAML string or a YAML object."""
346308 if baseuri is None :
347- baseuri = cwl_v1_0 .file_uri (str (Path .cwd ())) + "/"
309+ baseuri = schema_salad . runtime .file_uri (str (Path .cwd ())) + "/"
348310 if isinstance (doc , str ):
349311 return load_document_by_string (doc , baseuri , loadingOptions , id_ )
350312 return load_document_by_yaml (doc , baseuri , loadingOptions , id_ , load_all )
@@ -376,17 +338,11 @@ def load_document_by_yaml(
376338 yaml ["cwlVersion" ] = version
377339 match version :
378340 case "v1.0" :
379- result = cwl_v1_0 .load_document_by_yaml (
380- yaml , uri , cast (Optional [cwl_v1_0 .LoadingOptions ], loadingOptions )
381- )
341+ result = cwl_v1_0 .load_document_by_yaml (yaml , uri , loadingOptions )
382342 case "v1.1" :
383- result = cwl_v1_1 .load_document_by_yaml (
384- yaml , uri , cast (Optional [cwl_v1_1 .LoadingOptions ], loadingOptions )
385- )
343+ result = cwl_v1_1 .load_document_by_yaml (yaml , uri , loadingOptions )
386344 case "v1.2" :
387- result = cwl_v1_2 .load_document_by_yaml (
388- yaml , uri , cast (Optional [cwl_v1_2 .LoadingOptions ], loadingOptions )
389- )
345+ result = cwl_v1_2 .load_document_by_yaml (yaml , uri , loadingOptions )
390346 case None :
391347 raise ValidationException ("could not get the cwlVersion" )
392348 case _:
@@ -412,7 +368,7 @@ def save(
412368) -> Any :
413369 """Convert a CWL Python object into a JSON/YAML serializable object."""
414370 match val :
415- case cwl_v1_0 . Saveable () | cwl_v1_1 . Saveable () | cwl_v1_2 . Saveable ():
371+ case Saveable ():
416372 return val .save (top = top , base_url = base_url , relative_uris = relative_uris )
417373 case MutableSequence ():
418374 lst = [
0 commit comments