Skip to content

Commit 3c0326c

Browse files
committed
better interpolation
1 parent 77a2a31 commit 3c0326c

File tree

4 files changed

+70
-34
lines changed

4 files changed

+70
-34
lines changed

cwl_utils/cwl_v1_0_expression_refactor.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"""CWL Expression refactoring tool for CWL v1.0 ."""
33
import copy
44
import hashlib
5-
import logging
65
from collections.abc import Mapping
76
from typing import (
87
Any,
@@ -114,16 +113,29 @@ def get_expression(
114113
resources={},
115114
)
116115
except (WorkflowException, JavascriptException):
117-
return cast(
118-
str,
119-
interpolate(
120-
scan=string,
121-
rootvars={"inputs": inputs, "context": self, "runtime": runtime},
122-
fullJS=True,
123-
escaping_behavior=2,
124-
convert_to_expression=True,
125-
),
126-
)
116+
if (
117+
string[0:2] != "$("
118+
or not string.endswith(")")
119+
or len(string.split("$(")) > 2
120+
):
121+
# then it is a string interpolation
122+
return cast(
123+
str,
124+
interpolate(
125+
scan=string,
126+
rootvars={
127+
"inputs": inputs,
128+
"context": self,
129+
"runtime": runtime,
130+
},
131+
fullJS=True,
132+
escaping_behavior=2,
133+
convert_to_expression=True,
134+
),
135+
)
136+
else:
137+
# it is a CWL Expression in $() with no string interpolation
138+
return "${return " + string.strip()[2:-1] + ";}"
127139
return None
128140

129141

cwl_utils/cwl_v1_1_expression_refactor.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"""CWL Expression refactoring tool for CWL v1.1 ."""
33
import copy
44
import hashlib
5-
import logging
65
from collections.abc import Mapping
76
from typing import (
87
Any,
@@ -114,16 +113,29 @@ def get_expression(
114113
resources={},
115114
)
116115
except (WorkflowException, JavascriptException):
117-
return cast(
118-
str,
119-
interpolate(
120-
scan=string,
121-
rootvars={"inputs": inputs, "context": self, "runtime": runtime},
122-
fullJS=True,
123-
escaping_behavior=2,
124-
convert_to_expression=True,
125-
),
126-
)
116+
if (
117+
string[0:2] != "$("
118+
or not string.endswith(")")
119+
or len(string.split("$(")) > 2
120+
):
121+
# then it is a string interpolation
122+
return cast(
123+
str,
124+
interpolate(
125+
scan=string,
126+
rootvars={
127+
"inputs": inputs,
128+
"context": self,
129+
"runtime": runtime,
130+
},
131+
fullJS=True,
132+
escaping_behavior=2,
133+
convert_to_expression=True,
134+
),
135+
)
136+
else:
137+
# it is a CWL Expression in $() with no string interpolation
138+
return "${return " + string.strip()[2:-1] + ";}"
127139
return None
128140

129141

cwl_utils/cwl_v1_2_expression_refactor.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"""CWL Expression refactoring tool for CWL v1.2 ."""
33
import copy
44
import hashlib
5-
import logging
65
from collections.abc import Mapping
76
from typing import (
87
Any,
@@ -114,16 +113,29 @@ def get_expression(
114113
resources={},
115114
)
116115
except (WorkflowException, JavascriptException):
117-
return cast(
118-
str,
119-
interpolate(
120-
scan=string,
121-
rootvars={"inputs": inputs, "context": self, "runtime": runtime},
122-
fullJS=True,
123-
escaping_behavior=2,
124-
convert_to_expression=True,
125-
),
126-
)
116+
if (
117+
string[0:2] != "$("
118+
or not string.endswith(")")
119+
or len(string.split("$(")) > 2
120+
):
121+
# then it is a string interpolation
122+
return cast(
123+
str,
124+
interpolate(
125+
scan=string,
126+
rootvars={
127+
"inputs": inputs,
128+
"context": self,
129+
"runtime": runtime,
130+
},
131+
fullJS=True,
132+
escaping_behavior=2,
133+
convert_to_expression=True,
134+
),
135+
)
136+
else:
137+
# it is a CWL Expression in $() with no string interpolation
138+
return "${return " + string.strip()[2:-1] + ";}"
127139
return None
128140

129141

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"requests",
2323
"schema-salad >= 7, < 8",
2424
"typing_extensions",
25-
"cwltool",
25+
"cwltool >= 3.0.20201113183607",
2626
"cwlformat",
2727
],
2828
setup_requires=[] + pytest_runner,

0 commit comments

Comments
 (0)