Skip to content

Commit 1d14378

Browse files
committed
support Pydot versions before 3.0
1 parent 2291376 commit 1d14378

File tree

3 files changed

+19
-159
lines changed

3 files changed

+19
-159
lines changed

cwltool/cwlviewer.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77

88
import pydot
99
import rdflib
10+
from packaging.version import Version
11+
12+
if Version(pydot.__version__) > Version("3.0"):
13+
quote_id_if_necessary = pydot.quote_id_if_necessary
14+
else:
15+
quote_id_if_necessary = pydot.quote_if_necessary # type: ignore[attr-defined]
1016

1117

1218
def _get_inner_edges_query() -> str:
@@ -99,8 +105,8 @@ def _set_inner_edges(self) -> None:
99105
self._dot_graph.add_node(n)
100106
self._dot_graph.add_edge(
101107
pydot.Edge(
102-
pydot.quote_id_if_necessary(str(inner_edge_row["source_step"])),
103-
pydot.quote_id_if_necessary(str(inner_edge_row["target_step"])),
108+
quote_id_if_necessary(str(inner_edge_row["source_step"])),
109+
quote_id_if_necessary(str(inner_edge_row["target_step"])),
104110
)
105111
)
106112

@@ -130,8 +136,8 @@ def _set_input_edges(self) -> None:
130136
inputs_subgraph.add_node(n)
131137
self._dot_graph.add_edge(
132138
pydot.Edge(
133-
pydot.quote_id_if_necessary(str(input_row["input"])),
134-
pydot.quote_id_if_necessary(str(input_row["step"])),
139+
quote_id_if_necessary(str(input_row["input"])),
140+
quote_id_if_necessary(str(input_row["step"])),
135141
)
136142
)
137143

@@ -161,8 +167,8 @@ def _set_output_edges(self) -> None:
161167
outputs_graph.add_node(n)
162168
self._dot_graph.add_edge(
163169
pydot.Edge(
164-
pydot.quote_id_if_necessary(output_edge_row["step"]),
165-
pydot.quote_id_if_necessary(output_edge_row["output"]),
170+
quote_id_if_necessary(output_edge_row["step"]),
171+
quote_id_if_necessary(output_edge_row["output"]),
166172
)
167173
)
168174

mypy-stubs/pydot.pyi

Lines changed: 0 additions & 150 deletions
This file was deleted.

tests/test_examples.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import cwl_utils.expression as expr
1515
import pydot
16+
import pydot.core
1617
import pytest
1718
from cwl_utils.errors import JavascriptException
1819
from cwl_utils.sandboxjs import param_re
@@ -995,8 +996,10 @@ def test_var_spool_cwl_checker3() -> None:
995996
def test_print_dot() -> None:
996997
# print Workflow
997998
cwl_path = get_data("tests/wf/three_step_color.cwl")
998-
expected_dot = pydot.graph_from_dot_data(
999-
"""
999+
expected_dot = cast(
1000+
list[pydot.core.Dot],
1001+
pydot.graph_from_dot_data(
1002+
"""
10001003
digraph {{
10011004
graph [bgcolor="#eeeeee",
10021005
clusterrank=local,
@@ -1041,10 +1044,11 @@ def test_print_dot() -> None:
10411044
"command_line_tool" -> "file_output";
10421045
}}
10431046
""".format()
1047+
),
10441048
)[0]
10451049
stdout = StringIO()
10461050
assert main(["--debug", "--print-dot", cwl_path], stdout=stdout) == 0
1047-
computed_dot = pydot.graph_from_dot_data(stdout.getvalue())[0]
1051+
computed_dot = cast(list[pydot.core.Dot], pydot.graph_from_dot_data(stdout.getvalue()))[0]
10481052
computed_edges = sorted((source, target) for source, target in computed_dot.obj_dict["edges"])
10491053
expected_edges = sorted((source, target) for source, target in expected_dot.obj_dict["edges"])
10501054
assert computed_edges == expected_edges

0 commit comments

Comments
 (0)