Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions src/toil/cwl/cwltoil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2648,12 +2648,21 @@ def writeGlobalFileWrapper(


def remove_empty_listings(rec: CWLDirectoryType) -> None:
"""
Drop each empty listing that cwltool can list again from where it is.

A Directory literal (one cwltool gave a "_:" location) is not anywhere to
be listed: its listing is all there is of it, even when empty, so it keeps
it.
"""
if rec.get("class") != "Directory":
finddirs: list[CWLDirectoryType] = []
visit_class(rec, ("Directory",), finddirs.append)
for f in finddirs:
remove_empty_listings(f)
return
if rec.get("location", "_:").startswith("_:"):
return
if "listing" in rec and rec["listing"] == []:
del rec["listing"]
return
Expand Down
23 changes: 23 additions & 0 deletions src/toil/test/cwl/cwlTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2275,6 +2275,29 @@ def test_captured_stderr_for_failed_job_is_reported(tmp_path: Path) -> None:
assert "Message: This is a test" in p.stderr


@needs_cwl
@pytest.mark.cwl
@pytest.mark.cwl_small
def test_empty_directory_literal_input(tmp_path: Path) -> None:
"""
Make sure a tool can write into an empty Directory literal it is given:
the literal has nothing on disk to list, so its empty listing is all
there is of it and must reach the worker.
"""
with get_data("test/cwl/empty_directory_literal.cwl") as cwl_file:
with get_data("test/cwl/empty_directory_literal.json") as job_file:
cmd = [
"toil-cwl-runner",
f"--jobStore=file:{tmp_path / 'jobStore'}",
f"--outdir={tmp_path / 'outdir'}",
str(cwl_file),
str(job_file),
]
p = subprocess.run(cmd, capture_output=True, text=True)
assert p.returncode == 0, p.stderr
assert (tmp_path / "outdir" / "out" / "written").is_file()


@needs_cwl
@pytest.mark.cwl
@pytest.mark.cwl_small
Expand Down
17 changes: 17 additions & 0 deletions src/toil/test/cwl/empty_directory_literal.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cwlVersion: v1.2
class: CommandLineTool
doc: Write a file into an empty Directory literal given as an input, and return it.
requirements:
InitialWorkDirRequirement:
listing:
- entry: $(inputs.target)
writable: true
inputs:
target: Directory
baseCommand: [touch]
arguments: [$(inputs.target.basename)/written]
outputs:
filled:
type: Directory
outputBinding:
glob: $(inputs.target.basename)
7 changes: 7 additions & 0 deletions src/toil/test/cwl/empty_directory_literal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"target": {
"class": "Directory",
"basename": "out",
"listing": []
}
}
Loading