Skip to content

Commit c5e2912

Browse files
committed
mypyc: enable subclassing and/or pickling of popular classes
Fixes: DataBiosphere/toil#4394
1 parent 5947fd2 commit c5e2912

27 files changed

+120
-48
lines changed

cwltool/builder.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919

2020
from cwl_utils import expression
2121
from cwl_utils.file_formats import check_format
22+
from mypy_extensions import mypyc_attr
2223
from rdflib import Graph
24+
from ruamel.yaml.comments import CommentedMap
2325
from schema_salad.avro.schema import Names, Schema, make_avsc_object
2426
from schema_salad.exceptions import ValidationException
2527
from schema_salad.sourceline import SourceLine
2628
from schema_salad.utils import convert_to_dict, json_dumps
2729
from schema_salad.validate import validate
2830

29-
from ruamel.yaml.comments import CommentedMap
30-
3131
from .errors import WorkflowException
3232
from .loghandler import _logger
3333
from .mutation import MutationManager
@@ -94,6 +94,7 @@ def substitute(value: str, replace: str) -> str:
9494
return value + replace
9595

9696

97+
@mypyc_attr(allow_interpreted_subclasses=True)
9798
class Builder(HasReqsHints):
9899
"""Helper class to construct a command line from a CWL CommandLineTool."""
99100

cwltool/command_line_tool.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@
3232
)
3333

3434
import shellescape
35+
from mypy_extensions import mypyc_attr
36+
from ruamel.yaml.comments import CommentedMap, CommentedSeq
3537
from schema_salad.avro.schema import Schema
3638
from schema_salad.exceptions import ValidationException
3739
from schema_salad.ref_resolver import file_uri, uri_file_path
3840
from schema_salad.sourceline import SourceLine
3941
from schema_salad.utils import json_dumps
4042
from schema_salad.validate import validate_ex
4143

