Skip to content

Commit

Permalink
convert: add input object document
Browse files Browse the repository at this point in the history
  • Loading branch information
simleo committed Apr 14, 2023
1 parent 0c331a0 commit fd46a97
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/runcrate/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@


WORKFLOW_BASENAME = "packed.cwl"
INPUTS_FILE_BASENAME = "primary-job.json"

CWL_TYPE_MAP = {
"string": "Text",
Expand Down Expand Up @@ -256,6 +257,7 @@ def build(self):
self.add_engine_run(crate)
self.add_action(crate, self.workflow_run)
self.patch_workflow_input_collection(crate)
self.add_inputs_file(crate)
return crate

def add_root_metadata(self, crate):
Expand Down Expand Up @@ -644,3 +646,11 @@ def patch_workflow_input_collection(self, crate, wf=None):
for tool in wf.get("hasPart", []):
if "ComputationalWorkflow" in as_list(tool.type):
self.patch_workflow_input_collection(crate, wf=tool)

def add_inputs_file(self, crate):
path = self.root / "workflow" / INPUTS_FILE_BASENAME
if path.is_file():
crate.add_file(path, properties={
"name": "input object document",
"encodingFormat": "application/json",
})
6 changes: 6 additions & 0 deletions tests/test_cwlprov_crate_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def test_revsort(data_dir, tmpdir):
output = tmpdir / "revsort-run-1-crate"
license = "Apache-2.0"
readme = data_dir / "README.md"
inputs_file = data_dir / "workflow" / "primary-job.json"
workflow_name = "RevSort"
builder = ProvCrateBuilder(root, workflow_name=workflow_name, license=license, readme=readme)
crate = builder.build()
Expand Down Expand Up @@ -140,6 +141,11 @@ def test_revsort(data_dir, tmpdir):
assert set(_connected(workflow)) == set([
("packed.cwl#sorttool.cwl/output", "packed.cwl#main/output"),
])
inputs_f = crate.get(inputs_file.name)
assert inputs_f
assert inputs_f.type == "File"
assert inputs_f["encodingFormat"] == "application/json"

# file contents
in_text = (root / "data/32/327fc7aedf4f6b69a42a7c8b808dc5a7aff61376").read_text()
assert (output / wf_input_file.id).read_text() == in_text
Expand Down

0 comments on commit fd46a97

Please sign in to comment.