Skip to content

Commit f908ff6

Browse files
authored
Merge branch 'master' into py3_window
2 parents 8ff8f13 + 5729aa6 commit f908ff6

File tree

12 files changed

+131
-32
lines changed

12 files changed

+131
-32
lines changed

cwltool/builder.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def __init__(self): # type: () -> None
4949
self.make_fs_access = None # type: Type[StdFsAccess]
5050
self.debug = False # type: bool
5151
self.mutation_manager = None # type: MutationManager
52+
self.force_docker_pull = False # type: bool
5253

5354
# One of "no_listing", "shallow_listing", "deep_listing"
5455
# Will be default "no_listing" for CWL v1.1
@@ -245,4 +246,5 @@ def do_eval(self, ex, context=None, pull_image=True, recursive=False):
245246
self.resources,
246247
context=context, pull_image=pull_image,
247248
timeout=self.timeout,
249+
force_docker_pull=self.force_docker_pull,
248250
debug=self.debug)

cwltool/expression.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ def next_seg(remain, obj): # type: (Text, Any) -> Any
153153
return obj
154154

155155

156-
def evaluator(ex, jslib, obj, fullJS=False, timeout=None, debug=False):
157-
# type: (Text, Text, Dict[Text, Any], bool, int, bool) -> JSON
156+
def evaluator(ex, jslib, obj, fullJS=False, timeout=None, force_docker_pull=False, debug=False):
157+
# type: (Text, Text, Dict[Text, Any], bool, int, bool, bool) -> JSON
158158
m = param_re.match(ex)
159159
if m:
160160
if m.end(1)+1 == len(ex) and m.group(1) == "null":
@@ -164,16 +164,17 @@ def evaluator(ex, jslib, obj, fullJS=False, timeout=None, debug=False):
164164
except Exception as w:
165165
raise WorkflowException("%s%s" % (m.group(1), w))
166166
elif fullJS:
167-
return sandboxjs.execjs(ex, jslib, timeout=timeout, debug=debug)
167+
return sandboxjs.execjs(ex, jslib, timeout=timeout, force_docker_pull=force_docker_pull, debug=debug)
168168
else:
169169
raise sandboxjs.JavascriptException(
170170
"Syntax error in parameter reference '%s' or used Javascript code without specifying InlineJavascriptRequirement.",
171171
ex)
172172

173173

174174
def interpolate(scan, rootvars,
175-
timeout=None, fullJS=None, jslib="", debug=False):
176-
# type: (Text, Dict[Text, Any], int, bool, Union[str, Text], bool) -> JSON
175+
timeout=None, fullJS=None, jslib="",force_docker_pull=False,
176+
debug=False):
177+
# type: (Text, Dict[Text, Any], int, bool, Union[str, Text], bool, bool) -> JSON
177178
scan = scan.strip()
178179
parts = []
179180
w = scanner(scan)
@@ -182,7 +183,8 @@ def interpolate(scan, rootvars,
182183

183184
if scan[w[0]] == '$':
184185
e = evaluator(scan[w[0] + 1:w[1]], jslib, rootvars, fullJS=fullJS,
185-
timeout=timeout, debug=debug)
186+
timeout=timeout, force_docker_pull=force_docker_pull,
187+
debug=debug)
186188
if w[0] == 0 and w[1] == len(scan):
187189
return e
188190
leaf = json.dumps(e, sort_keys=True)
@@ -200,8 +202,8 @@ def interpolate(scan, rootvars,
200202

201203

202204
def do_eval(ex, jobinput, requirements, outdir, tmpdir, resources,
203-
context=None, pull_image=True, timeout=None, debug=False):
204-
# type: (Union[dict, AnyStr], Dict[Text, Union[Dict, List, Text]], List[Dict[Text, Any]], Text, Text, Dict[Text, Union[int, Text]], Any, bool, int, bool) -> Any
205+
context=None, pull_image=True, timeout=None, force_docker_pull=False, debug=False):
206+
# type: (Union[dict, AnyStr], Dict[Text, Union[Dict, List, Text]], List[Dict[Text, Any]], Text, Text, Dict[Text, Union[int, Text]], Any, bool, int, bool, bool) -> Any
205207

206208
runtime = copy.copy(resources)
207209
runtime["tmpdir"] = docker_windows_path_adjust(tmpdir)
@@ -227,6 +229,7 @@ def do_eval(ex, jobinput, requirements, outdir, tmpdir, resources,
227229
timeout=timeout,
228230
fullJS=fullJS,
229231
jslib=jslib,
232+
force_docker_pull=force_docker_pull,
230233
debug=debug)
231234
except Exception as e:
232235
raise WorkflowException("Expression evaluation error:\n%s" % e)