42-
from ruamel.yaml.comments import CommentedMap, CommentedSeq
43-
4444
from .builder import (
4545
INPUT_OBJ_VOCAB,
4646
Builder,
@@ -208,6 +208,7 @@ def run(
208208
self.output_callback({}, "permanentFail")
209209

210210

211+
@mypyc_attr(allow_interpreted_subclasses=True)
211212
class ExpressionTool(Process):
212213
def job(
213214
self,
@@ -315,6 +316,7 @@ def revmap_file(builder: Builder, outdir: str, f: CWLObjectType) -> Optional[CWL
315316
)
316317

317318

319+
@mypyc_attr(serializable=True)
318320
class CallbackJob:
319321
"""Callback Job class, used by :py:func:`CommandLineTool.job`."""
320322

@@ -401,6 +403,7 @@ def __init__(self, msg: str, port: CWLObjectType, **kwargs: Any) -> None:
401403
)
402404

403405

406+
@mypyc_attr(allow_interpreted_subclasses=True)
404407
class CommandLineTool(Process):
405408
def __init__(self, toolpath_object: CommentedMap, loadingContext: LoadingContext) -> None:
406409
"""Initialize this CommandLineTool."""
@@ -470,8 +473,8 @@ def make_job_runner(self, runtimeContext: RuntimeContext) -> Type[JobBase]:
470473
)
471474
return CommandLineJob
472475

476+
@staticmethod
473477
def make_path_mapper(
474-
self,
475478
reffiles: List[CWLObjectType],
476479
stagedir: str,
477480
runtimeContext: RuntimeContext,

cwltool/context.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@
1818
Union,
1919
)
2020

21+
from ruamel.yaml.comments import CommentedMap
2122
from schema_salad.avro.schema import Names
2223
from schema_salad.ref_resolver import Loader
2324
from schema_salad.utils import FetcherCallableType
2425
from typing_extensions import Literal
2526

26-
from ruamel.yaml.comments import CommentedMap
27-
2827
from .mpi import MpiConfig
2928
from .pathmapper import PathMapper
3029
from .stdfsaccess import StdFsAccess

cwltool/cwlrdf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55
from rdflib import Graph
66
from rdflib.query import ResultRow
7+
from ruamel.yaml.comments import CommentedMap
78
from schema_salad.jsonld_context import makerdf
89
from schema_salad.utils import ContextType
910

10-
from ruamel.yaml.comments import CommentedMap
11-
1211
from .cwlviewer import CWLViewer
1312
from .process import Process
1413

cwltool/docker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def __init__(
8383
self,
8484
builder: Builder,
8585
joborder: CWLObjectType,
86-
make_path_mapper: Callable[..., PathMapper],
86+
make_path_mapper: Callable[[List[CWLObjectType], str, RuntimeContext, bool], PathMapper],
8787
requirements: List[CWLObjectType],
8888
hints: List[CWLObjectType],
8989
name: str,
@@ -452,7 +452,7 @@ def __init__(
452452
self,
453453
builder: Builder,
454454
joborder: CWLObjectType,
455-
make_path_mapper: Callable[..., PathMapper],
455+
make_path_mapper: Callable[[List[CWLObjectType], str, RuntimeContext, bool], PathMapper],
456456
requirements: List[CWLObjectType],
457457
hints: List[CWLObjectType],
458458
name: str,

cwltool/executors.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
)
2121

2222
import psutil
23+
from mypy_extensions import mypyc_attr
2324
from schema_salad.exceptions import ValidationException
2425
from schema_salad.sourceline import SourceLine
2526

@@ -40,6 +41,7 @@
4041
TMPDIR_LOCK = Lock()
4142

4243

44+
@mypyc_attr(allow_interpreted_subclasses=True)
4345
class JobExecutor(metaclass=ABCMeta):
4446
"""Abstract base job executor."""
4547

@@ -178,6 +180,7 @@ def check_for_abstract_op(tool: CWLObjectType) -> None:
178180
return (None, "permanentFail")
179181

180182

183+
@mypyc_attr(allow_interpreted_subclasses=True)
181184
class SingleJobExecutor(JobExecutor):
182185
"""Default single-threaded CWL reference executor."""
183186

cwltool/job.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def __init__(
118118
self,
119119
builder: Builder,
120120
joborder: CWLObjectType,
121-
make_path_mapper: Callable[..., PathMapper],
121+
make_path_mapper: Callable[[List[CWLObjectType], str, RuntimeContext, bool], PathMapper],
122122
requirements: List[CWLObjectType],
123123
hints: List[CWLObjectType],
124124
name: str,

cwltool/load_tool.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
)
2222

2323
from cwl_utils.parser import cwl_v1_2, cwl_v1_2_utils
24+
from ruamel.yaml.comments import CommentedMap, CommentedSeq
2425
from schema_salad.exceptions import ValidationException
2526
from schema_salad.fetcher import Fetcher
2627
from schema_salad.ref_resolver import Loader, file_uri
@@ -34,8 +35,6 @@
3435
json_dumps,
3536
)
3637

37-
from ruamel.yaml.comments import CommentedMap, CommentedSeq
38-
3938
from . import CWL_CONTENT_TYPES, process, update
4039
from .context import LoadingContext
4140
from .errors import GraphTargetMissingException

cwltool/main.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
import argcomplete
3535
import coloredlogs
3636
import pkg_resources # part of setuptools
37+
import ruamel.yaml
38+
from ruamel.yaml.comments import CommentedMap, CommentedSeq
39+
from ruamel.yaml.main import YAML
3740
from schema_salad.exceptions import ValidationException
3841
from schema_salad.ref_resolver import Loader, file_uri, uri_file_path
3942
from schema_salad.sourceline import cmap, strip_dup_lineno
@@ -45,10 +48,6 @@
4548
yaml_no_ts,
4649
)
4750

48-
import ruamel.yaml
49-
from ruamel.yaml.comments import CommentedMap, CommentedSeq
50-
from ruamel.yaml.main import YAML
51-
5251
from . import CWL_CONTENT_TYPES, workflow
5352
from .argparser import arg_parser, generate_parser, get_default_args
5453
from .context import LoadingContext, RuntimeContext, getdefault

cwltool/pack.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414
cast,
1515
)
1616

17+
from ruamel.yaml.comments import CommentedMap, CommentedSeq
1718
from schema_salad.ref_resolver import Loader, SubLoader
1819
from schema_salad.utils import ResolveType
1920

20-
from ruamel.yaml.comments import CommentedMap, CommentedSeq
21-
2221
from .context import LoadingContext
2322
from .load_tool import fetch_document, resolve_and_validate_document
2423
from .process import shortname, uniquename

0 commit comments

Comments
 (0)