Skip to content

Commit 9fee238

Browse files
Added stdstreams to file conversion utils (#144)
1 parent 9a4f9d1 commit 9fee238

File tree

5 files changed

+479
-0
lines changed

5 files changed

+479
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,7 @@ venv.bak/
107107

108108
testenv*/
109109
pydocstyle_report.txt
110+
111+
# PyCharm
112+
.idea/
113+

cwl_utils/parser/cwl_v1_0_utils.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import hashlib
2+
3+
from schema_salad.exceptions import ValidationException
4+
from schema_salad.utils import json_dumps
5+
6+
from cwl_utils.parser.cwl_v1_0 import CommandLineTool, CommandOutputBinding
7+
8+
9+
def convert_stdstreams_to_files(clt: CommandLineTool) -> None:
10+
for out in clt.outputs:
11+
if out.type == 'stdout':
12+
if out.outputBinding is not None:
13+
raise ValidationException(
14+
"Not allowed to specify outputBinding when using stdout shortcut.")
15+
if clt.stdout is None:
16+
clt.stdout = str(hashlib.sha1(json_dumps( # nosec
17+
clt.save(), sort_keys=True).encode('utf-8')).hexdigest())
18+
out.type = 'File'
19+
out.outputBinding = CommandOutputBinding(glob=clt.stdout)
20+
elif out.type == 'stderr':
21+
if out.outputBinding is not None:
22+
raise ValidationException(
23+
"Not allowed to specify outputBinding when using stderr shortcut.")
24+
if clt.stderr is None:
25+
clt.stderr = str(hashlib.sha1(json_dumps( # nosec
26+
clt.save(), sort_keys=True).encode('utf-8')).hexdigest())
27+
out.type = 'File'
28+
out.outputBinding = CommandOutputBinding(glob=clt.stderr)

cwl_utils/parser/cwl_v1_1_utils.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import hashlib
2+
from typing import cast
3+
4+
from schema_salad.exceptions import ValidationException
5+
from schema_salad.utils import json_dumps
6+
7+
from cwl_utils.parser.cwl_v1_1 import CommandLineTool, CommandOutputBinding
8+
9+
10+
def convert_stdstreams_to_files(clt: CommandLineTool) -> None:
11+
for out in clt.outputs:
12+
if out.type == 'stdout':
13+
if out.outputBinding is not None:
14+
raise ValidationException(
15+
"Not allowed to specify outputBinding when using stdout shortcut.")
16+
if clt.stdout is None:
17+
clt.stdout = str(hashlib.sha1(json_dumps( # nosec
18+
clt.save(), sort_keys=True).encode('utf-8')).hexdigest())
19+
out.type = 'File'
20+
out.outputBinding = CommandOutputBinding(glob=clt.stdout)
21+
elif out.type == 'stderr':
22+
if out.outputBinding is not None:
23+
raise ValidationException(
24+
"Not allowed to specify outputBinding when using stderr shortcut.")
25+
if clt.stderr is None:
26+
clt.stderr = str(hashlib.sha1(json_dumps( # nosec
27+
clt.save(), sort_keys=True).encode('utf-8')).hexdigest())
28+
out.type = 'File'
29+
out.outputBinding = CommandOutputBinding(glob=clt.stderr)
30+
for inp in clt.inputs:
31+
if inp.type == 'stdin':
32+
if inp.inputBinding is not None:
33+
raise ValidationException(
34+
"Not allowed to specify unputBinding when using stdin shortcut.")
35+
if clt.stdin is not None:
36+
raise ValidationException(
37+
"Not allowed to specify stdin path when using stdin type shortcut.")
38+
else:
39+
clt.stdin = '$(inputs.%s.path)' % cast(str, inp.id).rpartition('#')[2].split('/')[-1]
40+
inp.type = 'File'

cwl_utils/parser/cwl_v1_2_utils.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import hashlib
2+
from typing import cast
3+
4+
from schema_salad.exceptions import ValidationException
5+
from schema_salad.utils import json_dumps
6+
7+
from cwl_utils.parser.cwl_v1_2 import CommandLineTool, CommandOutputBinding
8+
9+
10+
def convert_stdstreams_to_files(clt: CommandLineTool) -> None:
11+
for out in clt.outputs:
12+
if out.type == 'stdout':
13+
if out.outputBinding is not None:
14+
raise ValidationException(
15+
"Not allowed to specify outputBinding when using stdout shortcut.")
16+
if clt.stdout is None:
17+
clt.stdout = str(hashlib.sha1(json_dumps( # nosec
18+
clt.save(), sort_keys=True).encode('utf-8')).hexdigest())
19+
out.type = 'File'
20+
out.outputBinding = CommandOutputBinding(glob=clt.stdout)
21+
elif out.type == 'stderr':
22+
if out.outputBinding is not None:
23+
raise ValidationException(
24+
"Not allowed to specify outputBinding when using stderr shortcut.")
25+
if clt.stderr is None:
26+
clt.stderr = str(hashlib.sha1(json_dumps( # nosec
27+
clt.save(), sort_keys=True).encode('utf-8')).hexdigest())
28+
out.type = 'File'
29+
out.outputBinding = CommandOutputBinding(glob=clt.stderr)
30+
for inp in clt.inputs:
31+
if inp.type == 'stdin':
32+
if inp.inputBinding is not None:
33+
raise ValidationException(
34+
"Not allowed to specify unputBinding when using stdin shortcut.")
35+
if clt.stdin is not None:
36+
raise ValidationException(
37+
"Not allowed to specify stdin path when using stdin type shortcut.")
38+
else:
39+
clt.stdin = '$(inputs.%s.path)' % cast(str, inp.id).rpartition('#')[2].split('/')[-1]
40+
inp.type = 'File'

0 commit comments

Comments
 (0)