Skip to content

Commit

Permalink
scandeps handles File and Directory objects directly. (#193)
Browse files Browse the repository at this point in the history
* Scandeps understands File and Directory objects and handles directories
better.
  • Loading branch information
tetron authored Sep 18, 2016
1 parent 63f5e50 commit 4f073bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion cwltool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def loadref(b, u):

sf = scandeps(
basedir if basedir else uri, obj, set(("$import", "run")),
set(("$include", "$schemas", "path", "location")), loadref)
set(("$include", "$schemas")), loadref)
if sf:
deps["secondaryFiles"] = sf

Expand All @@ -491,6 +491,7 @@ def makeRelative(ob):
else:
ob["location"] = os.path.relpath(u, base)
adjustFileObjs(deps, makeRelative)
adjustDirObjs(deps, makeRelative)

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

Expand Down
16 changes: 13 additions & 3 deletions cwltool/process.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import os
import json
import copy
Expand Down Expand Up @@ -626,14 +625,15 @@ def mergedirs(listing):
elif e["class"] == "Directory":
ents[e["basename"]]["listing"].extend(e["listing"])
for e in ents.itervalues():
if e["class"] == "Directory":
if e["class"] == "Directory" and "listing" in e:
e["listing"] = mergedirs(e["listing"])
r.extend(ents.itervalues())
return r

def scandeps(base, doc, reffields, urlfields, loadref):
# type: (Text, Any, Set[Text], Set[Text], Callable[[Text, Text], Any]) -> List[Dict[Text, Text]]
r = [] # type: List[Dict[Text, Text]]
deps = None # type: Dict[Text, Any]
if isinstance(doc, dict):
if "id" in doc:
if doc["id"].startswith("file://"):
Expand All @@ -645,6 +645,16 @@ def scandeps(base, doc, reffields, urlfields, loadref):
})
base = df

if doc.get("class") in ("File", "Directory"):
u = doc.get("location", doc.get("path"))
if u:
deps = {
"class": doc["class"],
"location": urlparse.urljoin(base, u)
}
deps = nestdir(base, deps)
r.append(deps)

for k, v in doc.iteritems():
if k in reffields:
for u in aslist(v):
Expand All @@ -656,7 +666,7 @@ def scandeps(base, doc, reffields, urlfields, loadref):
deps = {
"class": "File",
"location": subid
} # type: Dict[Text, Any]
}
sf = scandeps(subid, sub, reffields, urlfields, loadref)
if sf:
deps["secondaryFiles"] = sf
Expand Down

0 comments on commit 4f073bb

Please sign in to comment.