Make wireviz an installable package.

This commit is contained in:
Morgan 2020-06-24 22:03:03 +02:00
parent e8318c3286
commit 7663f2b832
13 changed files with 217 additions and 119 deletions

1
AUTHORS Normal file
View File

@ -0,0 +1 @@
Daniel Rojas <github@danielrojas.net>

0
CHANGES Normal file
View File

1
MANIFEST.in Normal file
View File

@ -0,0 +1 @@
include AUTHORS CHANGES LICENSE README.rst requirements.txt

147
README.rst Normal file
View File

@ -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 <examples/demo02.bom.tsv>`__
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

105
readme.md
View File

@ -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

2
src/batch.py → scripts/batch Normal file → Executable file
View File

@ -1,3 +1,5 @@
#!/usr/bin/env python3
import wireviz import wireviz
import os import os

16
scripts/wirewiz Executable file
View File

@ -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)

38
setup.py Normal file
View File

@ -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',
]
)

6
wireviz/__init__.py Normal file
View File

@ -0,0 +1,6 @@
# Copyright 2020 Daniel Rojas. All Rights Reserved.
from wireviz.core import parse
__all__ = 'parse',

20
src/wireviz.py → wireviz/core.py Executable file → Normal file
View File

@ -1,13 +1,15 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os import os
from dataclasses import dataclass, field from dataclasses import dataclass, field
from typing import Any, List from typing import Any, List
from collections import Counter from collections import Counter
import yaml
from graphviz import Graph
import wv_colors from graphviz import Graph
from wv_helper import nested, int2tuple, awg_equiv, flatten2d, tuplelist2tsv import yaml
import wireviz.colors as wv_colors
from wireviz.helper import nested, int2tuple, awg_equiv, flatten2d, tuplelist2tsv
class Harness: class Harness:
@ -594,13 +596,3 @@ def parse(file_in, file_out=None, gen_bom=False):
raise Exception('Wrong number of connection parameters') raise Exception('Wrong number of connection parameters')
h.output(filename=file_out, format=('png','svg'), gen_bom=gen_bom, view=False) 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)