From 5260faad98640d271ac83390eb28a3d07990eea2 Mon Sep 17 00:00:00 2001 From: Tobias Falk Date: Sun, 16 Jun 2024 14:32:41 +0200 Subject: [PATCH] Added executable chack --- docs/syntax.md | 9 +-------- src/wireviz/DataClasses.py | 25 ++++++++++++------------- src/wireviz/Harness.py | 11 ++++++++--- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/docs/syntax.md b/docs/syntax.md index 8d77e88..8e7b8c4 100644 --- a/docs/syntax.md +++ b/docs/syntax.md @@ -87,14 +87,7 @@ tweak: # optional tweaking of .gv output # on the connector that are to be shorted # shorts - shorts: - : - pins: - color: # optional - manufacturer: # optional - mpn: # optional - description: # optional - type: # optional, default is internal + shorts: ``` ## Cable attributes diff --git a/src/wireviz/DataClasses.py b/src/wireviz/DataClasses.py index 600bc34..45e4ae1 100644 --- a/src/wireviz/DataClasses.py +++ b/src/wireviz/DataClasses.py @@ -18,7 +18,7 @@ MultilineHypertext = ( Designator = PlainText # Case insensitive unique name of connector or cable # Literal type aliases below are commented to avoid requiring python 3.8 -ConnectorMultiplier = PlainText # = Literal['pincount', 'populated', 'unpopulated', 'shorts'] +ConnectorMultiplier = PlainText # = Literal['pincount', 'populated', 'unpopulated'] CableMultiplier = ( PlainText # = Literal['wirecount', 'terminations', 'length', 'total_length'] ) @@ -207,18 +207,17 @@ class Connector: # hide pincount for simple (1 pin) connectors by default self.show_pincount = self.style != "simple" - # for loop in self.loops: - # # TODO: allow using pin labels in addition to pin numbers, just like when defining regular connections - # # TODO: include properties of wire used to create the loop - # if len(loop) != 2: - # raise Exception("Loops must be between exactly two pins!") - # for pin in loop: - # if pin not in self.pins: - # raise Exception( - # f'Unknown loop pin "{pin}" for connector "{self.name}"!' - # ) - # # Make sure loop connected pins are not hidden. - # self.activate_pin(pin, None) + for loop in self.loops: + # TODO: allow using pin labels in addition to pin numbers, just like when defining regular connections + # TODO: include properties of wire used to create the loop + for loopName in loop: + for pin in loop[loopName]: + if pin not in self.pins: + raise Exception( + f'Unknown loop pin "{pin}" for connector "{self.name}"!' + ) + # Make sure loop connected pins are not hidden. + self.activate_pin(pin, None) for i, item in enumerate(self.additional_components): if isinstance(item, dict): diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index e082e48..44d844c 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -8,6 +8,7 @@ from itertools import zip_longest from pathlib import Path from typing import Any, List, Union from dataclasses import asdict +from distutils.spawn import find_executable from graphviz import Graph @@ -731,9 +732,13 @@ class Harness: # This renders the graph with gvpr and neato, this is needed to be able to draw the stright lines for the jumpers def graphRender(self, type, filename, graph): - graph.save(filename=f"{filename}_tmp.gv") - os.system(f"dot {filename}_tmp.gv | gvpr -q -cf pin2pin.gvpr | neato -n2 -T{type} -o {filename}.{type}") - os.remove(f"{filename}_tmp.gv") + + if find_executable("dot") and find_executable("gvpr") and find_executable("neato"): + graph.save(filename=f"{filename}_tmp.gv") + os.system(f"dot {filename}_tmp.gv | gvpr -q -cf pin2pin.gvpr | neato -n2 -T{type} -o {filename}.{type}") + os.remove(f"{filename}_tmp.gv") + else: + graph.render(filename=filename) # old rendering methode, befor jumper implementations @property def graph(self):