Skip to content

Add yamlcopy to work around bug in ruamel.ordereddict #261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion cwltool/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json

from schema_salad.ref_resolver import Loader
from ruamel.yaml.comments import CommentedMap, CommentedSeq

from .process import scandeps, shortname

Expand Down Expand Up @@ -42,6 +43,26 @@ def replace_refs(d, rewrite, stem, newstem):
d[s] = newstem + v[len(stem):]
replace_refs(v, rewrite, stem, newstem)

def yamlcopy(d):
if isinstance(d, CommentedMap):
cm = CommentedMap()
for k,v in d.iteritems():
cm[k] = yamlcopy(v)
cm.__dict__ = copy.deepcopy(d.__dict__)
return cm
elif isinstance(d, CommentedSeq):
cs = CommentedSeq()
for v in d:
cs.append(yamlcopy(v))
cs.__dict__ = copy.deepcopy(d.__dict__)
return cs
elif isinstance(d, dict):
return {k: yamlcopy(v) for k,v in d.iteritems()}
elif isinstance(d, list):
return [yamlcopy(v) for v in d]
else:
return d

def pack(document_loader, processobj, uri, metadata):
# type: (Loader, Union[Dict[Text, Any], List[Dict[Text, Any]]], Text, Dict[Text, Text]) -> Dict[Text, Any]
def loadref(b, u):
Expand Down Expand Up @@ -71,7 +92,7 @@ def loadref(b, u):

for r in sorted(rewrite.keys()):
v = rewrite[r]
dc = cast(Dict[Text, Any], copy.deepcopy(document_loader.idx[r]))
dc = cast(Dict[Text, Any], yamlcopy(document_loader.idx[r]))
dc["id"] = v
for n in ("name", "cwlVersion"):
if n in dc:
Expand Down