Skip to content

Commit

Permalink
Fixup: rerun black
Browse files Browse the repository at this point in the history
  • Loading branch information
lkk7 committed Apr 14, 2024
1 parent 91d5f31 commit 3bcc027
Showing 1 changed file with 39 additions and 16 deletions.
55 changes: 39 additions & 16 deletions src/pydot/dot_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,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):
Expand All @@ -169,7 +171,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:
Expand All @@ -192,7 +196,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":
Expand All @@ -209,7 +215,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)
Expand Down Expand Up @@ -300,7 +308,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]
Expand All @@ -315,7 +325,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)
Expand Down Expand Up @@ -390,9 +402,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")

Expand All @@ -417,7 +429,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")

Expand All @@ -434,17 +448,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()))

Expand Down

0 comments on commit 3bcc027

Please sign in to comment.