Skip to content

Commit 65aedc5

Browse files
roksysmr-c
authored andcommitted
cli: fix for --target (#995)
* cli: fix for --target * New way to format url in case of $graph workflow. Solves #991. Signed-off-by: Rokas Maciulaitis <[email protected]> * tests: for --target option * Adding tests for `--target` option. Signed-off-by: Rokas Maciulaitis <[email protected]> * mark tests are requiring Docker under MS Windows
1 parent aaaece1 commit 65aedc5

File tree

3 files changed

+142
-3
lines changed

3 files changed

+142
-3
lines changed

cwltool/main.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import sys
1414
import time
1515
from codecs import StreamWriter, getwriter # pylint: disable=unused-import
16+
from six.moves import urllib
1617
from typing import (IO, Any, Callable, Dict, Iterable, List, Mapping,
1718
MutableMapping, MutableSequence, Optional, TextIO, Tuple,
1819
Union, cast)
@@ -702,9 +703,13 @@ def my_represent_none(self, data): # pylint: disable=unused-argument
702703

703704
if args.target:
704705
if isinstance(tool, Workflow):
705-
extracted = get_subgraph([document_loader.fetcher.urljoin(tool.tool["id"], "#"+r)
706-
for r in args.target],
707-
tool)
706+
url = urllib.parse.urlparse(tool.tool["id"])
707+
if url.fragment:
708+
extracted = get_subgraph([tool.tool["id"] + "/" + r for r in args.target], tool)
709+
else:
710+
extracted = get_subgraph([document_loader.fetcher.urljoin(tool.tool["id"], "#" + r)
711+
for r in args.target],
712+
tool)
708713
else:
709714
_logger.error("Can only use --target on Workflows")
710715
return 1

tests/test_target.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from cwltool.main import main
2+
3+
from .util import get_data, windows_needs_docker
4+
5+
6+
@windows_needs_docker
7+
def test_target():
8+
"""Test --target option successful."""
9+
test_file = "tests/wf/scatter-wf4.cwl"
10+
exit_code = main(['--target', 'out', get_data(test_file),
11+
'--inp1', 'INP1', '--inp2', 'INP2'])
12+
assert exit_code == 0
13+
14+
15+
def test_wrong_target():
16+
"""Test --target option when value is wrong."""
17+
test_file = "tests/wf/scatter-wf4.cwl"
18+
exit_code = main(['--target', 'dummy_target',
19+
get_data(test_file),
20+
'--inp1', 'INP1', '--inp2', 'INP2'])
21+
assert exit_code == 1
22+
23+
24+
@windows_needs_docker
25+
def test_target_packed():
26+
"""Test --target option with packed workflow schema."""
27+
test_file = "tests/wf/scatter-wf4.json"
28+
exit_code = main(['--target', 'out',
29+
get_data(test_file),
30+
'--inp1', 'INP1', '--inp2', 'INP2'])
31+
assert exit_code == 0

tests/wf/scatter-wf4.json

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
"cwlVersion": "v1.0",
3+
"$graph": [
4+
{
5+
"inputs": [
6+
{
7+
"inputBinding": {},
8+
"type": "string",
9+
"id": "#echo/echo_in1"
10+
},
11+
{
12+
"inputBinding": {},
13+
"type": "string",
14+
"id": "#echo/echo_in2"
15+
}
16+
],
17+
"requirements": [
18+
{
19+
"ramMin": 10,
20+
"class": "ResourceRequirement"
21+
}
22+
],
23+
"stdout": "step1_out",
24+
"outputs": [
25+
{
26+
"outputBinding": {
27+
"glob": "step1_out",
28+
"loadContents": true,
29+
"outputEval": "$(self[0].contents)"
30+
},
31+
"type": "string",
32+
"id": "#echo/echo_out"
33+
}
34+
],
35+
"baseCommand": "echo",
36+
"class": "CommandLineTool",
37+
"arguments": [
38+
"-n",
39+
"foo"
40+
],
41+
"id": "#echo"
42+
},
43+
{
44+
"inputs": [
45+
{
46+
"type": {
47+
"items": "string",
48+
"type": "array"
49+
},
50+
"id": "#main/inp1"
51+
},
52+
{
53+
"type": {
54+
"items": "string",
55+
"type": "array"
56+
},
57+
"id": "#main/inp2"
58+
}
59+
],
60+
"requirements": [
61+
{
62+
"class": "ScatterFeatureRequirement"
63+
}
64+
],
65+
"outputs": [
66+
{
67+
"type": {
68+
"items": "string",
69+
"type": "array"
70+
},
71+
"outputSource": "#main/step1/echo_out",
72+
"id": "#main/out"
73+
}
74+
],
75+
"class": "Workflow",
76+
"steps": [
77+
{
78+
"run": "#echo",
79+
"scatter": [
80+
"#main/step1/echo_in1",
81+
"#main/step1/echo_in2"
82+
],
83+
"in": [
84+
{
85+
"source": "#main/inp1",
86+
"id": "#main/step1/echo_in1"
87+
},
88+
{
89+
"source": "#main/inp2",
90+
"id": "#main/step1/echo_in2"
91+
}
92+
],
93+
"scatterMethod": "dotproduct",
94+
"id": "#main/step1",
95+
"out": [
96+
"#main/step1/echo_out"
97+
]
98+
}
99+
],
100+
"id": "#main"
101+
}
102+
]
103+
}

0 commit comments

Comments
 (0)