|
24 | 24 | from re import Pattern |
25 | 25 | from typing import TYPE_CHECKING, Any, Optional, TextIO, Union, cast |
26 | 26 |
|
| 27 | +from cwl_utils.types import ( |
| 28 | + CWLObjectType, |
| 29 | + CWLOutputType, |
| 30 | + DirectoryType, |
| 31 | + is_directory, |
| 32 | + is_file, |
| 33 | + is_file_or_directory, |
| 34 | +) |
27 | 35 | from mypy_extensions import mypyc_attr |
28 | 36 | from ruamel.yaml.comments import CommentedMap, CommentedSeq |
29 | 37 | from schema_salad.avro.schema import RecordSchema |
|
60 | 68 | from .udocker import UDockerCommandLineJob |
61 | 69 | from .update import ORDERED_VERSIONS, ORIGINAL_CWLVERSION |
62 | 70 | from .utils import ( |
63 | | - CWLObjectType, |
64 | | - CWLOutputType, |
65 | | - DirectoryType, |
66 | 71 | JobsGeneratorType, |
67 | 72 | OutputCallbackType, |
68 | 73 | adjustDirObjs, |
@@ -619,11 +624,8 @@ def _initialworkdir(self, j: JobBase | None, builder: Builder) -> None: |
619 | 624 | et: CWLObjectType = {} |
620 | 625 | writable = t.get("writable", False) |
621 | 626 | et["writable"] = writable |
622 | | - if isinstance(entry, Mapping) and entry.get("class") in ( |
623 | | - "File", |
624 | | - "Directory", |
625 | | - ): |
626 | | - if writable and "secondaryFiles" in entry: |
| 627 | + if is_file_or_directory(entry): |
| 628 | + if writable and is_file(entry) and "secondaryFiles" in entry: |
627 | 629 | secFiles = cast(MutableSequence[CWLObjectType], entry["secondaryFiles"]) |
628 | 630 | for sf in secFiles: |
629 | 631 | sf["writable"] = writable |
@@ -765,22 +767,23 @@ def _initialworkdir(self, j: JobBase | None, builder: Builder) -> None: |
765 | 767 | for entry in ls: |
766 | 768 | if "basename" in entry: |
767 | 769 | basename = cast(str, entry["basename"]) |
768 | | - dirname = os.path.join(builder.outdir, os.path.dirname(basename)) |
769 | | - entry["dirname"] = dirname |
770 | 770 | entry["basename"] = os.path.basename(basename) |
771 | | - if "secondaryFiles" in entry: |
772 | | - for sec_file in cast( |
773 | | - MutableSequence[CWLObjectType], entry["secondaryFiles"] |
774 | | - ): |
775 | | - sec_file["dirname"] = dirname |
| 771 | + if is_file(entry): |
| 772 | + dirname = os.path.join(builder.outdir, os.path.dirname(basename)) |
| 773 | + entry["dirname"] = dirname |
| 774 | + if "secondaryFiles" in entry: |
| 775 | + for sec_file in cast( |
| 776 | + MutableSequence[CWLObjectType], entry["secondaryFiles"] |
| 777 | + ): |
| 778 | + sec_file["dirname"] = dirname |
776 | 779 | normalizeFilesDirs(entry) |
777 | 780 | self.updatePathmap( |
778 | | - cast(Optional[str], entry.get("dirname")) or builder.outdir, |
| 781 | + (entry.get("dirname") if is_file(entry) else None) or builder.outdir, |
779 | 782 | cast(PathMapper, builder.pathmapper), |
780 | 783 | entry, |
781 | 784 | ) |
782 | 785 |
|
783 | | - if "listing" in entry: |
| 786 | + if is_directory(entry) and "listing" in entry: |
784 | 787 |
|
785 | 788 | def remove_dirname(d: CWLObjectType) -> None: |
786 | 789 | if "dirname" in d: |
|
0 commit comments