forked from pydot/pydot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
43 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,6 @@ dev = [ | |
] | ||
tests = [ | ||
'chardet', | ||
'black', | ||
'tox', | ||
'parameterized', | ||
'unittest-parallel', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
Author: Michael Krause <[email protected]> | ||
Fixes by: Ero Carrera <[email protected]> | ||
""" | ||
|
||
import logging | ||
|
||
from pyparsing import ( | ||
|
@@ -159,7 +160,9 @@ def update_parent_graph_hierarchy(g, parent_graph=None, level=0): | |
if vertex["parent_graph"] is g: | ||
pass | ||
else: | ||
vertex["parent_graph"].set_parent_graph(parent_graph) | ||
vertex["parent_graph"].set_parent_graph( | ||
parent_graph | ||
) | ||
|
||
|
||
def add_defaults(element, defaults): | ||
|
@@ -169,7 +172,9 @@ def add_defaults(element, defaults): | |
d[key] = value | ||
|
||
|
||
def add_elements(g, toks, defaults_graph=None, defaults_node=None, defaults_edge=None): | ||
def add_elements( | ||
g, toks, defaults_graph=None, defaults_node=None, defaults_edge=None | ||
): | ||
if defaults_graph is None: | ||
defaults_graph = {} | ||
if defaults_node is None: | ||
|
@@ -192,7 +197,9 @@ def add_elements(g, toks, defaults_graph=None, defaults_node=None, defaults_edge | |
|
||
elif isinstance(element, ParseResults): | ||
for e in element: | ||
add_elements(g, [e], defaults_graph, defaults_node, defaults_edge) | ||
add_elements( | ||
g, [e], defaults_graph, defaults_node, defaults_edge | ||
) | ||
|
||
elif isinstance(element, DefaultStatement): | ||
if element.default_type == "graph": | ||
|
@@ -209,7 +216,9 @@ def add_elements(g, toks, defaults_graph=None, defaults_node=None, defaults_edge | |
defaults_edge.update(element.attrs) | ||
|
||
else: | ||
raise ValueError(f"Unknown DefaultStatement: {element.default_type}") | ||
raise ValueError( | ||
f"Unknown DefaultStatement: {element.default_type}" | ||
) | ||
|
||
elif isinstance(element, P_AttrList): | ||
g.obj_dict["attributes"].update(element.attrs) | ||
|
@@ -300,7 +309,9 @@ def push_edge_stmt(s, loc, toks): | |
e.append(pydot.Edge(n_prev, n_next[0] + n_next_port, **attrs)) | ||
|
||
elif isinstance(toks[2][0], pydot.Graph): | ||
e.append(pydot.Edge(n_prev, pydot.frozendict(toks[2][0].obj_dict), **attrs)) | ||
e.append( | ||
pydot.Edge(n_prev, pydot.frozendict(toks[2][0].obj_dict), **attrs) | ||
) | ||
|
||
elif isinstance(toks[2][0], pydot.Node): | ||
node = toks[2][0] | ||
|
@@ -315,7 +326,9 @@ def push_edge_stmt(s, loc, toks): | |
# if the target of this edge is the name of a node | ||
elif isinstance(toks[2][0], str): | ||
for n_next in [n for n in tuple(toks)[2::2]]: | ||
if isinstance(n_next, P_AttrList) or not isinstance(n_next[0], str): | ||
if isinstance(n_next, P_AttrList) or not isinstance( | ||
n_next[0], str | ||
): | ||
continue | ||
|
||
n_next_port = do_node_ports(n_next) | ||
|
@@ -390,9 +403,9 @@ def graph_definition(): | |
|
||
ID = (identifier | html_text | double_quoted_string).setName("ID") | ||
|
||
float_number = Combine(Optional(minus) + OneOrMore(Word(nums + "."))).setName( | ||
"float_number" | ||
) | ||
float_number = Combine( | ||
Optional(minus) + OneOrMore(Word(nums + ".")) | ||
).setName("float_number") | ||
|
||
righthand_id = (float_number | ID).setName("righthand_id") | ||
|
||
|
@@ -417,7 +430,9 @@ def graph_definition(): | |
lbrack.suppress() + Optional(a_list) + rbrack.suppress() | ||
).setName("attr_list") | ||
|
||
attr_stmt = (Group(graph_ | node_ | edge_) + attr_list).setName("attr_stmt") | ||
attr_stmt = (Group(graph_ | node_ | edge_) + attr_list).setName( | ||
"attr_stmt" | ||
) | ||
|
||
edgeop = (Literal("--") | Literal("->")).setName("edgeop") | ||
|
||
|
@@ -434,17 +449,26 @@ def graph_definition(): | |
edgeRHS = OneOrMore(edgeop + edge_point) | ||
edge_stmt = edge_point + edgeRHS + Optional(attr_list) | ||
|
||
subgraph = Group(subgraph_ + Optional(ID) + graph_stmt).setName("subgraph") | ||
|
||
edge_point << Group(subgraph | graph_stmt | node_id).setName("edge_point") | ||
subgraph = Group(subgraph_ + Optional(ID) + graph_stmt).setName( | ||
"subgraph" | ||
) | ||
|
||
node_stmt = (node_id + Optional(attr_list) + Optional(semi.suppress())).setName( | ||
"node_stmt" | ||
edge_point << Group(subgraph | graph_stmt | node_id).setName( | ||
"edge_point" | ||
) | ||
|
||
node_stmt = ( | ||
node_id + Optional(attr_list) + Optional(semi.suppress()) | ||
).setName("node_stmt") | ||
|
||
assignment = (ID + equals + righthand_id).setName("assignment") | ||
stmt = ( | ||
assignment | edge_stmt | attr_stmt | subgraph | graph_stmt | node_stmt | ||
assignment | ||
| edge_stmt | ||
| attr_stmt | ||
| subgraph | ||
| graph_stmt | ||
| node_stmt | ||
).setName("stmt") | ||
stmt_list << OneOrMore(stmt + Optional(semi.suppress())) | ||
|
||
|