Skip to content

Commit c7c3799

Browse files
authored
Pass loadingContext to pack(). (#1263)
Ensures that all the document loading options get passed through.
1 parent 2256a30 commit c7c3799

File tree

5 files changed

+19
-22
lines changed

5 files changed

+19
-22
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ DEVPKGS=diff_cover black pylint coverage pep257 pydocstyle flake8 mypy\
2929
pytest-xdist==1.27.0 isort wheel -rtest-requirements.txt
3030
DEBDEVPKGS=pep8 python-autopep8 pylint python-coverage pydocstyle sloccount \
3131
python-flake8 python-mock shellcheck
32-
VERSION=2.0.$(shell TZ=UTC git log --first-parent --max-count=1 \
32+
VERSION=3.0.$(shell TZ=UTC git log --first-parent --max-count=1 \
3333
--format=format:%cd --date=format-local:%Y%m%d%H%M%S)
3434
mkfile_dir := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
3535
UNAME_S=$(shell uname -s)

cwltool/main.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -554,12 +554,11 @@ def loadref(base, uri): # type: (str, str) -> Any
554554

555555

556556
def print_pack(
557-
document_loader, # type: Loader
557+
loadingContext, # type: LoadingContext
558558
uri, # type: str
559-
metadata, # type: Dict[str, Any]
560559
): # type: (...) -> str
561560
"""Return a CWL serialization of the CWL document in JSON."""
562-
packed = pack(document_loader, uri, metadata)
561+
packed = pack(loadingContext, uri)
563562
if len(packed["$graph"]) > 1:
564563
return json_dumps(packed, indent=4)
565564
return json_dumps(packed["$graph"][0], indent=4)
@@ -923,13 +922,13 @@ def main(
923922
processobj, metadata = loadingContext.loader.resolve_ref(uri)
924923
processobj = cast(CommentedMap, processobj)
925924
if args.pack:
926-
stdout.write(print_pack(loadingContext.loader, uri, metadata))
925+
stdout.write(print_pack(loadingContext, uri))
927926
return 0
928927

929928
if args.provenance and runtimeContext.research_obj:
930929
# Can't really be combined with args.pack at same time
931930
runtimeContext.research_obj.packed_workflow(
932-
print_pack(loadingContext.loader, uri, metadata)
931+
print_pack(loadingContext, uri)
933932
)
934933

935934
if args.print_pre:

cwltool/pack.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ def import_embed(d, seen):
122122

123123

124124
def pack(
125-
document_loader: Loader,
125+
loadingContext: LoadingContext,
126126
uri, # type: str
127-
metadata, # type: Dict[str, str]
128127
rewrite_out=None, # type: Optional[Dict[str, str]]
128+
loader=None, # type: Optional[Loader]
129129
): # type: (...) -> Dict[str, Any]
130130

131131
# The workflow document we have in memory right now may have been
@@ -138,8 +138,8 @@ def pack(
138138
# loading process with an empty index and updating turned off
139139
# so we have the original un-updated documents.
140140
#
141-
document_loader = SubLoader(document_loader)
142-
loadingContext = LoadingContext()
141+
loadingContext = loadingContext.copy()
142+
document_loader = SubLoader(loader or loadingContext.loader or Loader({}))
143143
loadingContext.do_update = False
144144
loadingContext.loader = document_loader
145145
loadingContext.loader.idx = {}
@@ -223,7 +223,6 @@ def rewrite_id(r, mainuri):
223223
dcr = cast(CommentedMap, dcr)
224224
if not isinstance(dcr, MutableMapping):
225225
continue
226-
metadata = cast(Dict[str, Any], metadata)
227226
if "$schemas" in metadata:
228227
for s in metadata["$schemas"]:
229228
schemas.add(s)

cwltool/update.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ def v1_1_0dev1to1_1(doc, loader, baseuri): # pylint: disable=unused-argument
143143
# type: (Any, Loader, str) -> Tuple[Any, str]
144144
return (doc, "v1.1")
145145

146+
146147
def v1_2_0dev1todev2(doc, loader, baseuri): # pylint: disable=unused-argument
147148
# type: (Any, Loader, str) -> Tuple[Any, str]
148149
return (doc, "v1.2.0-dev2")

tests/test_pack.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_pack():
2626
with open(get_data("tests/wf/expect_packed.cwl")) as packed_file:
2727
expect_packed = yaml.safe_load(packed_file)
2828

29-
packed = cwltool.pack.pack(loadingContext.loader, uri, loadingContext.metadata)
29+
packed = cwltool.pack.pack(loadingContext, uri)
3030
adjustFileObjs(
3131
packed, partial(make_relative, os.path.abspath(get_data("tests/wf")))
3232
)
@@ -53,7 +53,7 @@ def test_pack_input_named_name():
5353
with open(get_data("tests/wf/expect_trick_packed.cwl")) as packed_file:
5454
expect_packed = yaml.round_trip_load(packed_file)
5555

56-
packed = cwltool.pack.pack(loadingContext.loader, uri, loadingContext.metadata)
56+
packed = cwltool.pack.pack(loadingContext, uri)
5757
adjustFileObjs(
5858
packed, partial(make_relative, os.path.abspath(get_data("tests/wf")))
5959
)
@@ -77,7 +77,7 @@ def test_pack_single_tool():
7777
)
7878
processobj = loadingContext.loader.resolve_ref(uri)[0]
7979

80-
packed = cwltool.pack.pack(loadingContext.loader, uri, loadingContext.metadata)
80+
packed = cwltool.pack.pack(loadingContext, uri)
8181
assert "$schemas" in packed
8282

8383

@@ -86,9 +86,7 @@ def test_pack_fragment():
8686
expect_packed = yaml.safe_load(packed_file)
8787

8888
loadingContext, workflowobj, uri = fetch_document(get_data("tests/wf/scatter2.cwl"))
89-
packed = cwltool.pack.pack(
90-
loadingContext.loader, uri + "#scatterstep/mysub", loadingContext.metadata
91-
)
89+
packed = cwltool.pack.pack(loadingContext, uri + "#scatterstep/mysub")
9290
adjustFileObjs(
9391
packed, partial(make_relative, os.path.abspath(get_data("tests/wf")))
9492
)
@@ -112,7 +110,7 @@ def test_pack_rewrites():
112110
processobj = loadingContext.loader.resolve_ref(uri)[0]
113111

114112
cwltool.pack.pack(
115-
loadingContext.loader, uri, loadingContext.metadata, rewrite_out=rewrites,
113+
loadingContext, uri, rewrite_out=rewrites,
116114
)
117115

118116
assert len(rewrites) == 6
@@ -136,7 +134,7 @@ def test_pack_missing_cwlVersion(cwl_path):
136134
processobj = loadingContext.loader.resolve_ref(uri)[0]
137135

138136
# generate pack output dict
139-
packed = json.loads(print_pack(loadingContext.loader, uri, loadingContext.metadata))
137+
packed = json.loads(print_pack(loadingContext, uri))
140138

141139
assert packed["cwlVersion"] == "v1.0"
142140

@@ -160,7 +158,7 @@ def _pack_idempotently(document):
160158
processobj = loadingContext.loader.resolve_ref(uri)[0]
161159

162160
# generate pack output dict
163-
packed_text = print_pack(loadingContext.loader, uri, loadingContext.metadata)
161+
packed_text = print_pack(loadingContext, uri)
164162
packed = json.loads(packed_text)
165163

166164
tmp = NamedTemporaryFile(mode="w", delete=False)
@@ -177,7 +175,7 @@ def _pack_idempotently(document):
177175
processobj = loadingContext.loader.resolve_ref(uri2)[0]
178176

179177
# generate pack output dict
180-
packed_text = print_pack(loadingContext.loader, uri2, loadingContext.metadata)
178+
packed_text = print_pack(loadingContext, uri2)
181179
double_packed = json.loads(packed_text)
182180
finally:
183181
os.remove(tmp.name)
@@ -203,7 +201,7 @@ def test_packed_workflow_execution(wf_path, job_path, namespaced, tmpdir):
203201
loadingContext, workflowobj, uri
204202
)
205203
processobj = loadingContext.loader.resolve_ref(uri)[0]
206-
packed = json.loads(print_pack(loadingContext.loader, uri, loadingContext.metadata))
204+
packed = json.loads(print_pack(loadingContext, uri))
207205

208206
assert not namespaced or "$namespaces" in packed
209207

0 commit comments

Comments
 (0)