Skip to content

Commit

Permalink
ruff autofix
Browse files Browse the repository at this point in the history
  • Loading branch information
hbmartin committed Jul 3, 2024
1 parent 7b3bbc6 commit 9ce3fb2
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 36 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ python -m graphviz2drawio test/directed/hello.gv.txt
- [ ] Implementation for outstanding TODOs in code
- [ ] Image / tooltip support #49
- [ ] Text on edge alignment #59
- [ ] Support for node with `path` shape #47

## Roadmap to 1.0
- [ ] Complete test suite for official graphviz examples
Expand Down
3 changes: 1 addition & 2 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
Expand Down Expand Up @@ -142,7 +141,7 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, "graphviz2drawio", "Graphviz2drawio Documentation", [author], 1)
(master_doc, "graphviz2drawio", "Graphviz2drawio Documentation", [author], 1),
]


Expand Down
3 changes: 2 additions & 1 deletion graphviz2drawio/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from sys import stderr

from .graphviz2drawio import convert
from .models import Arguments
from .version import __version__
Expand All @@ -17,7 +18,7 @@ def main():
except BaseException:
stderr.write("Something went wrong, please report\n")
stderr.write(
"An automatic crash report can be sent to the developer (no personal or graph information)\n"
"An automatic crash report can be sent to the developer (no personal or graph information)\n",
)
permission = input("Type 'no' to cancel report, press enter to send: ")
if permission != "no":
Expand Down
2 changes: 1 addition & 1 deletion graphviz2drawio/graphviz2drawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def convert(graph_to_convert, layout_prog="dot"):
graph = AGraph(graph_to_convert)
except BaseException as e:
raise ValueError(
"graph_to_convert must be one of a string, file, or AGraph object"
"graph_to_convert must be one of a string, file, or AGraph object",
) from e