cwltool/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@ def arg_parser(): # type: () -> argparse.ArgumentParser
226226
exgroup.add_argument("--make-template", action="store_true",
227227
help="Generate a template input object")
228228

229-
229+
parser.add_argument("--force-docker-pull", action="store_true",
230+
default=False, help="Pull latest docker image even if"
231+
" it is locally present", dest="force_docker_pull")
230232
parser.add_argument("workflow", type=Text, nargs="?", default=None)
231233
parser.add_argument("job_order", nargs=argparse.REMAINDER)
232234

cwltool/pack.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,9 @@ def rewrite_id(r, mainuri):
157157

158158
import_embed(packed, set())
159159

160+
if len(packed["$graph"]) == 1:
161+
# duplicate 'cwlVersion' inside $graph when there is a single item
162+
# because we're printing contents inside '$graph' rather than whole dict
163+
packed["$graph"][0]["cwlVersion"] = packed["cwlVersion"]
164+
160165
return packed

cwltool/process.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ def _init_job(self, joborder, **kwargs):
560560

561561
builder.make_fs_access = kwargs.get("make_fs_access") or StdFsAccess
562562
builder.fs_access = builder.make_fs_access(kwargs["basedir"])
563+
builder.force_docker_pull = kwargs.get("force_docker_pull")
563564

564565
loadListingReq, _ = self.get_requirement("http://commonwl.org/cwltool#LoadListingRequirement")
565566
if loadListingReq:

cwltool/sandboxjs.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ def check_js_threshold_version(working_alias):
5353
return False
5454

5555

56-
def new_js_proc():
57-
# type: () -> subprocess.Popen
56+
def new_js_proc(force_docker_pull=False):
57+
# type: (bool) -> subprocess.Popen
5858

5959
res = resource_stream(__name__, 'cwlNodeEngine.js')
6060
nodecode = res.read().decode('utf-8')
@@ -86,10 +86,11 @@ def new_js_proc():
8686
try:
8787
nodeimg = "node:slim"
8888
global have_node_slim
89+
8990
if not have_node_slim:
9091
dockerimgs = subprocess.check_output(["docker", "images", "-q", nodeimg]).decode('utf-8')
9192
# if output is an empty string
92-
if len(dockerimgs.split("\n")) <= 1:
93+
if (len(dockerimgs.split("\n")) <= 1) or force_docker_pull:
9394
# pull node:slim docker container
9495
nodejsimg = subprocess.check_output(["docker", "pull", nodeimg]).decode('utf-8')
9596
_logger.info("Pulled Docker image %s %s", nodeimg, nodejsimg)
@@ -124,10 +125,10 @@ def new_js_proc():
124125
return nodejs
125126

126127

127-
def execjs(js, jslib, timeout=None, debug=False): # type: (Union[Mapping, Text], Any, int, bool) -> JSON
128+
def execjs(js, jslib, timeout=None, force_docker_pull=False, debug=False): # type: (Union[Mapping, Text], Any, int, bool, bool) -> JSON
128129

129130
if not hasattr(localdata, "proc") or localdata.proc.poll() is not None or onWindows():
130-
localdata.proc = new_js_proc()
131+
localdata.proc = new_js_proc(force_docker_pull=force_docker_pull)
131132

132133
nodejs = localdata.proc
133134

