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
27 changes: 20 additions & 7 deletions cwltool/command_line_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,10 +611,16 @@ def _initialworkdir(self, j: Optional[JobBase], builder: Builder) -> None:
continue

et: CWLObjectType = {}
writable = t.get("writable", False)
et["writable"] = writable
if isinstance(entry, Mapping) and entry.get("class") in (
"File",
"Directory",
):
if writable and "secondaryFiles" in entry:
secFiles = cast(MutableSequence[CWLObjectType], entry["secondaryFiles"])
for sf in secFiles:
sf["writable"] = writable
et["entry"] = cast(CWLOutputType, entry)
else:
if isinstance(entry, str):
Expand Down Expand Up @@ -650,7 +656,6 @@ def _initialworkdir(self, j: Optional[JobBase], builder: Builder) -> None:
et["entryname"] = entryname_field
else:
et["entryname"] = None
et["writable"] = t.get("writable", False)
ls.append(et)
else:
# Expression, must return a Dirent, File, Directory
Expand Down Expand Up @@ -700,13 +705,14 @@ def _initialworkdir(self, j: Optional[JobBase], builder: Builder) -> None:
)

if t2.get("entryname") or t2.get("writable"):
t2 = copy.deepcopy(t2)
t2entry = cast(CWLObjectType, t2["entry"])
t2copy = copy.deepcopy(t2)
t2entry = cast(CWLObjectType, t2copy["entry"])
if t2.get("entryname"):
t2entry["basename"] = t2["entryname"]
t2entry["writable"] = t2.get("writable")
t2entry["basename"] = t2copy["entryname"]
t2entry["writable"] = t2copy.get("writable")
t2["entry"] = t2entry

ls[i] = cast(CWLObjectType, t2["entry"])
ls[i] = t2["entry"]

for i, t3 in enumerate(ls):
if t3.get("class") not in ("File", "Directory"):
Expand Down Expand Up @@ -753,14 +759,21 @@ def _initialworkdir(self, j: Optional[JobBase], builder: Builder) -> None:
for entry in ls:
if "basename" in entry:
basename = cast(str, entry["basename"])
entry["dirname"] = os.path.join(builder.outdir, os.path.dirname(basename))
dirname = os.path.join(builder.outdir, os.path.dirname(basename))
entry["dirname"] = dirname
entry["basename"] = os.path.basename(basename)
if "secondaryFiles" in entry:
for sec_file in cast(
MutableSequence[CWLObjectType], entry["secondaryFiles"]
):
sec_file["dirname"] = dirname
normalizeFilesDirs(entry)
self.updatePathmap(
cast(Optional[str], entry.get("dirname")) or builder.outdir,
cast(PathMapper, builder.pathmapper),
entry,
)

if "listing" in entry:

def remove_dirname(d: CWLObjectType) -> None:
Expand Down
4 changes: 2 additions & 2 deletions cwltool/pathmapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ def visit(
copy: bool = False,
staged: bool = False,
) -> None:
if obj["location"] in self._pathmap:
return
stagedir = cast(Optional[str], obj.get("dirname")) or stagedir
tgt = os.path.join(
stagedir,
cast(str, obj["basename"]),
)
if obj["location"] in self._pathmap:
return
if obj["class"] == "Directory":
location = cast(str, obj["location"])
if location.startswith("file://"):
Expand Down
12 changes: 12 additions & 0 deletions tests/iwdr_writable_secfile-inputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"example_file_with_secondary": {
"class": "File",
"location": "2.fasta",
"secondaryFiles": [
{
"class": "File",
"location": "2.fastq"
}
]
}
}
23 changes: 23 additions & 0 deletions tests/iwdr_writable_secfile.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cwlVersion: v1.2
class: CommandLineTool

requirements:
InlineJavascriptRequirement: {}
InitialWorkDirRequirement:
listing:
- entry: $(inputs.example_file_with_secondary)
writable: true
inputs:
example_file_with_secondary:
type: File
secondaryFiles:
- pattern: "^.fastq"
required: true
outputs:
same_file:
type: stdout

baseCommand: cat
arguments:
- $(inputs.example_file_with_secondary.path)
- $(inputs.example_file_with_secondary.path.split('.')[0]+'.fastq')
13 changes: 13 additions & 0 deletions tests/test_iwdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,16 @@ def test_iwdr_permutations_singularity_inplace(
)
== 0
)


def test_iwdr_writable_secondaryfiles(tmp_path: Path) -> None:
"""Confirm that a writable primary file and its secondary files are still co-located."""
err_code, _, _ = get_main_output(
[
"--outdir",
str(tmp_path),
get_data("tests/iwdr_writable_secfile.cwl"),
get_data("tests/iwdr_writable_secfile-inputs.json"),
]
)
assert err_code == 0