graph_edges = {
Expand Down
2 changes: 1 addition & 1 deletion graphviz2drawio/models/Arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(self, version):
self.add_argument(
"--version",
action="version",
version="%(prog)s {version}".format(version=version),
version=f"%(prog)s {version}",
)
self.add_argument(
"-p",
Expand Down
6 changes: 4 additions & 2 deletions graphviz2drawio/models/SvgParser.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from collections import OrderedDict
from xml.etree import ElementTree

from graphviz2drawio.mx.EdgeFactory import EdgeFactory
from graphviz2drawio.mx.NodeFactory import NodeFactory
from . import SVG
from .CoordsTranslate import CoordsTranslate

from ..mx.Edge import Edge
from ..mx.Node import Node
from . import SVG
from .CoordsTranslate import CoordsTranslate


def parse_nodes_edges_clusters(
Expand Down
9 changes: 3 additions & 6 deletions graphviz2drawio/mx/Curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@ def __str__(self):

@staticmethod
def is_linear(points, threshold=linear_min_r2):
"""
Returns a boolean indicating whether a list of complex points is linear.
"""Returns a boolean indicating whether a list of complex points is linear.
Takes a list of complex points and optional minimum R**2 threshold for linear regression.
"""
r2 = LinearRegression.coefficients(points)[2]
return r2 > threshold

def cubic_bezier_coordinates(self, t):
"""
Returns a complex number representing the point along the cubic bezier curve.
"""Returns a complex number representing the point along the cubic bezier curve.
Takes parametric parameter t where 0 <= t <= 1
"""
Expand All @@ -41,8 +39,7 @@ def _cb(self, prop):

@staticmethod
def _cubic_bezier(p, t):
"""
Returns a float representing the point along the cubic bezier curve in the given dimension.
"""Returns a float representing the point along the cubic bezier curve in the given dimension.
Takes ordered list of 4 control points [P0, P1, P2, P3] and parametric parameter t where 0 <= t <= 1
Expand Down
11 changes: 6 additions & 5 deletions graphviz2drawio/mx/CurveFactory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from svg.path import CubicBezier, Move
from svg.path import parse_path
from svg.path import CubicBezier, Move, parse_path

from .Curve import Curve


Expand All @@ -23,13 +23,14 @@ def from_svg(self, svg_path) -> Curve:
cb = [self.coords.complex_translate(p) for p in points]

if len(path) > 1: # set of curves/points
for r in range(0, len(path)):
for r in range(len(path)):
cbset.append(
(
self.coords.translate(
path[r].start.real, path[r].start.imag
path[r].start.real,
path[r].start.imag,
),
self.coords.translate(path[r].end.real, path[r].end.imag),
)
),
)
return Curve(start=start, end=end, cb=cb, cbset=cbset)
1 change: 1 addition & 0 deletions graphviz2drawio/mx/Edge.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from graphviz2drawio.models import DotAttr

from .Curve import Curve
from .GraphObj import GraphObj

Expand Down
1 change: 1 addition & 0 deletions graphviz2drawio/mx/EdgeFactory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from graphviz2drawio.models import SVG

from .CurveFactory import CurveFactory
from .Edge import Edge

Expand Down
7 changes: 5 additions & 2 deletions graphviz2drawio/mx/MxGraph.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import uuid
from xml.etree import ElementTree as ET

from graphviz2drawio.models import DotAttr
from graphviz2drawio.mx import MxConst
from graphviz2drawio.mx.Styles import Styles
import uuid


class MxGraph:
Expand Down Expand Up @@ -133,7 +133,10 @@ def add_mx_geo_with_points(element, curve):
ET.SubElement(array, MxConst.POINT, x=str(cb[0][0]), y=str(cb[0][1]))
if cb:
ET.SubElement(
array, MxConst.POINT, x=str(cb[1][0]), y=str(cb[1][1])
array,
MxConst.POINT,
x=str(cb[1][0]),
y=str(cb[1][1]),
)

# TODO: needs to account for multiple bezier in path
Expand Down
5 changes: 3 additions & 2 deletions graphviz2drawio/mx/NodeFactory.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from graphviz2drawio.models import SVG
from graphviz2drawio.models.Rect import Rect

from . import Shape
from .Node import Node
from .Text import Text
from . import Shape


class NodeFactory:
Expand Down Expand Up @@ -55,7 +56,7 @@ def from_svg(self, g) -> Node:

if SVG.has(g, "polygon"):
rect = self.rect_from_svg_points(
SVG.get_first(g, "polygon").attrib["points"]
SVG.get_first(g, "polygon").attrib["points"],
)
shape = Shape.RECT
else:
Expand Down
1 change: 1 addition & 0 deletions graphviz2drawio/mx/Styles.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from enum import Enum

from . import Shape


Expand Down
1 change: 1 addition & 0 deletions graphviz2drawio/mx/Text.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from graphviz2drawio.models import DotAttr
from graphviz2drawio.mx import MxConst

from .Styles import Styles


Expand Down
30 changes: 16 additions & 14 deletions test/test_graphs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from graphviz2drawio import graphviz2drawio
import xml.etree.ElementTree as ET
import re
import html
import re
import xml.etree.ElementTree as ET

from graphviz2drawio import graphviz2drawio

num_cells_offset = 2

Expand Down Expand Up @@ -145,24 +146,25 @@ def test_datastruct():
assert elements[-1].attrib["target"] == "node2"


# TODO: https://github.com/hbmartin/graphviz2drawio/issues/33
# def test_subgraph():
# file = "test/directed/subgraph.gv.txt"
# xml = graphviz2drawio.convert(file)
# print(xml)
#
# root = ET.fromstring(xml)
# elements = check_xml_top(root)


def test_compound():
file = "test/directed/compound.gv.txt"
xml = graphviz2drawio.convert(file)
print(xml)

root = ET.fromstring(xml)
elements = check_xml_top(root)
assert elements[-1].attrib["target"] == "node7"
assert elements[2].attrib["id"] == "clust1"
assert elements[3].attrib["id"] == "clust2"


# TODO: https://github.com/hbmartin/graphviz2drawio/issues/33
# def test_subgraph():
# file = "test/directed/subgraph.gv.txt"
# xml = graphviz2drawio.convert(file)
# print(xml)
#
# root = ET.fromstring(xml)
# elements = check_xml_top(root


# def test_runAll():
Expand Down

0 comments on commit 9ce3fb2

Please sign in to comment.