Skip to content

Commit a23db06

Browse files
authored
upgrade to mypy 0.971 (#139)
1 parent 0576e19 commit a23db06

File tree

9 files changed

+47
-32
lines changed

9 files changed

+47
-32
lines changed

cwl_utils/cwl_normalizer.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ def run(args: argparse.Namespace) -> int:
8383
add_lc_filename(result, document)
8484
version = result.get("cwlVersion", None)
8585
if version in ("draft-3", "cwl:draft-3", "v1.0", "v1.1"):
86-
result = cwlupgrader.upgrade_document(
87-
result, False, False, args.dir, imports
88-
)
86+
result = cwlupgrader.upgrade_document(result, args.dir, imports=imports)
8987
else:
9088
_logger.error(
9189
"Sorry, %s in %s is not a supported CWL version by this tool.",

cwl_utils/graph_split.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
import argparse
1212
import json
1313
import os
14-
from typing import Any, IO, MutableMapping, Set, Union, cast
14+
from typing import IO, Any, MutableMapping, Set, Union, cast
1515

1616
from cwlformat.formatter import stringify_dict
17-
from ruamel import yaml
17+
from ruamel.yaml.main import YAML, dump
18+
from ruamel.yaml.representer import RoundTripRepresenter
19+
from ruamel.yaml.dumper import RoundTripDumper
1820
from schema_salad.sourceline import SourceLine, add_lc_filename
1921

2022

@@ -72,7 +74,9 @@ def run(
7274
sourceIO: IO[str], output_dir: str, output_format: str, mainfile: str, pretty: bool
7375
) -> None:
7476
"""Loop over the provided packed CWL document and split it up."""
75-
source = yaml.main.round_trip_load(sourceIO, preserve_quotes=True)
77+
yaml = YAML(typ="rt")
78+
yaml.preserve_quotes = True # type: ignore[assignment]
79+
source = yaml.load(sourceIO)
7680
add_lc_filename(source, sourceIO.name)
7781

7882
if "$graph" not in source:
@@ -87,7 +91,7 @@ def my_represent_none(
8791
"""Force clean representation of 'null'."""
8892
return self.represent_scalar("tag:yaml.org,2002:null", "null")
8993

90-
yaml.representer.RoundTripRepresenter.add_representer(type(None), my_represent_none)
94+
RoundTripRepresenter.add_representer(type(None), my_represent_none)
9195

9296
for entry in source["$graph"]:
9397
entry_id = entry.pop("id")[1:]
@@ -205,9 +209,7 @@ def rewrite_schemadef(document: MutableMapping[str, Any]) -> Set[str]:
205209
field["name"] = field["name"].split("/")[2]
206210
rewrite_types(field, entry_file, True)
207211
with open(entry_file[1:], "a", encoding="utf-8") as entry_handle:
208-
yaml.main.dump(
209-
[entry], entry_handle, Dumper=yaml.dumper.RoundTripDumper
210-
)
212+
dump([entry], entry_handle, Dumper=RoundTripDumper)
211213
entry["$import"] = entry_file[1:]
212214
del entry["name"]
213215
del entry["type"]
@@ -236,16 +238,17 @@ def json_dump(entry: Any, output_file: str) -> None:
236238

237239
def yaml_dump(entry: Any, output_file: str, pretty: bool) -> None:
238240
"""Output object as YAML."""
241+
yaml = YAML(typ="rt")
242+
yaml.default_flow_style = False
243+
yaml.map_indent = 4 # type: ignore[assignment]
244+
yaml.sequence_indent = 2 # type: ignore[assignment]
239245
with open(output_file, "w", encoding="utf-8") as result_handle:
240246
if pretty:
241247
result_handle.write(stringify_dict(entry))
242248
else:
243-
yaml.main.round_trip_dump(
249+
yaml.dump(
244250
entry,
245251
result_handle,
246-
default_flow_style=False,
247-
indent=4,
248-
block_seq_indent=2,
249252
)
250253

251254

cwl_utils/pack.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,25 @@
1818
import sys
1919
import urllib.parse
2020
import urllib.request
21-
from typing import Any, Dict, ItemsView, List, Optional, Tuple, cast
21+
from typing import (
22+
TYPE_CHECKING,
23+
Any,
24+
Dict,
25+
ItemsView,
26+
List,
27+
Optional,
28+
Tuple,
29+
Union,
30+
cast,
31+
)
2232

2333
from packaging import version
2434

2535
from cwl_utils import schemadef, utils
2636

37+
if TYPE_CHECKING:
38+
from _collections_abc import dict_items
39+
2740
logger = logging.getLogger(__name__)
2841

2942

@@ -167,7 +180,7 @@ def resolve_schemadefs(
167180

168181
def resolve_imports(cwl: Any, base_url: urllib.parse.ParseResult) -> Any:
169182
if isinstance(cwl, dict):
170-
itr = cwl.items()
183+
itr: Union["dict_items[Any, Any]", ItemsView[Any, Any]] = cwl.items()
171184
elif isinstance(cwl, list):
172185
itr = cast(ItemsView[Any, Any], [(n, v) for n, v in enumerate(cwl)])
173186
else:

cwl_utils/sandboxjs.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,13 @@ def __init__(
9797
self.have_node_slim: bool = have_node_slim
9898
self.minimum_node_version_str: str = minimum_node_version_str
9999
self.process_finished_str: str = process_finished_str
100-
self.processes_to_kill = (
101-
collections.deque()
102-
) # type: Deque[subprocess.Popen[str]]
100+
self.processes_to_kill: Deque[subprocess.Popen[str]] = collections.deque()
103101

104102
def __del__(self) -> None:
105-
kill_processes(self.processes_to_kill)
103+
try:
104+
kill_processes(self.processes_to_kill)
105+
except TypeError:
106+
pass
106107

107108
def check_js_threshold_version(self, working_alias: str) -> bool:
108109
"""

cwl_utils/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ def _is_github_symbolic_link(base_url: urllib.parse.ParseResult, contents: str)
5151

5252
def bytes2str_in_dicts(
5353
inp: Union[MutableMapping[str, Any], MutableSequence[Any], Any],
54-
):
55-
# type: (...) -> Union[str, MutableSequence[Any], MutableMapping[str, Any]]
54+
) -> Union[str, MutableSequence[Any], MutableMapping[str, Any]]:
5655
"""
5756
Convert any present byte string to unicode string, inplace.
5857

mypy-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
mypy==0.910
1+
mypy==0.971
22
typing_extensions
33
types-requests
44
types-setuptools>==57.4.0

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cwl-upgrader >= 1.2
1+
cwl-upgrader >= 1.2.3
22
packaging
33
requests
44
schema-salad >= 8.2, < 9

tests/load_cwl_by_path.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# SPDX-License-Identifier: Apache-2.0
33
from pathlib import Path
44

5-
65
from cwl_utils.parser import load_document_by_uri, save
76

87
# File Input - This is the only thing you will need to adjust or take in as an input to your function:

tests/test_parser.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Test the load and save functions for CWL."""
22
from pathlib import Path
33

4-
from ruamel import yaml
4+
from ruamel.yaml.main import YAML
55

66
import cwl_utils.parser.latest as latest
77
from cwl_utils.parser import (
@@ -16,20 +16,22 @@
1616
TEST_v1_0_CWL = HERE / "../testdata/md5sum.cwl"
1717
TEST_v1_0_CWL_REMOTE = "https://raw.githubusercontent.com/common-workflow-language/cwl-utils/main/testdata/md5sum.cwl"
1818
TEST_v1_2_CWL = HERE / "../testdata/workflow_input_format_expr_v1_2.cwl"
19+
yaml = YAML(typ="rt")
20+
yaml.preserve_quotes = True # type: ignore[assignment]
1921

2022

2123
def test_cwl_version() -> None:
2224
"""Test cwl_version for a CommandLineTool."""
2325
with open(TEST_v1_0_CWL) as cwl_h:
24-
yaml_obj = yaml.main.round_trip_load(cwl_h, preserve_quotes=True)
26+
yaml_obj = yaml.load(cwl_h)
2527
ver = cwl_version(yaml_obj)
2628
assert ver == "v1.0"
2729

2830

2931
def test_load_document() -> None:
3032
"""Test load_document for a CommandLineTool."""
3133
with open(TEST_v1_0_CWL) as cwl_h:
32-
yaml_obj = yaml.main.round_trip_load(cwl_h, preserve_quotes=True)
34+
yaml_obj = yaml.load(cwl_h)
3335
cwl_obj = load_document(yaml_obj)
3436
assert cwl_obj.cwlVersion == "v1.0"
3537
assert cwl_obj.inputs[0].id.endswith("input_file")
@@ -54,12 +56,12 @@ def test_load_document_with_remote_uri() -> None:
5456
def test_save() -> None:
5557
"""Test save for a list of Process objects with different cwlVersions."""
5658
with open(TEST_v1_0_CWL) as cwl_h:
57-
yaml_obj10 = yaml.main.round_trip_load(cwl_h, preserve_quotes=True)
59+
yaml_obj10 = yaml.load(cwl_h)
5860
cwl_obj10 = load_document(yaml_obj10)
5961
assert cwl_obj10.cwlVersion == "v1.0"
6062

6163
with open(TEST_v1_2_CWL) as cwl_h:
62-
yaml_obj12 = yaml.main.round_trip_load(cwl_h, preserve_quotes=True)
64+
yaml_obj12 = yaml.load(cwl_h)
6365
cwl_obj12 = load_document(yaml_obj12)
6466
assert cwl_obj12.cwlVersion == "v1.2"
6567

@@ -72,8 +74,8 @@ def test_latest_parser() -> None:
7274
"""Test the `latest` parser is same as cwl_v1_2 (current latest) parser."""
7375
uri = Path(TEST_v1_2_CWL).as_uri()
7476
with open(TEST_v1_2_CWL) as cwl_h:
75-
yaml_obj12 = yaml.main.round_trip_load(cwl_h, preserve_quotes=True)
76-
latest_cwl_obj = latest.load_document_by_yaml(yaml_obj12, uri) # type: ignore
77+
yaml_obj12 = yaml.load(cwl_h)
78+
latest_cwl_obj = latest.load_document_by_yaml(yaml_obj12, uri)
7779
assert latest_cwl_obj.cwlVersion == "v1.2"
7880

7981

0 commit comments

Comments
 (0)