Skip to content

Commit 9eeccee

Browse files
authored
MyPy stubs rename (#1699)
* rename our local type stubs dir & fix types As per python/mypy#13155 (comment) * upgrade minimum ruamel.yaml versions
1 parent 1c2cbfc commit 9eeccee

File tree

525 files changed

+3768
-5902
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

525 files changed

+3768
-5902
lines changed

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ venv3/
2828
# pycharm
2929
.idea/
3030

31-
# typshed repo
32-
typeshed/2and3/schema_salad
33-
typeshed/2and3/ruamel/yaml
34-
31+
# local stubs
32+
mypy-stubs/ruamel/yaml
3533

3634
#mypy
3735
.mypy_cache/

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ include MANIFEST.in
33
include LICENSE.txt
44
include *requirements.txt mypy.ini tox.ini
55
include gittaggers.py Makefile cwltool.py
6-
recursive-include typeshed *.pyi
6+
recursive-include mypy-stubs *.pyi *.py
77
include tests/*
88
include tests/tmp1/tmp2/tmp3/.gitkeep
99
include tests/tmp4/alpha/*

Makefile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ clean: check-python3 FORCE
9090

9191
# Linting and code style related targets
9292
## sorting imports using isort: https://github.com/timothycrosley/isort
93-
sort_imports: $(PYSOURCES)
93+
sort_imports: $(PYSOURCES) mypy-stubs
9494
isort $^
9595

9696
remove_unused_imports: $(PYSOURCES)
@@ -110,14 +110,14 @@ diff_pydocstyle_report: pydocstyle_report.txt
110110

111111
## codespell : check for common mispellings
112112
codespell:
113-
codespell -w $(shell git ls-files | grep -v cwltool/schemas | grep -v cwltool/jshint/ | grep -v typeshed)
113+
codespell -w $(shell git ls-files | grep -v cwltool/schemas | grep -v cwltool/jshint/ | grep -v mypy-stubs)
114114

115115
## format : check/fix all code indentation and formatting (runs black)
116116
format:
117-
black --exclude cwltool/schemas setup.py cwltool.py cwltool tests
117+
black --exclude cwltool/schemas setup.py cwltool.py cwltool tests mypy-stubs
118118

119119
format-check:
120-
black --diff --check --exclude cwltool/schemas setup.py cwltool.py cwltool tests
120+
black --diff --check --exclude cwltool/schemas setup.py cwltool.py cwltool tests mypy-stubs
121121

122122
## pylint : run static code analysis on Python code
123123
pylint: $(PYSOURCES)
@@ -177,14 +177,14 @@ mypy3: mypy
177177
mypy: $(filter-out setup.py gittagger.py,$(PYSOURCES))
178178
if ! test -f $(shell python -c 'import ruamel.yaml; import os.path; print(os.path.dirname(ruamel.yaml.__file__))')/py.typed ; \
179179
then \
180-
rm -Rf typeshed/ruamel/yaml ; \
180+
rm -Rf mypy-stubs/ruamel/yaml ; \
181181
ln -s $(shell python -c 'import ruamel.yaml; import os.path; print(os.path.dirname(ruamel.yaml.__file__))') \
182-
typeshed/ruamel/ ; \
182+
mypy-stubs/ruamel/ ; \
183183
fi # if minimally required ruamel.yaml version is 0.15.99 or greater, than the above can be removed
184-
MYPYPATH=$$MYPYPATH:typeshed mypy $^
184+
MYPYPATH=$$MYPYPATH:mypy-stubs mypy $^
185185

186186
mypyc: $(PYSOURCES)
187-
MYPYPATH=typeshed CWLTOOL_USE_MYPYC=1 pip install --verbose -e . \
187+
MYPYPATH=mypy-stubs CWLTOOL_USE_MYPYC=1 pip install --verbose -e . \
188188
&& pytest -rs -vv ${PYTEST_EXTRA}
189189

190190
shellcheck: FORCE

cwltool.Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ RUN pip install toml -rmypy-requirements.txt "$(grep ruamel requirements.txt)" \
99
"$(grep schema.salad requirements.txt)"
1010
# schema-salad is needed to be installed (this time as pure Python) for
1111
# cwltool + mypyc
12-
RUN CWLTOOL_USE_MYPYC=1 MYPYPATH=typeshed pip wheel --no-binary schema-salad --wheel-dir=/wheels .[deps]
12+
RUN CWLTOOL_USE_MYPYC=1 MYPYPATH=mypy-stubs pip wheel --no-binary schema-salad --wheel-dir=/wheels .[deps]
1313
RUN rm /wheels/schema_salad*
1414
RUN pip install black
15-
RUN SCHEMA_SALAD_USE_MYPYC=1 MYPYPATH=typeshed pip wheel --no-binary schema-salad \
15+
RUN SCHEMA_SALAD_USE_MYPYC=1 MYPYPATH=mypy-stubs pip wheel --no-binary schema-salad \
1616
$(grep schema.salad requirements.txt) black --wheel-dir=/wheels
1717
RUN pip install --force-reinstall --no-index --no-warn-script-location --root=/pythonroot/ /wheels/*.whl
1818
# --force-reinstall to install our new mypyc compiled schema-salad package

cwltool/cwlrdf.py

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import urllib
22
from codecs import StreamWriter
3-
from typing import Any, Dict, Optional, TextIO, Union, cast
3+
from typing import Any, Dict, Iterator, Optional, TextIO, Union, cast
44

55
from rdflib import Graph
6+
from rdflib.query import ResultRow
67
from ruamel.yaml.comments import CommentedMap
78
from schema_salad.jsonld_context import makerdf
89
from schema_salad.utils import ContextType
@@ -26,7 +27,7 @@ def printrdf(wflow: Process, ctx: ContextType, style: str) -> str:
2627
rdf = gather(wflow, ctx).serialize(format=style, encoding="utf-8")
2728
if not rdf:
2829
return ""
29-
return cast(str, rdf.decode("utf-8"))
30+
return rdf.decode("utf-8")
3031

3132

3233
def lastpart(uri: Any) -> str:
@@ -37,28 +38,34 @@ def lastpart(uri: Any) -> str:
3738

3839

3940
def dot_with_parameters(g: Graph, stdout: Union[TextIO, StreamWriter]) -> None:
40-
qres = g.query(
41-
"""SELECT ?step ?run ?runtype
41+
qres = cast(
42+
Iterator[ResultRow],
43+
g.query(
44+
"""SELECT ?step ?run ?runtype
4245
WHERE {
4346
?step cwl:run ?run .
4447
?run rdf:type ?runtype .
4548
}"""
46-
)
49+
),
50+
) # ResultRow because the query is of type SELECT
4751

4852
for step, run, _ in qres:
4953
stdout.write(
5054
'"%s" [label="%s"]\n'
5155
% (lastpart(step), f"{lastpart(step)} ({lastpart(run)})")
5256
)
5357

54-
qres = g.query(
55-
"""SELECT ?step ?inp ?source
58+
qres = cast(
59+
Iterator[ResultRow],
60+
g.query(
61+
"""SELECT ?step ?inp ?source
5662
WHERE {
5763
?wf Workflow:steps ?step .
5864
?step cwl:inputs ?inp .
5965
?inp cwl:source ?source .
6066
}"""
61-
)
67+
),
68+
) # ResultRow because the query is of type SELECT
6269

6370
for step, inp, source in qres:
6471
stdout.write('"%s" [shape=box]\n' % (lastpart(inp)))
@@ -69,41 +76,50 @@ def dot_with_parameters(g: Graph, stdout: Union[TextIO, StreamWriter]) -> None:
6976
'"{}" -> "{}" [label="{}"]\n'.format(lastpart(inp), lastpart(step), "")
7077
)
7178

72-
qres = g.query(
73-
"""SELECT ?step ?out
79+
qres = cast(
80+
Iterator[ResultRow],
81+
g.query(
82+
"""SELECT ?step ?out
7483
WHERE {
7584
?wf Workflow:steps ?step .
7685
?step cwl:outputs ?out .
7786
}"""
78-
)
87+
),
88+
) # ResultRow because the query is of type SELECT
7989

8090
for step, out in qres:
8191
stdout.write('"%s" [shape=box]\n' % (lastpart(out)))
8292
stdout.write(
8393
'"{}" -> "{}" [label="{}"]\n'.format(lastpart(step), lastpart(out), "")
8494
)
8595

86-
qres = g.query(
87-
"""SELECT ?out ?source
96+
qres = cast(
97+
Iterator[ResultRow],
98+
g.query(
99+
"""SELECT ?out ?source
88100
WHERE {
89101
?wf cwl:outputs ?out .
90102
?out cwl:source ?source .
91103
}"""
92-
)
104+
),
105+
) # ResultRow because the query is of type SELECT
93106

94107
for out, source in qres:
95108
stdout.write('"%s" [shape=octagon]\n' % (lastpart(out)))
96109
stdout.write(
97110
'"{}" -> "{}" [label="{}"]\n'.format(lastpart(source), lastpart(out), "")
98111
)
99112

100-
qres = g.query(
101-
"""SELECT ?inp
113+
qres = cast(
114+
Iterator[ResultRow],
115+
g.query(
116+
"""SELECT ?inp
102117
WHERE {
103118
?wf rdf:type cwl:Workflow .
104119
?wf cwl:inputs ?inp .
105120
}"""
106-
)
121+
),
122+
) # ResultRow because the query is of type SELECT
107123

108124
for (inp,) in qres:
109125
stdout.write('"%s" [shape=octagon]\n' % (lastpart(inp)))
@@ -116,27 +132,33 @@ def dot_without_parameters(g: Graph, stdout: Union[TextIO, StreamWriter]) -> Non
116132
stdout.write("compound=true\n")
117133

118134
subworkflows = set()
119-
qres = g.query(
120-
"""SELECT ?run
135+
qres = cast(
136+
Iterator[ResultRow],
137+
g.query(
138+
"""SELECT ?run
121139
WHERE {
122140
?wf rdf:type cwl:Workflow .
123141
?wf Workflow:steps ?step .
124142
?step cwl:run ?run .
125143
?run rdf:type cwl:Workflow .
126144
} ORDER BY ?wf"""
127-
)
145+
),
146+
) # ResultRow because the query is of type SELECT
128147
for (run,) in qres:
129148
subworkflows.add(run)
130149

131-
qres = g.query(
132-
"""SELECT ?wf ?step ?run ?runtype
150+
qres = cast(
151+
Iterator[ResultRow],
152+
g.query(
153+
"""SELECT ?wf ?step ?run ?runtype
133154
WHERE {
134155
?wf rdf:type cwl:Workflow .
135156
?wf Workflow:steps ?step .
136157
?step cwl:run ?run .
137158
?run rdf:type ?runtype .
138159
} ORDER BY ?wf"""
139-
)
160+
),
161+
) # ResultRow because the query is of type SELECT
140162

141163
currentwf = None # type: Optional[str]
142164
for wf, step, _run, runtype in qres:
@@ -164,8 +186,10 @@ def dot_without_parameters(g: Graph, stdout: Union[TextIO, StreamWriter]) -> Non
164186
if currentwf is not None:
165187
stdout.write("}\n")
166188

167-
qres = g.query(
168-
"""SELECT DISTINCT ?src ?sink ?srcrun ?sinkrun
189+
qres = cast(
190+
Iterator[ResultRow],
191+
g.query(
192+
"""SELECT DISTINCT ?src ?sink ?srcrun ?sinkrun
169193
WHERE {
170194
?wf1 Workflow:steps ?src .
171195
?wf2 Workflow:steps ?sink .
@@ -175,7 +199,8 @@ def dot_without_parameters(g: Graph, stdout: Union[TextIO, StreamWriter]) -> Non
175199
?src cwl:run ?srcrun .
176200
?sink cwl:run ?sinkrun .
177201
}"""
178-
)
202+
),
203+
) # ResultRow because the query is of type SELECT
179204

180205
for src, sink, srcrun, sinkrun in qres:
181206
attr = ""

cwltool/cwlviewer.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Visualize a CWL workflow."""
22
from pathlib import Path
3+
from typing import Iterator, List, cast
34
from urllib.parse import urlparse
45

56
import pydot
@@ -32,9 +33,12 @@ def _load_cwl_graph(self, rdf_description: str) -> rdflib.graph.Graph:
3233
def _set_inner_edges(self) -> None:
3334
with open(_get_inner_edges_query_path) as f:
3435
get_inner_edges_query = f.read()
35-
inner_edges = self._rdf_graph.query(
36-
get_inner_edges_query, initBindings={"root_graph": self._root_graph_uri}
37-
)
36+
inner_edges = cast(
37+
Iterator[rdflib.query.ResultRow],
38+
self._rdf_graph.query(
39+
get_inner_edges_query, initBindings={"root_graph": self._root_graph_uri}
40+
),
41+
) # ResultRow because the query is of type SELECT
3842
for inner_edge_row in inner_edges:
3943
source_label = (
4044
inner_edge_row["source_label"]
@@ -103,9 +107,12 @@ def _set_input_edges(self) -> None:
103107
inputs_subgraph.set("style", "dashed")
104108
inputs_subgraph.set("label", "Workflow Inputs")
105109

106-
input_edges = self._rdf_graph.query(
107-
get_input_edges_query, initBindings={"root_graph": self._root_graph_uri}
108-
)
110+
input_edges = cast(
111+
Iterator[rdflib.query.ResultRow],
112+
self._rdf_graph.query(
113+
get_input_edges_query, initBindings={"root_graph": self._root_graph_uri}
114+
),
115+
) # ResultRow because the query is of type SELECT
109116
for input_row in input_edges:
110117
n = pydot.Node(
111118
"",
@@ -130,9 +137,12 @@ def _set_output_edges(self) -> None:
130137
outputs_graph.set("style", "dashed")
131138
outputs_graph.set("label", "Workflow Outputs")
132139
outputs_graph.set("labelloc", "b")
133-
output_edges = self._rdf_graph.query(
134-
get_output_edges, initBindings={"root_graph": self._root_graph_uri}
135-
)
140+
output_edges = cast(
141+
Iterator[rdflib.query.ResultRow],
142+
self._rdf_graph.query(
143+
get_output_edges, initBindings={"root_graph": self._root_graph_uri}
144+
),
145+
) # ResultRow because the query is of type SELECT
136146
for output_edge_row in output_edges:
137147
n = pydot.Node(
138148
"",
@@ -150,11 +160,14 @@ def _set_output_edges(self) -> None:
150160
def _get_root_graph_uri(self) -> rdflib.URIRef:
151161
with open(_get_root_query_path) as f:
152162
get_root_query = f.read()
153-
root = list(
154-
self._rdf_graph.query(
155-
get_root_query,
156-
)
157-
)
163+
root = cast(
164+
List[rdflib.query.ResultRow],
165+
list(
166+
self._rdf_graph.query(
167+
get_root_query,
168+
)
169+
),
170+
) # ResultRow because the query is of type SELECT
158171
if len(root) != 1:
159172
raise RuntimeError(
160173
"Cannot identify root workflow! Notice that only Workflows can be visualized"

0 commit comments

Comments
 (0)