Skip to content

Commit e85dce3

Browse files
author
Vasu Jaganath
committed
port some functions from isinstance to match 1/n
1 parent 884885e commit e85dce3

File tree

2 files changed

+31
-24
lines changed

2 files changed

+31
-24
lines changed

src/sophios/run_local.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import shutil
1010
import platform
1111
import traceback
12-
from typing import Dict, List, Optional
12+
from typing import List, Optional
1313
from datetime import datetime
1414

1515
try:
@@ -413,20 +413,23 @@ def stage_input_files(yml_inputs: Yaml, root_yml_dir_abs: Path,
413413
FileNotFoundError: If throw and it any of the input files do not exist.
414414
"""
415415
for key, val in yml_inputs.items():
416-
if isinstance(val, Dict) and val.get('class', '') == 'File':
417-
path = root_yml_dir_abs / Path(val['path'])
418-
if not path.exists() and throw:
419-
# raise FileNotFoundError(f'Error! {path} does not exist!')
420-
print(f'Error! {path} does not exist!')
421-
sys.exit(1)
422-
423-
relpath = Path('autogenerated/') if relative_run_path else Path('.')
424-
pathauto = relpath / Path(val['path']) # .name # NOTE: Use .name ?
425-
pathauto.parent.mkdir(parents=True, exist_ok=True)
426-
427-
if path != pathauto:
428-
cmd = ['cp', str(path), str(pathauto)]
429-
proc = sub.run(cmd, check=False)
416+
match val:
417+
case {'class': 'File', **rest_of_val}:
418+
path = root_yml_dir_abs / Path(val['path'])
419+
if not path.exists() and throw:
420+
# raise FileNotFoundError(f'Error! {path} does not exist!')
421+
print(f'Error! {path} does not exist!')
422+
sys.exit(1)
423+
424+
relpath = Path('autogenerated/') if relative_run_path else Path('.')
425+
pathauto = relpath / Path(val['path']) # .name # NOTE: Use .name ?
426+
pathauto.parent.mkdir(parents=True, exist_ok=True)
427+
428+
if path != pathauto:
429+
cmd = ['cp', str(path), str(pathauto)]
430+
_ = sub.run(cmd, check=False)
431+
case _:
432+
pass
430433

431434

432435
def cwltool_main() -> int:

src/sophios/utils_cwl.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,19 @@ def canonicalize_type(type_obj: Any) -> Any:
229229
Returns:
230230
Any: The JSON canonical normal form associated with type_obj
231231
"""
232-
if isinstance(type_obj, str):
233-
if len(type_obj) >= 1 and type_obj[-1:] == '?':
234-
return ['null', canonicalize_type(type_obj[:-1])]
235-
if len(type_obj) >= 2 and type_obj[-2:] == '[]':
236-
return {'type': 'array', 'items': canonicalize_type(type_obj[:-2])}
237-
if isinstance(type_obj, Dict):
238-
if type_obj.get('type') == 'array':
239-
return {**type_obj, 'items': canonicalize_type(type_obj['items'])}
240-
return type_obj
232+
match type_obj:
233+
case str() as str_obj:
234+
if len(str_obj) >= 1 and str_obj[-1:] == '?':
235+
return ['null', canonicalize_type(str_obj[:-1])]
236+
if len(str_obj) >= 2 and str_obj[-2:] == '[]':
237+
return {'type': 'array', 'items': canonicalize_type(str_obj[:-2])}
238+
return str_obj
239+
case dict() as dict_obj:
240+
if dict_obj.get('type') == 'array':
241+
return {**dict_obj, 'items': canonicalize_type(dict_obj['items'])}
242+
return dict_obj
243+
case _:
244+
return type_obj
241245

242246

243247
def canonicalize_steps_list(steps: Yaml) -> List[Yaml]:

0 commit comments

Comments
 (0)