jenkins.bash

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,40 @@ cloneorpull() {
1414
}
1515
venv() {
1616
if ! test -d "$1" ; then
17-
virtualenv "$1"
17+
virtualenv -p python${PYTHON_VERSION} "$1"
1818
fi
1919
# shellcheck source=/dev/null
2020
source "$1"/bin/activate
2121
}
22-
git clean --force -d -x || /bin/true
22+
2323
cloneorpull common-workflow-language https://github.com/common-workflow-language/common-workflow-language.git
24-
venv cwltool-venv
2524
docker pull node:slim
26-
export PIP_DOWNLOAD_CACHE=/var/lib/jenkins/pypi-cache/
27-
pip install -U setuptools wheel pip
28-
python setup.py install
29-
pip install "cwltest>=1.0.20160825151655"
30-
pushd common-workflow-language
25+
# clean both the repos before the loop
3126
git clean --force -d -x || /bin/true
32-
# shellcheck disable=SC2154
33-
if [[ "$version" = *dev* ]]
34-
then
35-
EXTRA="EXTRA=--enable-dev"
36-
fi
37-
./run_test.sh --junit-xml=result.xml RUNNER=cwltool -j4 DRAFT="${version}" ${EXTRA}
38-
CODE=$?
39-
popd
27+
git -C common-workflow-language clean --force -d -x || /bin/true
28+
29+
# Test for Python 2.7 and Python 3
30+
for PYTHON_VERSION in 2.7 3
31+
do
32+
venv cwltool-venv${PYTHON_VERSION}
33+
export PIP_DOWNLOAD_CACHE=/var/lib/jenkins/pypi-cache/
34+
# use pip2.7 and pip3 in separate loop runs
35+
pip${PYTHON_VERSION} install -U setuptools wheel pip
36+
pip${PYTHON_VERSION} install .
37+
pip${PYTHON_VERSION} install "cwltest>=1.0.20160825151655"
38+
pushd common-workflow-language
39+
# shellcheck disable=SC2154
40+
if [[ "$version" = *dev* ]]
41+
then
42+
EXTRA="EXTRA=--enable-dev"
43+
fi
44+
./run_test.sh --junit-xml=result${PYTHON_VERSION}.xml RUNNER=cwltool -j4 DRAFT=${version}
45+
CODE=$(($CODE+$?)) # capture return code of ./run_test.sh
46+
deactivate
47+
popd
48+
done
49+
50+
# build new docker container
4051
if [ "$GIT_BRANCH" = "origin/master" ] && [[ "$version" = "v1.0" ]]
4152
then
4253
./build-cwl-docker.sh && docker push commonworkflowlanguage/cwltool_module && docker push commonworkflowlanguage/cwltool

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
requests>=1.0
1+
requests>=2.12.4
22
ruamel.yaml>=0.12.4,<0.15
33
rdflib==4.2.2
44
rdflib-jsonld==0.4.0

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
include_package_data=True,
4949
install_requires=[
5050
'setuptools',
51-
'requests >= 1.0',
51+
'requests >= 2.12.4',
5252
'ruamel.yaml >= 0.12.4, < 0.15',
5353
'rdflib >= 4.2.2, < 4.3.0',
5454
'shellescape >= 3.4.1, < 3.5',

tests/test_pack.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from functools import partial
66

77
import cwltool.pack
8+
from cwltool.main import print_pack as print_pack
89
import cwltool.workflow
910
from cwltool.load_tool import fetch_document, validate_document
1011
from cwltool.main import makeRelative
@@ -33,3 +34,29 @@ def test_pack(self):
3334
del expect_packed["$schemas"]
3435

3536
self.assertEqual(expect_packed, packed)
37+
38+
def test_pack_missing_cwlVersion(self):
39+
"""Test to ensure the generated pack output is not missing
40+
the `cwlVersion` in case of single tool workflow and single step workflow"""
41+
# Since diff is longer than 3174 characters
42+
self.maxDiff = None
43+
44+
# Testing single tool workflow
45+
document_loader, workflowobj, uri = fetch_document(
46+
get_data("tests/wf/hello_single_tool.cwl"))
47+
document_loader, avsc_names, processobj, metadata, uri = validate_document(
48+
document_loader, workflowobj, uri)
49+
# generate pack output dict
50+
packed = json.loads(print_pack(document_loader, processobj, uri, metadata))
51+
52+
self.assertEqual('v1.0', packed["cwlVersion"])
53+
54+
# Testing single step workflow
55+
document_loader, workflowobj, uri = fetch_document(
56+
get_data("tests/wf/hello-workflow.cwl"))
57+
document_loader, avsc_names, processobj, metadata, uri = validate_document(
58+
document_loader, workflowobj, uri)
59+
# generate pack output dict
60+
packed = json.loads(print_pack(document_loader, processobj, uri, metadata))
61+
62+
self.assertEqual('v1.0', packed["cwlVersion"])

tests/wf/hello-workflow.cwl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env cwl-runner
2+
3+
cwlVersion: v1.0
4+
class: Workflow
5+
6+
label: "Hello World"
7+
doc: "Outputs a message using echo"
8+
9+
inputs:
10+
usermessage: string
11+
12+
outputs:
13+
response:
14+
outputSource: step0/response
15+
type: File
16+
17+
steps:
18+
step0:
19+
run:
20+
class: CommandLineTool
21+
inputs:
22+
message:
23+
type: string
24+
doc: "The message to print"
25+
default: "Hello World"
26+
inputBinding:
27+
position: 1
28+
baseCommand: echo
29+
arguments:
30+
- "-n"
31+
- "-e"
32+
stdout: response.txt
33+
outputs:
34+
response:
35+
type: stdout
36+
in:
37+
message: usermessage
38+
out: [response]

tests/wf/hello_single_tool.cwl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cwlVersion: v1.0
2+
class: CommandLineTool
3+
baseCommand: echo
4+
inputs:
5+
message:
6+
type: string
7+
inputBinding:
8+
position: 1
9+
outputs: []

0 commit comments

Comments
 (0)