Skip to content

Commit 0f82805

Browse files
GlassOfWhiskeymr-c
authored andcommitted
Solving some typing problems
1 parent 852b080 commit 0f82805

35 files changed

+78
-77
lines changed

cwltool/builder.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from cwl_utils import expression
1111
from cwl_utils.file_formats import check_format
12+
from cwl_utils.types import CWLObjectType, CWLOutputType
1213
from mypy_extensions import mypyc_attr
1314
from rdflib import Graph
1415
from ruamel.yaml.comments import CommentedMap
@@ -26,8 +27,6 @@
2627
from .stdfsaccess import StdFsAccess
2728
from .utils import (
2829
CONTENT_LIMIT,
29-
CWLObjectType,
30-
CWLOutputType,
3130
HasReqsHints,
3231
LoadListingType,
3332
aslist,

cwltool/checker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
from collections.abc import Iterator, MutableMapping, MutableSequence, Sized
44
from typing import Any, Literal, NamedTuple, Optional, Union, cast
55

6+
from cwl_utils.types import CWLObjectType, CWLOutputType, SinkType
67
from schema_salad.exceptions import ValidationException
78
from schema_salad.sourceline import SourceLine, bullets, strip_dup_lineno
89
from schema_salad.utils import json_dumps
910

1011
from .errors import WorkflowException
1112
from .loghandler import _logger
1213
from .process import shortname
13-
from .utils import CWLObjectType, CWLOutputType, SinkType, aslist
14+
from .utils import aslist
1415

1516

1617
def _get_type(tp: Any) -> Any:

cwltool/command_line_tool.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@
2424
from re import Pattern
2525
from typing import TYPE_CHECKING, Any, Optional, TextIO, Union, cast
2626

27+
from cwl_utils.types import (
28+
CWLObjectType,
29+
CWLOutputType,
30+
DirectoryType,
31+
is_directory,
32+
is_file,
33+
is_file_or_directory,
34+
)
2735
from mypy_extensions import mypyc_attr
2836
from ruamel.yaml.comments import CommentedMap, CommentedSeq
2937
from schema_salad.avro.schema import RecordSchema
@@ -60,9 +68,6 @@
6068
from .udocker import UDockerCommandLineJob
6169
from .update import ORDERED_VERSIONS, ORIGINAL_CWLVERSION
6270
from .utils import (
63-
CWLObjectType,
64-
CWLOutputType,
65-
DirectoryType,
6671
JobsGeneratorType,
6772
OutputCallbackType,
6873
adjustDirObjs,
@@ -619,11 +624,8 @@ def _initialworkdir(self, j: JobBase | None, builder: Builder) -> None:
619624
et: CWLObjectType = {}
620625
writable = t.get("writable", False)
621626
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:
627629
secFiles = cast(MutableSequence[CWLObjectType], entry["secondaryFiles"])
628630
for sf in secFiles:
629631
sf["writable"] = writable
@@ -765,22 +767,23 @@ def _initialworkdir(self, j: JobBase | None, builder: Builder) -> None:
765767
for entry in ls:
766768
if "basename" in entry:
767769
basename = cast(str, entry["basename"])
768-
dirname = os.path.join(builder.outdir, os.path.dirname(basename))
769-
entry["dirname"] = dirname
770770
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
776779
normalizeFilesDirs(entry)
777780
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,
779782
cast(PathMapper, builder.pathmapper),
780783
entry,
781784
)
782785

783-
if "listing" in entry:
786+
if is_directory(entry) and "listing" in entry:
784787

785788
def remove_dirname(d: CWLObjectType) -> None:
786789
if "dirname" in d:

cwltool/context.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from collections.abc import Callable, Iterable
99
from typing import IO, TYPE_CHECKING, Any, Literal, Optional, TextIO, Union
1010

11+
from cwl_utils.types import CWLObjectType
1112
from ruamel.yaml.comments import CommentedMap
1213
from schema_salad.avro.schema import Names
1314
from schema_salad.ref_resolver import Loader
@@ -16,7 +17,7 @@
1617
from .mpi import MpiConfig
1718
from .pathmapper import PathMapper
1819
from .stdfsaccess import StdFsAccess
19-
from .utils import DEFAULT_TMP_PREFIX, CWLObjectType, HasReqsHints, ResolverType
20+
from .utils import DEFAULT_TMP_PREFIX, HasReqsHints, ResolverType
2021

2122
if TYPE_CHECKING:
2223
from _typeshed import SupportsWrite

cwltool/cuda.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
import subprocess # nosec
44
import xml.dom.minidom # nosec
55

6+
from cwl_utils.types import CWLObjectType
7+
68
from .loghandler import _logger
7-
from .utils import CWLObjectType
89

910

1011
def cuda_version_and_device_count() -> tuple[str, int]:

cwltool/cwlprov/provenance_profile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pathlib import PurePath, PurePosixPath
99
from typing import TYPE_CHECKING, Any, cast
1010

11+
from cwl_utils.types import CWLObjectType
1112
from prov.identifier import Identifier, QualifiedName
1213
from prov.model import PROV, PROV_LABEL, PROV_TYPE, PROV_VALUE, ProvDocument, ProvEntity
1314
from schema_salad.sourceline import SourceLine
@@ -17,7 +18,7 @@
1718
from ..loghandler import _logger
1819
from ..process import Process, shortname
1920
from ..stdfsaccess import StdFsAccess
20-
from ..utils import CWLObjectType, JobsType, get_listing, posix_path, versionstring
21+
from ..utils import JobsType, get_listing, posix_path, versionstring
2122
from ..workflow_job import WorkflowJob
2223
from .provenance_constants import (
2324
ACCOUNT_UUID,

cwltool/cwlprov/ro.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@
1313
from typing import IO, TYPE_CHECKING, Any, Optional, cast
1414

1515
import prov.model as provM
16+
from cwl_utils.types import CWLObjectType, CWLOutputType, is_directory, is_file
1617
from prov.model import ProvDocument
1718

1819
from ..loghandler import _logger
1920
from ..stdfsaccess import StdFsAccess
2021
from ..utils import (
21-
CWLObjectType,
22-
CWLOutputType,
2322
create_tmp_dir,
2423
local_path,
2524
posix_path,
@@ -642,10 +641,10 @@ def _relativise_files(
642641
_logger.debug("[provenance] Relativising: %s", structure)
643642

644643
if isinstance(structure, MutableMapping):
645-
if structure.get("class") == "File":
644+
if is_file(structure):
646645
relative_path: str | PurePosixPath | None = None
647646
if "checksum" in structure:
648-
raw_checksum = cast(str, structure["checksum"])
647+
raw_checksum = structure["checksum"]
649648
alg, checksum = raw_checksum.split("$")
650649
if alg != SHA1:
651650
raise TypeError(
@@ -659,7 +658,7 @@ def _relativise_files(
659658
# Register in RO; but why was this not picked
660659
# up by used_artefacts?
661660
_logger.info("[provenance] Adding to RO %s", structure["location"])
662-
with self.fsaccess.open(cast(str, structure["location"]), "rb") as fp:
661+
with self.fsaccess.open(structure["location"], "rb") as fp:
663662
relative_path = self.add_data_file(fp)
664663
checksum = PurePosixPath(relative_path).name
665664
structure["checksum"] = f"{SHA1}${checksum}"
@@ -668,7 +667,7 @@ def _relativise_files(
668667
if "path" in structure:
669668
del structure["path"]
670669

671-
if structure.get("class") == "Directory":
670+
if is_directory(structure):
672671
# TODO: Generate anonymous Directory with a "listing"
673672
# pointing to the hashed files
674673
del structure["location"]

cwltool/cwlprov/writablebagfile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
from pathlib import Path, PurePosixPath
1515
from typing import Any, BinaryIO, cast
1616

17+
from cwl_utils.types import CWLObjectType
1718
from schema_salad.utils import json_dumps
1819

1920
from ..loghandler import _logger
20-
from ..utils import CWLObjectType, local_path, posix_path
21+
from ..utils import local_path, posix_path
2122
from .provenance_constants import (
2223
CWLPROV,
2324
CWLPROV_VERSION,

cwltool/docker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from typing import Optional, cast
1515

1616
import requests
17+
from cwl_utils.types import CWLObjectType
1718

1819
from .builder import Builder
1920
from .context import RuntimeContext
@@ -22,7 +23,7 @@
2223
from .job import ContainerCommandLineJob
2324
from .loghandler import _logger
2425
from .pathmapper import MapperEnt, PathMapper
25-
from .utils import CWLObjectType, create_tmp_dir, ensure_writable
26+
from .utils import create_tmp_dir, ensure_writable
2627

2728
_IMAGES: set[str] = set()
2829
_IMAGES_LOCK = threading.Lock()

cwltool/executors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from typing import Optional, cast
1414

1515
import psutil
16+
from cwl_utils.types import CWLObjectType
1617
from mypy_extensions import mypyc_attr
1718
from schema_salad.exceptions import ValidationException
1819
from schema_salad.sourceline import SourceLine
@@ -27,7 +28,7 @@
2728
from .process import Process, cleanIntermediate, relocateOutputs
2829
from .task_queue import TaskQueue
2930
from .update import ORIGINAL_CWLVERSION
30-
from .utils import CWLObjectType, JobsType
31+
from .utils import JobsType
3132
from .workflow import Workflow
3233
from .workflow_job import WorkflowJob, WorkflowJobStep
3334

0 commit comments

Comments
 (0)