Skip to content

Commit

Permalink
Added stdstreams to file conversion utils (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
GlassOfWhiskey authored Aug 24, 2022
1 parent 9a4f9d1 commit 9fee238
Show file tree
Hide file tree
Showing 5 changed files with 479 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,7 @@ venv.bak/

testenv*/
pydocstyle_report.txt

# PyCharm
.idea/

28 changes: 28 additions & 0 deletions cwl_utils/parser/cwl_v1_0_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import hashlib

from schema_salad.exceptions import ValidationException
from schema_salad.utils import json_dumps

from cwl_utils.parser.cwl_v1_0 import CommandLineTool, CommandOutputBinding


def convert_stdstreams_to_files(clt: CommandLineTool) -> None:
for out in clt.outputs:
if out.type == 'stdout':
if out.outputBinding is not None:
raise ValidationException(
"Not allowed to specify outputBinding when using stdout shortcut.")
if clt.stdout is None:
clt.stdout = str(hashlib.sha1(json_dumps( # nosec
clt.save(), sort_keys=True).encode('utf-8')).hexdigest())
out.type = 'File'
out.outputBinding = CommandOutputBinding(glob=clt.stdout)
elif out.type == 'stderr':
if out.outputBinding is not None:
raise ValidationException(
"Not allowed to specify outputBinding when using stderr shortcut.")
if clt.stderr is None:
clt.stderr = str(hashlib.sha1(json_dumps( # nosec
clt.save(), sort_keys=True).encode('utf-8')).hexdigest())
out.type = 'File'
out.outputBinding = CommandOutputBinding(glob=clt.stderr)
40 changes: 40 additions & 0 deletions cwl_utils/parser/cwl_v1_1_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import hashlib
from typing import cast

from schema_salad.exceptions import ValidationException
from schema_salad.utils import json_dumps

from cwl_utils.parser.cwl_v1_1 import CommandLineTool, CommandOutputBinding


def convert_stdstreams_to_files(clt: CommandLineTool) -> None:
for out in clt.outputs:
if out.type == 'stdout':
if out.outputBinding is not None:
raise ValidationException(
"Not allowed to specify outputBinding when using stdout shortcut.")
if clt.stdout is None:
clt.stdout = str(hashlib.sha1(json_dumps( # nosec
clt.save(), sort_keys=True).encode('utf-8')).hexdigest())
out.type = 'File'
out.outputBinding = CommandOutputBinding(glob=clt.stdout)
elif out.type == 'stderr':
if out.outputBinding is not None:
raise ValidationException(
"Not allowed to specify outputBinding when using stderr shortcut.")
if clt.stderr is None:
clt.stderr = str(hashlib.sha1(json_dumps( # nosec
clt.save(), sort_keys=True).encode('utf-8')).hexdigest())
out.type = 'File'
out.outputBinding = CommandOutputBinding(glob=clt.stderr)
for inp in clt.inputs:
if inp.type == 'stdin':
if inp.inputBinding is not None:
raise ValidationException(
"Not allowed to specify unputBinding when using stdin shortcut.")
if clt.stdin is not None:
raise ValidationException(
"Not allowed to specify stdin path when using stdin type shortcut.")
else:
clt.stdin = '$(inputs.%s.path)' % cast(str, inp.id).rpartition('#')[2].split('/')[-1]
inp.type = 'File'
40 changes: 40 additions & 0 deletions cwl_utils/parser/cwl_v1_2_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import hashlib
from typing import cast

from schema_salad.exceptions import ValidationException
from schema_salad.utils import json_dumps

from cwl_utils.parser.cwl_v1_2 import CommandLineTool, CommandOutputBinding


def convert_stdstreams_to_files(clt: CommandLineTool) -> None:
for out in clt.outputs:
if out.type == 'stdout':
if out.outputBinding is not None:
raise ValidationException(
"Not allowed to specify outputBinding when using stdout shortcut.")
if clt.stdout is None:
clt.stdout = str(hashlib.sha1(json_dumps( # nosec
clt.save(), sort_keys=True).encode('utf-8')).hexdigest())
out.type = 'File'
out.outputBinding = CommandOutputBinding(glob=clt.stdout)
elif out.type == 'stderr':
if out.outputBinding is not None:
raise ValidationException(
"Not allowed to specify outputBinding when using stderr shortcut.")
if clt.stderr is None:
clt.stderr = str(hashlib.sha1(json_dumps( # nosec
clt.save(), sort_keys=True).encode('utf-8')).hexdigest())
out.type = 'File'
out.outputBinding = CommandOutputBinding(glob=clt.stderr)
for inp in clt.inputs:
if inp.type == 'stdin':
if inp.inputBinding is not None:
raise ValidationException(
"Not allowed to specify unputBinding when using stdin shortcut.")
if clt.stdin is not None:
raise ValidationException(
"Not allowed to specify stdin path when using stdin type shortcut.")
else:
clt.stdin = '$(inputs.%s.path)' % cast(str, inp.id).rpartition('#')[2].split('/')[-1]
inp.type = 'File'
Loading

0 comments on commit 9fee238

Please sign in to comment.