Skip to content

Commit 0a97ccd

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

File tree

4 files changed

+20
-160
lines changed

4 files changed

+20
-160
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.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ requires = [
1010
"cwl-utils>=0.32",
1111
"toml",
1212
"argcomplete>=1.12.0",
13-
"rich-argparse"
13+
"rich-argparse",
14+
"pydot >= 1.4.1"
1415
]
1516
build-backend = "setuptools.build_meta"
1617

tests/test_examples.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -995,8 +995,10 @@ def test_var_spool_cwl_checker3() -> None:
995995
def test_print_dot() -> None:
996996
# print Workflow
997997
cwl_path = get_data("tests/wf/three_step_color.cwl")
998-
expected_dot = pydot.graph_from_dot_data(
999-
"""
998+
expected_dot = cast(
999+
list[pydot.core.Dot],
1000+
pydot.graph_from_dot_data(
1001+
"""
10001002
digraph {{
10011003
graph [bgcolor="#eeeeee",
10021004
clusterrank=local,
@@ -1041,10 +1043,11 @@ def test_print_dot() -> None:
10411043
"command_line_tool" -> "file_output";
10421044
}}
10431045
""".format()
1046+
),
10441047
)[0]
10451048
stdout = StringIO()
10461049
assert main(["--debug", "--print-dot", cwl_path], stdout=stdout) == 0
1047-
computed_dot = pydot.graph_from_dot_data(stdout.getvalue())[0]
1050+
computed_dot = cast(list[pydot.core.Dot], pydot.graph_from_dot_data(stdout.getvalue()))[0]
10481051
computed_edges = sorted((source, target) for source, target in computed_dot.obj_dict["edges"])
10491052
expected_edges = sorted((source, target) for source, target in expected_dot.obj_dict["edges"])
10501053
assert computed_edges == expected_edges

0 commit comments

Comments
 (0)