Skip to content

Commit 00fce36

Browse files
authored
Scandeps only picks up file objects when "location" in urlfileds. (#194)
* Scandeps only picks up file objects when "location" in urlfileds. * Make test for scandeps actually test something. Also expand pack() test to include external (non-packable) files.
1 parent 4f073bb commit 00fce36

File tree

7 files changed

+72
-17
lines changed

7 files changed

+72
-17
lines changed

cwltool/main.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,14 @@ def pathToLoc(p):
461461

462462
return (job_order_object, input_basedir)
463463

464+
def makeRelative(base, ob):
465+
u = ob.get("location", ob.get("path"))
466+
if ":" in u.split("/")[0] and not u.startswith("file://"):
467+
pass
468+
else:
469+
if u.startswith("file://"):
470+
u = u[7:]
471+
ob["location"] = os.path.relpath(u, base)
464472

465473
def printdeps(obj, document_loader, stdout, relative_deps, uri, basedir=None):
466474
# type: (Dict[Text, Any], Loader, IO[Any], bool, Text, Text) -> None
@@ -472,7 +480,7 @@ def loadref(b, u):
472480

473481
sf = scandeps(
474482
basedir if basedir else uri, obj, set(("$import", "run")),
475-
set(("$include", "$schemas")), loadref)
483+
set(("$include", "$schemas", "location")), loadref)
476484
if sf:
477485
deps["secondaryFiles"] = sf
478486

@@ -484,14 +492,8 @@ def loadref(b, u):
484492
else:
485493
raise Exception(u"Unknown relative_deps %s" % relative_deps)
486494

487-
def makeRelative(ob):
488-
u = ob.get("location", ob.get("path"))
489-
if ":" in u.split("/")[0] and not u.startswith("file://"):
490-
pass
491-
else:
492-
ob["location"] = os.path.relpath(u, base)
493-
adjustFileObjs(deps, makeRelative)
494-
adjustDirObjs(deps, makeRelative)
495+
adjustFileObjs(deps, functools.partial(makeRelative, base))
496+
adjustDirObjs(deps, functools.partial(makeRelative, base))
495497

496498
stdout.write(json.dumps(deps, indent=4))
497499

cwltool/process.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ def scandeps(base, doc, reffields, urlfields, loadref):
645645
})
646646
base = df
647647

648-
if doc.get("class") in ("File", "Directory"):
648+
if doc.get("class") in ("File", "Directory") and "location" in urlfields:
649649
u = doc.get("location", doc.get("path"))
650650
if u:
651651
deps = {

tests/test_examples.py

+37-6
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,16 @@ def test_scandeps(self):
122122
"id": "file:///example/foo.cwl#input1",
123123
"default": {
124124
"class": "File",
125-
"path": "file:///example/data.txt"
125+
"location": "file:///example/data.txt"
126126
}
127127
}],
128128
"run": {
129129
"id": "file:///example/bar.cwl",
130130
"inputs": [{
131131
"id": "file:///example/bar.cwl#input2",
132132
"default": {
133-
"class": "File",
134-
"path": "file:///example/data2.txt"
133+
"class": "Directory",
134+
"location": "file:///example/data2"
135135
}
136136
}]
137137
}
@@ -145,10 +145,41 @@ def loadref(base, p):
145145
else:
146146
raise Exception("test case can't load things")
147147

148-
print json.dumps(cwltool.process.scandeps(obj["id"], obj,
148+
sc = cwltool.process.scandeps(obj["id"], obj,
149149
set(("$import", "run")),
150-
set(("$include", "$schemas", "path")),
151-
loadref), indent=4)
150+
set(("$include", "$schemas", "location")),
151+
loadref)
152+
153+
sc.sort(key=lambda k: k["basename"])
154+
155+
self.assertEquals([{
156+
"basename": "bar.cwl",
157+
"class": "File",
158+
"location": "file:///example/bar.cwl"
159+
},
160+
{
161+
"basename": "data.txt",
162+
"class": "File",
163+
"location": "file:///example/data.txt"
164+
},
165+
{
166+
"basename": "data2",
167+
"class": "Directory",
168+
"location": "file:///example/data2"
169+
}], sc)
170+
171+
sc = cwltool.process.scandeps(obj["id"], obj,
172+
set(("run"),),
173+
set(), loadref)
174+
175+
sc.sort(key=lambda k: k["basename"])
176+
177+
self.assertEquals([{
178+
"basename": "bar.cwl",
179+
"class": "File",
180+
"location": "file:///example/bar.cwl"
181+
}], sc)
182+
152183

153184
class TestTypeCompare(unittest.TestCase):
154185
def test_typecompare(self):

tests/test_pack.py

+9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import unittest
22
import json
3+
import os
4+
from functools import partial
5+
36
from cwltool.load_tool import fetch_document, validate_document
47
import cwltool.pack
58
import cwltool.workflow
9+
from cwltool.main import makeRelative
10+
from cwltool.process import adjustFileObjs, adjustDirObjs
11+
612

713
class TestPack(unittest.TestCase):
814
def test_pack(self):
@@ -14,4 +20,7 @@ def test_pack(self):
1420
packed = cwltool.pack.pack(document_loader, processobj, uri, metadata)
1521
with open("tests/wf/expect_packed.cwl") as f:
1622
expect_packed = json.load(f)
23+
adjustFileObjs(packed, partial(makeRelative, os.path.abspath("tests/wf")))
24+
adjustDirObjs(packed, partial(makeRelative, os.path.abspath("tests/wf")))
25+
1726
self.assertEqual(expect_packed, packed)

tests/wf/expect_packed.cwl

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
{
77
"doc": "The input file to be processed.",
88
"type": "File",
9-
"id": "#main/input"
9+
"id": "#main/input",
10+
"default": {
11+
"class": "File",
12+
"location": "hello.txt"
13+
}
1014
},
1115
{
1216
"default": true,

tests/wf/hello.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Hello
2+
world
3+
testing
4+
one
5+
two
6+
three.

tests/wf/revsort.cwl

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ inputs:
2323
input:
2424
type: File
2525
doc: "The input file to be processed."
26+
default:
27+
class: File
28+
location: hello.txt
2629
reverse_sort:
2730
type: boolean
2831
default: true

0 commit comments

Comments
 (0)