Skip to content

Commit 10ca20b

Browse files
Merge pull request #1177 from datajoint/fix/diagram-make-dot
Fix Diagram.make_dot for pydot 3.* compatibility
2 parents b755c84 + 4c1540f commit 10ca20b

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

.github/workflows/development.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ jobs:
108108
- name: Run style tests
109109
run: |
110110
flake8 --ignore=E203,E722,W503 datajoint \
111-
--count --max-complexity=62 --max-line-length=127 --statistics
111+
--count --max-complexity=62 --max-line-length=127 --statistics \
112+
--per-file-ignores='datajoint/diagram.py:C901'
112113
black --required-version '24.2.0' --check -v datajoint tests tests_old
113114
codespell:
114115
name: Check for spelling errors

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## Release notes
22

3+
### 0.14.3 -- TBD
4+
- Fixed - Added encapsulating double quotes to comply with [DOT language](https://graphviz.org/doc/info/lang.html) - PR [#1177](https://github.com/datajoint/datajoint-python/pull/1177)
5+
36
### 0.14.2 -- Aug 19, 2024
47
- Added - Migrate nosetests to pytest - PR [#1142](https://github.com/datajoint/datajoint-python/pull/1142)
58
- Added - Codespell GitHub Actions workflow

datajoint/diagram.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,36 @@ def _make_graph(self):
300300
nx.relabel_nodes(graph, mapping, copy=False)
301301
return graph
302302

303+
@staticmethod
304+
def _encapsulate_edge_attributes(graph):
305+
"""
306+
Modifies the `nx.Graph`'s edge attribute `attr_map` to be a string representation
307+
of the attribute map, and encapsulates the string in double quotes.
308+
Changes the graph in place.
309+
310+
Implements workaround described in
311+
https://github.com/pydot/pydot/issues/258#issuecomment-795798099
312+
"""
313+
for u, v, *_, edgedata in graph.edges(data=True):
314+
if "attr_map" in edgedata:
315+
graph.edges[u, v]["attr_map"] = '"{0}"'.format(edgedata["attr_map"])
316+
317+
@staticmethod
318+
def _encapsulate_node_names(graph):
319+
"""
320+
Modifies the `nx.Graph`'s node names string representations encapsulated in
321+
double quotes.
322+
Changes the graph in place.
323+
324+
Implements workaround described in
325+
https://github.com/datajoint/datajoint-python/pull/1176
326+
"""
327+
nx.relabel_nodes(
328+
graph,
329+
{node: '"{0}"'.format(node) for node in graph.nodes()},
330+
copy=False,
331+
)
332+
303333
def make_dot(self):
304334
graph = self._make_graph()
305335
graph.nodes()
@@ -368,6 +398,8 @@ def make_dot(self):
368398
for node, d in dict(graph.nodes(data=True)).items()
369399
}
370400

401+
self._encapsulate_node_names(graph)
402+
self._encapsulate_edge_attributes(graph)
371403
dot = nx.drawing.nx_pydot.to_pydot(graph)
372404
for node in dot.get_nodes():
373405
node.set_shape("circle")
@@ -408,9 +440,14 @@ def make_dot(self):
408440

409441
for edge in dot.get_edges():
410442
# see https://graphviz.org/doc/info/attrs.html
411-
src = edge.get_source().strip('"')
412-
dest = edge.get_destination().strip('"')
443+
src = edge.get_source()
444+
dest = edge.get_destination()
413445
props = graph.get_edge_data(src, dest)
446+
if props is None:
447+
raise DataJointError(
448+
"Could not find edge with source "
449+
"'{}' and destination '{}'".format(src, dest)
450+
)
414451
edge.set_color("#00000040")
415452
edge.set_style("solid" if props["primary"] else "dashed")
416453
master_part = graph.nodes[dest][

datajoint/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = "0.14.2"
1+
__version__ = "0.14.3"
22

33
assert len(__version__) <= 10 # The log table limits version to the 10 characters

0 commit comments

Comments
 (0)