From 7663f2b832ff4a5e8cec115d1bfd63b7664aea76 Mon Sep 17 00:00:00 2001 From: Morgan Date: Wed, 24 Jun 2020 22:03:03 +0200 Subject: [PATCH] Make wireviz an installable package. --- AUTHORS | 1 + CHANGES | 0 LICENSE.txt => LICENSE | 0 MANIFEST.in | 1 + README.rst | 147 ++++++++++++++++++++++++++ readme.md | 105 ------------------ src/batch.py => scripts/batch | 2 + scripts/wirewiz | 16 +++ setup.py | 38 +++++++ wireviz/__init__.py | 6 ++ src/wv_colors.py => wireviz/colors.py | 0 src/wireviz.py => wireviz/core.py | 20 ++-- src/wv_helper.py => wireviz/helper.py | 0 13 files changed, 217 insertions(+), 119 deletions(-) create mode 100644 AUTHORS create mode 100644 CHANGES rename LICENSE.txt => LICENSE (100%) create mode 100644 MANIFEST.in create mode 100644 README.rst delete mode 100644 readme.md rename src/batch.py => scripts/batch (98%) mode change 100644 => 100755 create mode 100755 scripts/wirewiz create mode 100644 setup.py create mode 100644 wireviz/__init__.py rename src/wv_colors.py => wireviz/colors.py (100%) rename src/wireviz.py => wireviz/core.py (98%) mode change 100755 => 100644 rename src/wv_helper.py => wireviz/helper.py (100%) diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..0340870 --- /dev/null +++ b/AUTHORS @@ -0,0 +1 @@ +Daniel Rojas diff --git a/CHANGES b/CHANGES new file mode 100644 index 0000000..e69de29 diff --git a/LICENSE.txt b/LICENSE similarity index 100% rename from LICENSE.txt rename to LICENSE diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..4c57218 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include AUTHORS CHANGES LICENSE README.rst requirements.txt diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..7c7b30c --- /dev/null +++ b/README.rst @@ -0,0 +1,147 @@ +WireViz +======= + +Summary +------- + +WireViz is a tool for easily documenting cables, wiring harnesses and +connector pinouts. It takes plain text, YAML-formatted files as input +and produces beautiful graphical output (SVG, PNG, …) thanks to +`GraphViz`_. It handles automatic BOM (Bill of Materials) creation and +has a lot of extra features. + +Features +-------- + +- WireViz input files are fully text based + + - No special editor required + - Human readable + - Easy version control + - YAML syntax + +- Understands and uses color abbreviations as per `IEC 60757`_ + (black=BK, red=RD, …) + + - Optionally outputs colors as abbreviation (e.g. ‘YE’), full name + (e.g. ‘yellow’) or hex value (e.g. ‘#ffff00’), with choice of + UPPER or lower case + +- Auto-generates standard wire color schemes and allows custom ones if + needed + + - `DIN 47100`_ (WT/BN/GN/YE/GY/PK/BU/RD/BK/VT/…) + - `IEC 62`_ (BN/RD/OR/YE/GN/BU/VT/GY/WT/BK/…) + +- Understands wire gauge in mm² or AWG + + - Optionally auto-calculates and displays AWG equivalent when + specifying mm² + +- Allows more than one connector per side, as well as loopbacks +- Allows for easy-autorouting for 1-to-1 wiring +- Generates BOM (Bill of Materials) + +*Note*: WireViz is not designed to represent the complete wiring of a +system. Its main aim is to document the construction of individual wires +and harnesses. + +Examples +-------- + +Demo 01 +~~~~~~~ + +`WireViz input file`_: + +.. code:: yaml + + connectors: + X1: + type: D-Sub + subtype: female + pinout: [DCD, RX, TX, DTR, GND, DSR, RTS, CTS, RI] + X2: + type: Molex KK 254 + subtype: female + pinout: [GND, RX, TX] + + cables: + W1: + gauge: 0.25 mm2 + length: 0.2 + color_code: DIN + wirecount: 3 + shield: true + + connections: + - + - X1: [5,2,1] + - W1: [1,2,3] + - X2: [1,3,2] + - + - X1: 5 + - W1: s + +Output file: + +.. figure:: examples/demo01.png + :alt: Sample output diagram + + Sample output diagram + +`Bill of Materials`_ (auto-generated) + +Demo 02 +~~~~~~~ + +|image0| + +`Source`_ - `Bill of Materials `__ + +Tutorial and example gallery +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +See the `tutorial page`_ for sample code, as well as the `example +gallery`_ to see more of what WireViz can do. + +Usage +----- + +:: + + $ python3 wireviz.py ~/path/to/file/mywire.yml + +This will output the following files + +:: + + mywire.gv GraphViz output + mywire.svg Wiring diagram as vector image + mywire.png Wiring diagram as raster image + mywire.bom.tsv BOM (bill of materials) as tab-separated text file + mywire.html HTML page with wiring diagram and BOM embedded + +Status +------ + +This is very much a `work in progress`_. Source code, API, syntax and +functionality may change wildly at any time. + +Requirements +------------ + +Developed and tested using Python 3.7; mi + +.. _GraphViz: https://www.graphviz.org/ +.. _IEC 60757: https://en.wikipedia.org/wiki/Electronic_color_code#Color_band_system +.. _DIN 47100: https://en.wikipedia.org/wiki/DIN_47100 +.. _IEC 62: https://en.wikipedia.org/wiki/Electronic_color_code#Color_band_system +.. _WireViz input file: examples/demo01.yml +.. _Bill of Materials: examples/demo01.bom.tsv +.. _Source: examples/demo02.yml +.. _tutorial page: tutorial/readme.md +.. _example gallery: examples/readme.md +.. _work in progress: todo.md + +.. |image0| image:: examples/demo02.png diff --git a/readme.md b/readme.md deleted file mode 100644 index bca9684..0000000 --- a/readme.md +++ /dev/null @@ -1,105 +0,0 @@ -# WireViz - -## Summary - -WireViz is a tool for easily documenting cables, wiring harnesses and connector pinouts. It takes plain text, YAML-formatted files as input and produces beautiful graphical output (SVG, PNG, ...) thanks to [GraphViz](https://www.graphviz.org/). It handles automatic BOM (Bill of Materials) creation and has a lot of extra features. - -## Features - -* WireViz input files are fully text based - * No special editor required - * Human readable - * Easy version control - * YAML syntax -* Understands and uses color abbreviations as per [IEC 60757](https://en.wikipedia.org/wiki/Electronic_color_code#Color_band_system) (black=BK, red=RD, ...) - * Optionally outputs colors as abbreviation (e.g. 'YE'), full name (e.g. 'yellow') or hex value (e.g. '#ffff00'), with choice of UPPER or lower case -* Auto-generates standard wire color schemes and allows custom ones if needed - * [DIN 47100](https://en.wikipedia.org/wiki/DIN_47100) (WT/BN/GN/YE/GY/PK/BU/RD/BK/VT/...) - * [IEC 62](https://en.wikipedia.org/wiki/Electronic_color_code#Color_band_system) (BN/RD/OR/YE/GN/BU/VT/GY/WT/BK/...) -* Understands wire gauge in mm² or AWG - * Optionally auto-calculates and displays AWG equivalent when specifying mm² -* Allows more than one connector per side, as well as loopbacks -* Allows for easy-autorouting for 1-to-1 wiring -* Generates BOM (Bill of Materials) - -_Note_: WireViz is not designed to represent the complete wiring of a system. Its main aim is to document the construction of individual wires and harnesses. - -## Examples - -### Demo 01 - -[WireViz input file](examples/demo01.yml): - -```yaml -connectors: - X1: - type: D-Sub - subtype: female - pinout: [DCD, RX, TX, DTR, GND, DSR, RTS, CTS, RI] - X2: - type: Molex KK 254 - subtype: female - pinout: [GND, RX, TX] - -cables: - W1: - gauge: 0.25 mm2 - length: 0.2 - color_code: DIN - wirecount: 3 - shield: true - -connections: - - - - X1: [5,2,1] - - W1: [1,2,3] - - X2: [1,3,2] - - - - X1: 5 - - W1: s -``` - -Output file: - -![Sample output diagram](examples/demo01.png) - -[Bill of Materials](examples/demo01.bom.tsv) (auto-generated) - -### Demo 02 - -![](examples/demo02.png) - -[Source](examples/demo02.yml) - [Bill of Materials](examples/demo02.bom.tsv) - -### Tutorial and example gallery - -See the [tutorial page](tutorial/readme.md) for sample code, -as well as the [example gallery](examples/readme.md) to see more of what WireViz can do. - -## Usage - -``` -$ python3 wireviz.py ~/path/to/file/mywire.yml -``` - -This will output the following files - -``` -mywire.gv GraphViz output -mywire.svg Wiring diagram as vector image -mywire.png Wiring diagram as raster image -mywire.bom.tsv BOM (bill of materials) as tab-separated text file -mywire.html HTML page with wiring diagram and BOM embedded -``` - -## Status - -This is very much a [work in progress](todo.md). Source code, API, syntax and functionality may change wildly at any time. - -## Requirements - -Developed and tested using Python 3.7; might not work with older Python versions. - -## License - -GNU GPLv3 diff --git a/src/batch.py b/scripts/batch old mode 100644 new mode 100755 similarity index 98% rename from src/batch.py rename to scripts/batch index 300cd84..1cbb826 --- a/src/batch.py +++ b/scripts/batch @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + import wireviz import os diff --git a/scripts/wirewiz b/scripts/wirewiz new file mode 100755 index 0000000..f9fbc09 --- /dev/null +++ b/scripts/wirewiz @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +"""Invoke wireviz from the command line.""" + +import argparse + +import wireviz + + +if __name__ == '__main__': + ap = argparse.ArgumentParser() + ap.add_argument('file_input', nargs='?', default='_test/test.yml') + ap.add_argument('file_output', nargs='?', default=None) + ap.add_argument('--bom', action='store_const', default=True, const=True) + args = ap.parse_args() + + wireviz.parse(args.file_input, file_out=args.file_output, gen_bom=args.bom) diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..2558c36 --- /dev/null +++ b/setup.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +"""WireViz is a tool for easily documenting wiring harnesses.""" + + +from setuptools import setup, find_packages + + +setup( + + name='wireviz', + version='0.0.2', + + author='Daniel Rojas', + author_email='github@danielrojas.net', + maintainer='Daniel Rojas', + maintainer_email='github@danielrojas.net', + + url='', + description=__doc__, + long_description=open('README.rst').read(), + install_requires=open('requirements.txt').read().splitlines(), + + packages=find_packages(), + include_package_data=True, + zip_safe=False, + scripts=[ + 'scripts/wirewiz', + ], + + license='GPL', + platforms='any', + classifiers=[ + 'Development Status :: 4 - Beta', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3', + ] + +) diff --git a/wireviz/__init__.py b/wireviz/__init__.py new file mode 100644 index 0000000..21e1bcc --- /dev/null +++ b/wireviz/__init__.py @@ -0,0 +1,6 @@ +# Copyright 2020 Daniel Rojas. All Rights Reserved. + +from wireviz.core import parse + + +__all__ = 'parse', diff --git a/src/wv_colors.py b/wireviz/colors.py similarity index 100% rename from src/wv_colors.py rename to wireviz/colors.py diff --git a/src/wireviz.py b/wireviz/core.py old mode 100755 new mode 100644 similarity index 98% rename from src/wireviz.py rename to wireviz/core.py index afe825d..f2c81d7 --- a/src/wireviz.py +++ b/wireviz/core.py @@ -1,13 +1,15 @@ #!/usr/bin/env python3 import os + from dataclasses import dataclass, field from typing import Any, List from collections import Counter -import yaml -from graphviz import Graph -import wv_colors -from wv_helper import nested, int2tuple, awg_equiv, flatten2d, tuplelist2tsv +from graphviz import Graph +import yaml + +import wireviz.colors as wv_colors +from wireviz.helper import nested, int2tuple, awg_equiv, flatten2d, tuplelist2tsv class Harness: @@ -594,13 +596,3 @@ def parse(file_in, file_out=None, gen_bom=False): raise Exception('Wrong number of connection parameters') h.output(filename=file_out, format=('png','svg'), gen_bom=gen_bom, view=False) - -if __name__ == '__main__': - import argparse - ap = argparse.ArgumentParser() - ap.add_argument('file_input', nargs='?', default='_test/test.yml') - ap.add_argument('file_output', nargs='?', default=None) - ap.add_argument('--bom', action='store_const', default=True, const=True) - args = ap.parse_args() - - parse(args.file_input, file_out=args.file_output, gen_bom=args.bom) diff --git a/src/wv_helper.py b/wireviz/helper.py similarity index 100% rename from src/wv_helper.py rename to wireviz/helper.py