Skip to content

Commit

Permalink
--pack generates same-file $import to reference shared objects (#353)
Browse files Browse the repository at this point in the history
* Use same-file $import to reference shared objects (such as SchemaDefRequirement).
  • Loading branch information
tetron authored Mar 29, 2017
1 parent d8981e1 commit eba1d64
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cwltool/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,26 @@ def replace_refs(d, rewrite, stem, newstem):
d[s] = newstem + v[len(stem):]
replace_refs(v, rewrite, stem, newstem)

def import_embed(d, seen):
# type: (Any, Set[Text]) -> None
if isinstance(d, list):
for v in d:
import_embed(v, seen)
elif isinstance(d, dict):
for n in ("id", "name"):
if n in d:
if d[n] in seen:
this = d[n]
d.clear()
d["$import"] = this
else:
this = d[n]
seen.add(this)
break

for v in d.values():
import_embed(v, seen)


def pack(document_loader, processobj, uri, metadata):
# type: (Loader, Union[Dict[Text, Any], List[Dict[Text, Any]]], Text, Dict[Text, Text]) -> Dict[Text, Any]
Expand Down Expand Up @@ -133,4 +153,6 @@ def rewrite_id(r, mainuri):
v = rewrite[r]
replace_refs(packed, rewrite, r + "/" if "#" in r else r + "#", v + "/")

import_embed(packed, set())

return packed

0 comments on commit eba1d64

Please sign in to comment.