Compare commits

..

1 Commits

Author SHA1 Message Date
Liam Beguin
4d9346a365 Add jinja2 preprocessor stage
Some checks failed
Create Examples / build (3.7) (push) Has been cancelled
Create Examples / build (3.8) (push) Has been cancelled
This allows users to leverage jinja to include other files but also
loops, conditions, and other templating features.

Signed-off-by: Liam Beguin <liambeguin@gmail.com>
2024-06-09 17:53:54 -04:00
69 changed files with 303 additions and 383 deletions

View File

@ -4,40 +4,29 @@ on: [push, pull_request, workflow_dispatch]
jobs:
build:
runs-on: ubuntu-latest
strategy:
max-parallel: 6
max-parallel: 4
matrix:
# ubuntu-22.04 supports Python 3.7-3.12
# ubuntu-24.04 (currently latest & preferred) supports Python 3.9-3.12
# More details: https://github.com/actions/runner-images/issues/10636
os: [ubuntu-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]
include:
- os: ubuntu-22.04
python-version: "3.7"
- os: ubuntu-22.04
python-version: "3.8"
runs-on: ${{ matrix.os }}
python-version: [3.7, 3.8]
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Setup Graphviz
uses: ts-graphviz/setup-graphviz@v2
uses: ts-graphviz/setup-graphviz@v1
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .
- name: Create Examples
run: PYTHONPATH=$(pwd)/src/wireviz:$PYTHONPATH cd src/wireviz/ && python build_examples.py
run: PYTHONPATH=$(pwd)/src:$PYTHONPATH cd src/wireviz/ && python build_examples.py
- name: Upload examples, demos, and tutorials
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v2
with:
name: examples-and-tutorials-v${{ matrix.python-version }}
name: examples-and-tutorials
path: |
examples/
tutorial/
if-no-files-found: error

View File

@ -1,31 +1,6 @@
# Change Log
## [0.4.1] (2024-07-13)
### Improvements to help reported issues
- Print Python & OS versions when raising unexpected OSError related to #346 & #392 (bugfixes below)
- Explain unexpeced top-level type ([#342](https://github.com/wireviz/WireViz/issues/342), [#383](https://github.com/wireviz/WireViz/pull/383))
- Add non-empty label to reduce over-sized loops ([#286](https://github.com/wireviz/WireViz/issues/286), [#381](https://github.com/wireviz/WireViz/pull/381))
- Improve placeholder name consistency ([#377](https://github.com/wireviz/WireViz/issues/377), [#380](https://github.com/wireviz/WireViz/pull/380))
- Add work-around for Graphviz SVG bug ([#175](https://github.com/wireviz/WireViz/issues/175), [#371](https://github.com/wireviz/WireViz/pull/371))
### Bugfixes
- Avoid ResourceWarning: unclosed file ([#309 (comment)](https://github.com/wireviz/WireViz/pull/309#issuecomment-2170988381), [#395](https://github.com/wireviz/WireViz/pull/395))
- Catch ValueError and OSError(errno=None) ([#318 (review)](https://github.com/wireviz/WireViz/pull/318#pullrequestreview-1457016602), [#391](https://github.com/wireviz/WireViz/issues/391), [#392](https://github.com/wireviz/WireViz/pull/392))
- Add minor missing doc entry ([#186 (comment)](https://github.com/wireviz/WireViz/pull/186#issuecomment-2139037434), [#186 (comment)](https://github.com/wireviz/WireViz/pull/186#issuecomment-2155032522))
- Avoid Graphviz error when hiding all pins ([#257](https://github.com/wireviz/WireViz/issues/257), [#375](https://github.com/wireviz/WireViz/pull/375))
- Avoid decimal point and trailing zero for integer BOM quantities ([#340](https://github.com/wireviz/WireViz/issues/340), [#374](https://github.com/wireviz/WireViz/pull/374))
- Update project URL references ([#316 (comment)](https://github.com/wireviz/WireViz/issues/316#issuecomment-1568748914), [#364](https://github.com/wireviz/WireViz/pull/364))
- Add missing import of embed_svg_images ([#363](https://github.com/wireviz/WireViz/pull/363))
- Use correct default title ([#360](https://github.com/wireviz/WireViz/issues/360), [#361](https://github.com/wireviz/WireViz/pull/361))
- Fix bugs in mate processing ([#355](https://github.com/wireviz/WireViz/issues/355), [#358](https://github.com/wireviz/WireViz/pull/358))
- Include missing files in published package ([#345](https://github.com/wireviz/WireViz/issues/345), [#347](https://github.com/wireviz/WireViz/pull/347))
- Catch OSError(errno=EINVAL) ([#344](https://github.com/wireviz/WireViz/issues/344), [#346](https://github.com/wireviz/WireViz/pull/346))
## [0.4](https://github.com/wireviz/WireViz/tree/v0.4) (2024-05-12)
## [0.4](https://github.com/formatc1702/WireViz/tree/v0.4) (2024-05-12)
### Backward-incompatible changes
- New syntax for autogenerated components ([#184](https://github.com/wireviz/WireViz/issues/184), [#186](https://github.com/wireviz/WireViz/pull/186))
@ -34,6 +9,7 @@
- The path specified with the `-o`/`--output-dir` option no longer includes the filename (without extension) of the generated files. Use the `-O`/`--output-name` option to specify a different filename for the generated files.
- The `.gv` file is no longer included as a default output format (only as an intermediate file during processing) unless specified with the new `-f` option described below.
### New features
- Allow mates between connectors ([#134](https://github.com/wireviz/WireViz/issues/134), [#186](https://github.com/wireviz/WireViz/pull/186))
@ -49,89 +25,91 @@
- Minor adjustments ([#256](https://github.com/wireviz/WireViz/pull/256))
## [0.3.2](https://github.com/wireviz/WireViz/tree/v0.3.2) (2021-11-27)
## [0.3.2](https://github.com/formatc1702/WireViz/tree/v0.3.2) (2021-11-27)
### Hotfix
- Adjust GraphViz generation code for compatibility with v0.18 of the `graphviz` Python package ([#258](https://github.com/wireviz/WireViz/issues/258), [#261](https://github.com/wireviz/WireViz/pull/261))
- Adjust GraphViz generation code for compatibility with v0.18 of the `graphviz` Python package ([#258](https://github.com/formatc1702/WireViz/issues/258), [#261](https://github.com/formatc1702/WireViz/pull/261))
## [0.3.1](https://github.com/wireviz/WireViz/tree/v0.3.1) (2021-10-25)
## [0.3.1](https://github.com/formatc1702/WireViz/tree/v0.3.1) (2021-10-25)
### Hotfix
- Assign generic harness title when using WireViz as a module and not specifying an output file name ([#253](https://github.com/wireviz/WireViz/issues/253), [#254](https://github.com/wireviz/WireViz/pull/254))
- Assign generic harness title when using WireViz as a module and not specifying an output file name ([#253](https://github.com/formatc1702/WireViz/issues/253), [#254](https://github.com/formatc1702/WireViz/pull/254))
## [0.3](https://github.com/wireviz/WireViz/tree/v0.3) (2021-10-11)
## [0.3](https://github.com/formatc1702/WireViz/tree/v0.3) (2021-10-11)
### New features
- Allow referencing a cable's/bundle's wires by color or by label ([#70](https://github.com/wireviz/WireViz/issues/70), [#169](https://github.com/wireviz/WireViz/issues/169), [#193](https://github.com/wireviz/WireViz/issues/193), [#194](https://github.com/wireviz/WireViz/pull/194))
- Allow additional BOM items within components ([#50](https://github.com/wireviz/WireViz/issues/50), [#115](https://github.com/wireviz/WireViz/pull/115))
- Add support for length units in cables and wires ([#7](https://github.com/wireviz/WireViz/issues/7), [#196](https://github.com/wireviz/WireViz/pull/196) (with work from [#161](https://github.com/wireviz/WireViz/pull/161), [#162](https://github.com/wireviz/WireViz/pull/162), [#171](https://github.com/wireviz/WireViz/pull/171)), [#198](https://github.com/wireviz/WireViz/pull/198), [#205](https://github.com/wireviz/WireViz/issues/205). [#206](https://github.com/wireviz/WireViz/pull/206))
- Add option to define connector pin colors ([#53](https://github.com/wireviz/WireViz/issues/53), [#141](https://github.com/wireviz/WireViz/pull/141))
- Remove HTML links from the input attributes ([#164](https://github.com/wireviz/WireViz/pull/164))
- Add harness metadata section ([#158](https://github.com/wireviz/WireViz/issues/158), [#214](https://github.com/wireviz/WireViz/pull/214))
- Add support for supplier and supplier part number information ([#240](https://github.com/wireviz/WireViz/issues/240), [#241](https://github.com/wireviz/WireViz/pull/241/))
- Add graph rendering options (background colors, fontname, color name display style, ...) ([#158](https://github.com/wireviz/WireViz/issues/158), [#214](https://github.com/wireviz/WireViz/pull/214))
- Add support for background colors for cables and connectors, as well as for some individual cells ([#210](https://github.com/wireviz/WireViz/issues/210), [#219](https://github.com/wireviz/WireViz/pull/219))
- Add optional tweaking of the .gv output ([#215](https://github.com/wireviz/WireViz/pull/215)) (experimental)
- Allow referencing a cable's/bundle's wires by color or by label ([#70](https://github.com/formatc1702/WireViz/issues/70), [#169](https://github.com/formatc1702/WireViz/issues/169), [#193](https://github.com/formatc1702/WireViz/issues/193), [#194](https://github.com/formatc1702/WireViz/pull/194))
- Allow additional BOM items within components ([#50](https://github.com/formatc1702/WireViz/issues/50), [#115](https://github.com/formatc1702/WireViz/pull/115))
- Add support for length units in cables and wires ([#7](https://github.com/formatc1702/WireViz/issues/7), [#196](https://github.com/formatc1702/WireViz/pull/196) (with work from [#161](https://github.com/formatc1702/WireViz/pull/161), [#162](https://github.com/formatc1702/WireViz/pull/162), [#171](https://github.com/formatc1702/WireViz/pull/171)), [#198](https://github.com/formatc1702/WireViz/pull/198), [#205](https://github.com/formatc1702/WireViz/issues/205). [#206](https://github.com/formatc1702/WireViz/pull/206))
- Add option to define connector pin colors ([#53](https://github.com/formatc1702/WireViz/issues/53), [#141](https://github.com/formatc1702/WireViz/pull/141))
- Remove HTML links from the input attributes ([#164](https://github.com/formatc1702/WireViz/pull/164))
- Add harness metadata section ([#158](https://github.com/formatc1702/WireViz/issues/158), [#214](https://github.com/formatc1702/WireViz/pull/214))
- Add support for supplier and supplier part number information ([#240](https://github.com/formatc1702/WireViz/issues/240), [#241](https://github.com/formatc1702/WireViz/pull/241/))
- Add graph rendering options (background colors, fontname, color name display style, ...) ([#158](https://github.com/formatc1702/WireViz/issues/158), [#214](https://github.com/formatc1702/WireViz/pull/214))
- Add support for background colors for cables and connectors, as well as for some individual cells ([#210](https://github.com/formatc1702/WireViz/issues/210), [#219](https://github.com/formatc1702/WireViz/pull/219))
- Add optional tweaking of the .gv output ([#215](https://github.com/formatc1702/WireViz/pull/215)) (experimental)
### Misc. fixes
- Remove case-sensitivity issues with pin names and labels ([#160](https://github.com/wireviz/WireViz/issues/160), [#229](https://github.com/wireviz/WireViz/pull/229))
- Improve type hinting ([#156](https://github.com/wireviz/WireViz/issues/156), [#163](https://github.com/wireviz/WireViz/pull/163))
- Move BOM management and HTML functions to separate modules ([#151](https://github.com/wireviz/WireViz/issues/151), [#192](https://github.com/wireviz/WireViz/pull/192))
- Simplify BOM code ([#197](https://github.com/wireviz/WireViz/pull/197))
- Bug fixes ([#218](https://github.com/wireviz/WireViz/pull/218), [#221](https://github.com/wireviz/WireViz/pull/221))
- Remove case-sensitivity issues with pin names and labels ([#160](https://github.com/formatc1702/WireViz/issues/160), [#229](https://github.com/formatc1702/WireViz/pull/229))
- Improve type hinting ([#156](https://github.com/formatc1702/WireViz/issues/156), [#163](https://github.com/formatc1702/WireViz/pull/163))
- Move BOM management and HTML functions to separate modules ([#151](https://github.com/formatc1702/WireViz/issues/151), [#192](https://github.com/formatc1702/WireViz/pull/192))
- Simplify BOM code ([#197](https://github.com/formatc1702/WireViz/pull/197))
- Bug fixes ([#218](https://github.com/formatc1702/WireViz/pull/218), [#221](https://github.com/formatc1702/WireViz/pull/221))
### Known issues
- Including images in the harness may lead to issues in the following cases: ([#189](https://github.com/wireviz/WireViz/pull/189), [#220](https://github.com/wireviz/WireViz/issues/220))
- Including images in the harness may lead to issues in the following cases: ([#189](https://github.com/formatc1702/WireViz/pull/189), [#220](https://github.com/formatc1702/WireViz/issues/220))
- When using the `-o`/`--output_file` CLI option, specifying an output path in a different directory from the input file
- When using the `--prepend-file` CLI option, specifying a prepend file in a different directory from the mail input file
## [0.2](https://github.com/wireviz/WireViz/tree/v0.2) (2020-10-17)
## [0.2](https://github.com/formatc1702/WireViz/tree/v0.2) (2020-10-17)
### Backward incompatible changes
- Change names of connector attributes ([#77](https://github.com/wireviz/WireViz/issues/77), [#105](https://github.com/wireviz/WireViz/pull/105))
- Change names of connector attributes ([#77](https://github.com/formatc1702/WireViz/issues/77), [#105](https://github.com/formatc1702/WireViz/pull/105))
- `pinnumbers` is now `pins`
- `pinout` is now `pinlabels`
- Remove ferrules as a separate connector type ([#78](https://github.com/wireviz/WireViz/issues/78), [#102](https://github.com/wireviz/WireViz/pull/102))
- Remove ferrules as a separate connector type ([#78](https://github.com/formatc1702/WireViz/issues/78), [#102](https://github.com/formatc1702/WireViz/pull/102))
- Simple connectors like ferrules are now defined using the `style: simple` attribute
- Change the way loops are defined ([#79](https://github.com/wireviz/WireViz/issues/79), [#75](https://github.com/wireviz/WireViz/pull/75))
- Change the way loops are defined ([#79](https://github.com/formatc1702/WireViz/issues/79), [#75](https://github.com/formatc1702/WireViz/pull/75))
- Wires looping between two pins of the same connector are now handled via the connector's `loops` attribute.
See the [syntax description](syntax.md) for details.
### New features
- Add bidirectional AWG/mm2 conversion ([#40](https://github.com/wireviz/WireViz/issues/40), [#41](https://github.com/wireviz/WireViz/pull/41))
- Add support for part numbers ([#11](https://github.com/wireviz/WireViz/pull/11), [#114](https://github.com/wireviz/WireViz/issues/114), [#121](https://github.com/wireviz/WireViz/pull/121))
- Add support for multicolored wires ([#12](https://github.com/wireviz/WireViz/issues/12), [#17](https://github.com/wireviz/WireViz/pull/17), [#96](https://github.com/wireviz/WireViz/pull/96), [#131](https://github.com/wireviz/WireViz/issues/131), [#132](https://github.com/wireviz/WireViz/pull/132))
- Add support for images ([#27](https://github.com/wireviz/WireViz/issues/27), [#153](https://github.com/wireviz/WireViz/pull/153))
- Add ability to export data directly to other programs ([#55](https://github.com/wireviz/WireViz/pull/55))
- Add support for line breaks in various fields ([#49](https://github.com/wireviz/WireViz/issues/49), [#64](https://github.com/wireviz/WireViz/pull/64))
- Allow using connector pin names to define connections ([#72](https://github.com/wireviz/WireViz/issues/72), [#139](https://github.com/wireviz/WireViz/issues/139), [#140](https://github.com/wireviz/WireViz/pull/140))
- Make defining connection sets easier and more flexible ([#67](https://github.com/wireviz/WireViz/issues/67), [#75](https://github.com/wireviz/WireViz/pull/75))
- Add new command line options ([#167](https://github.com/wireviz/WireViz/issues/167), [#173](https://github.com/wireviz/WireViz/pull/173))
- Add new features to `build_examples.py` ([#118](https://github.com/wireviz/WireViz/pull/118))
- Add new colors ([#103](https://github.com/wireviz/WireViz/pull/103), [#113](https://github.com/wireviz/WireViz/pull/113), [#144](https://github.com/wireviz/WireViz/issues/144), [#145](https://github.com/wireviz/WireViz/pull/145))
- Improve documentation ([#107](https://github.com/wireviz/WireViz/issues/107), [#111](https://github.com/wireviz/WireViz/pull/111))
- Add bidirectional AWG/mm2 conversion ([#40](https://github.com/formatc1702/WireViz/issues/40), [#41](https://github.com/formatc1702/WireViz/pull/41))
- Add support for part numbers ([#11](https://github.com/formatc1702/WireViz/pull/11), [#114](https://github.com/formatc1702/WireViz/issues/114), [#121](https://github.com/formatc1702/WireViz/pull/121))
- Add support for multicolored wires ([#12](https://github.com/formatc1702/WireViz/issues/12), [#17](https://github.com/formatc1702/WireViz/pull/17), [#96](https://github.com/formatc1702/WireViz/pull/96), [#131](https://github.com/formatc1702/WireViz/issues/131), [#132](https://github.com/formatc1702/WireViz/pull/132))
- Add support for images ([#27](https://github.com/formatc1702/WireViz/issues/27), [#153](https://github.com/formatc1702/WireViz/pull/153))
- Add ability to export data directly to other programs ([#55](https://github.com/formatc1702/WireViz/pull/55))
- Add support for line breaks in various fields ([#49](https://github.com/formatc1702/WireViz/issues/49), [#64](https://github.com/formatc1702/WireViz/pull/64))
- Allow using connector pin names to define connections ([#72](https://github.com/formatc1702/WireViz/issues/72), [#139](https://github.com/formatc1702/WireViz/issues/139), [#140](https://github.com/formatc1702/WireViz/pull/140))
- Make defining connection sets easier and more flexible ([#67](https://github.com/formatc1702/WireViz/issues/67), [#75](https://github.com/formatc1702/WireViz/pull/75))
- Add new command line options ([#167](https://github.com/formatc1702/WireViz/issues/167), [#173](https://github.com/formatc1702/WireViz/pull/173))
- Add new features to `build_examples.py` ([#118](https://github.com/formatc1702/WireViz/pull/118))
- Add new colors ([#103](https://github.com/formatc1702/WireViz/pull/103), [#113](https://github.com/formatc1702/WireViz/pull/113), [#144](https://github.com/formatc1702/WireViz/issues/144), [#145](https://github.com/formatc1702/WireViz/pull/145))
- Improve documentation ([#107](https://github.com/formatc1702/WireViz/issues/107), [#111](https://github.com/formatc1702/WireViz/pull/111))
### Misc. fixes
- Improve BOM generation
- Add various input sanity checks
- Improve HTML output ([#66](https://github.com/wireviz/WireViz/issues/66), [#136](https://github.com/wireviz/WireViz/pull/136), [#95](https://github.com/wireviz/WireViz/pull/95), [#177](https://github.com/wireviz/WireViz/pull/177))
- Fix node rendering bug ([#69](https://github.com/wireviz/WireViz/issues/69), [#104](https://github.com/wireviz/WireViz/pull/104))
- Improve shield rendering ([#125](https://github.com/wireviz/WireViz/issues/125), [#126](https://github.com/wireviz/WireViz/pull/126))
- Add GitHub Linguist overrides ([#146](https://github.com/wireviz/WireViz/issues/146), [#154](https://github.com/wireviz/WireViz/pull/154))
- Improve HTML output ([#66](https://github.com/formatc1702/WireViz/issues/66), [#136](https://github.com/formatc1702/WireViz/pull/136), [#95](https://github.com/formatc1702/WireViz/pull/95), [#177](https://github.com/formatc1702/WireViz/pull/177))
- Fix node rendering bug ([#69](https://github.com/formatc1702/WireViz/issues/69), [#104](https://github.com/formatc1702/WireViz/pull/104))
- Improve shield rendering ([#125](https://github.com/formatc1702/WireViz/issues/125), [#126](https://github.com/formatc1702/WireViz/pull/126))
- Add GitHub Linguist overrides ([#146](https://github.com/formatc1702/WireViz/issues/146), [#154](https://github.com/formatc1702/WireViz/pull/154))
## [0.1](https://github.com/wireviz/WireViz/tree/v0.1) (2020-06-29)
## [0.1](https://github.com/formatc1702/WireViz/tree/v0.1) (2020-06-29)
- Initial release

View File

@ -1,6 +1,6 @@
# Contribution Guidelines
When contributing to this repository, please [submit a new issue](https://github.com/wireviz/WireViz/issues) first to discuss the proposed change, before submitting a pull request.
When contributing to this repository, please [submit a new issue](https://github.com/formatc1702/WireViz/issues) first to discuss the proposed change, before submitting a pull request.
## Submitting a new Issue
@ -27,7 +27,7 @@ When contributing to this repository, please [submit a new issue](https://github
1. Push the changes to your fork.
1. Please format your code using [`isort`](https://pycqa.github.io/isort/) and [`black`](https://black.readthedocs.io) before submitting.
1. Submit a new pull request, using `dev` as the base branch.
- If your code changes or extends the WireViz YAML syntax, be sure to update the [syntax description document](https://github.com/wireviz/WireViz/blob/dev/docs/syntax.md) in your PR.
- If your code changes or extends the WireViz YAML syntax, be sure to update the [syntax description document](https://github.com/formatc1702/WireViz/blob/dev/docs/syntax.md) in your PR.
1. Please include in the PR description (and optionally also in the commit message body) a reference (# followed by issue number) to the issue where the suggested changes are discussed.
### Hints

View File

@ -2,7 +2,7 @@
<!--
The following text is taken from #118
https://github.com/wireviz/WireViz/pull/118
https://github.com/formatc1702/WireViz/pull/118
TODO: write a better explaination -->

View File

@ -319,8 +319,6 @@ connections:
Since the internally assigned designator of an unnamed component is not known to the user, one instance of the connector can not be referenced again outside the point of creation (i.e. in other connection sets, or later in the same set). Autogeneration of unnamed instances is therefore only useful for terminals with only one wire attached, or splices with exactly one wire going in, and one wire going out.
If a component is to be used in other connection sets (e.g. for a three-way splice, or a crimp where multiple wires are joined), a named instance needs to be used.
The default character to trigger autogeneration of components is `.`. A different character can be specified using the `template_separator` option (see below).
Names of autogenerated components are hidden by default. While they can be shown in the graphical output using the `show_name: true` option, it is not recommended to manually use the internally assigned designator (starting with a double underscore `__`), since it might change in future WireViz versions, or when the order of items in connection sets changes.
@ -355,7 +353,6 @@ If any component is defined in the `connectors` or `cables` sections but not ref
# If no value is specified for 'title', then the
# output filename without extension is used.
```
See [HTML Output Templates](../src/wireviz/templates/) for how metadata entries can be inserted into the HTML output.
## Options
@ -390,9 +387,6 @@ See [HTML Output Templates](../src/wireviz/templates/) for how metadata entries
# about additional components inside the diagram node (connector/cable box).
# If False, show all info about additional components inside the diagram node.
mini_bom_mode: <bool> # Default = True
# Character to split template and designator for autogenerated components
template_separator: <str> # Default = '.'
```

4
examples/demo01.gv generated
View File

@ -1,6 +1,6 @@
graph {
// Graph generated by WireViz 0.4.1
// https://github.com/wireviz/WireViz
// Graph generated by WireViz 0.4
// https://github.com/formatc1702/WireViz
graph [bgcolor="#FFFFFF" fontname=arial nodesep=0.33 rankdir=LR ranksep=2]
node [fillcolor="#FFFFFF" fontname=arial height=0 margin=0 shape=none style=filled width=0]
edge [fontname=arial style=bold]

2
examples/demo01.html generated
View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<meta name="generator" content="WireViz 0.4.1 - https://github.com/wireviz/WireViz">
<meta name="generator" content="WireViz 0.4 - https://github.com/formatc1702/WireViz">
<title>demo01</title>
<style>

4
examples/demo02.gv generated
View File

@ -1,6 +1,6 @@
graph {
// Graph generated by WireViz 0.4.1
// https://github.com/wireviz/WireViz
// Graph generated by WireViz 0.4
// https://github.com/formatc1702/WireViz
graph [bgcolor="#FFFFFF" fontname=arial nodesep=0.33 rankdir=LR ranksep=2]
node [fillcolor="#FFFFFF" fontname=arial height=0 margin=0 shape=none style=filled width=0]
edge [fontname=arial style=bold]

2
examples/demo02.html generated
View File

@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="generator" content="WireViz 0.4.1 - https://github.com/wireviz/WireViz">
<meta name="generator" content="WireViz 0.4 - https://github.com/formatc1702/WireViz">
<title>WireViz Demo 2</title>
<style>
body {

4
examples/ex01.gv generated
View File

@ -1,6 +1,6 @@
graph {
// Graph generated by WireViz 0.4.1
// https://github.com/wireviz/WireViz
// Graph generated by WireViz 0.4
// https://github.com/formatc1702/WireViz
graph [bgcolor="#FFFFFF" fontname=arial nodesep=0.33 rankdir=LR ranksep=2]
node [fillcolor="#FFFFFF" fontname=arial height=0 margin=0 shape=none style=filled width=0]
edge [fontname=arial style=bold]

2
examples/ex01.html generated
View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<meta name="generator" content="WireViz 0.4.1 - https://github.com/wireviz/WireViz">
<meta name="generator" content="WireViz 0.4 - https://github.com/formatc1702/WireViz">
<title>ex01</title>
<style>

4
examples/ex02.gv generated
View File

@ -1,6 +1,6 @@
graph {
// Graph generated by WireViz 0.4.1
// https://github.com/wireviz/WireViz
// Graph generated by WireViz 0.4
// https://github.com/formatc1702/WireViz
graph [bgcolor="#FFFFFF" fontname=arial nodesep=0.33 rankdir=LR ranksep=2]
node [fillcolor="#FFFFFF" fontname=arial height=0 margin=0 shape=none style=filled width=0]
edge [fontname=arial style=bold]

2
examples/ex02.html generated
View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<meta name="generator" content="WireViz 0.4.1 - https://github.com/wireviz/WireViz">
<meta name="generator" content="WireViz 0.4 - https://github.com/formatc1702/WireViz">
<title>ex02</title>
<style>

4
examples/ex03.gv generated
View File

@ -1,6 +1,6 @@
graph {
// Graph generated by WireViz 0.4.1
// https://github.com/wireviz/WireViz
// Graph generated by WireViz 0.4
// https://github.com/formatc1702/WireViz
graph [bgcolor="#FFFFFF" fontname=arial nodesep=0.33 rankdir=LR ranksep=2]
node [fillcolor="#FFFFFF" fontname=arial height=0 margin=0 shape=none style=filled width=0]
edge [fontname=arial style=bold]

2
examples/ex03.html generated
View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<meta name="generator" content="WireViz 0.4.1 - https://github.com/wireviz/WireViz">
<meta name="generator" content="WireViz 0.4 - https://github.com/formatc1702/WireViz">
<title>ex03</title>
<style>

4
examples/ex04.gv generated
View File

@ -1,6 +1,6 @@
graph {
// Graph generated by WireViz 0.4.1
// https://github.com/wireviz/WireViz
// Graph generated by WireViz 0.4
// https://github.com/formatc1702/WireViz
graph [bgcolor="#FFFFFF" fontname=arial nodesep=0.33 rankdir=LR ranksep=2]
node [fillcolor="#FFFFFF" fontname=arial height=0 margin=0 shape=none style=filled width=0]
edge [fontname=arial style=bold]

2
examples/ex04.html generated
View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<meta name="generator" content="WireViz 0.4.1 - https://github.com/wireviz/WireViz">
<meta name="generator" content="WireViz 0.4 - https://github.com/formatc1702/WireViz">
<title>ex04</title>
<style>

4
examples/ex05.gv generated
View File

@ -1,6 +1,6 @@
graph {
// Graph generated by WireViz 0.4.1
// https://github.com/wireviz/WireViz
// Graph generated by WireViz 0.4
// https://github.com/formatc1702/WireViz
graph [bgcolor="#FFFFFF" fontname=arial nodesep=0.33 rankdir=LR ranksep=2]
node [fillcolor="#FFFFFF" fontname=arial height=0 margin=0 shape=none style=filled width=0]
edge [fontname=arial style=bold]

2
examples/ex05.html generated
View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<meta name="generator" content="WireViz 0.4.1 - https://github.com/wireviz/WireViz">
<meta name="generator" content="WireViz 0.4 - https://github.com/formatc1702/WireViz">
<title>ex05</title>
<style>

8
examples/ex06.bom.tsv generated
View File

@ -1,6 +1,6 @@
Id Description Qty Unit Designators
1 Connector, Molex KK 254, female, 4 pins 6 X1, X2, X3, X4, X5, X6
2 Wire, 0.25 mm², PK 1 m W1, W2, W3, W4, W5
3 Wire, 0.25 mm², TQ 1 m W1, W2, W3, W4, W5
4 Wire, 0.25 mm², VT 1 m W1, W2, W3, W4, W5
5 Wire, 0.25 mm², YE 1 m W1, W2, W3, W4, W5
2 Wire, 0.25 mm², PK 1.0 m W1, W2, W3, W4, W5
3 Wire, 0.25 mm², TQ 1.0 m W1, W2, W3, W4, W5
4 Wire, 0.25 mm², VT 1.0 m W1, W2, W3, W4, W5
5 Wire, 0.25 mm², YE 1.0 m W1, W2, W3, W4, W5

1 Id Description Qty Unit Designators
2 1 Connector, Molex KK 254, female, 4 pins 6 X1, X2, X3, X4, X5, X6
3 2 Wire, 0.25 mm², PK 1 1.0 m W1, W2, W3, W4, W5
4 3 Wire, 0.25 mm², TQ 1 1.0 m W1, W2, W3, W4, W5
5 4 Wire, 0.25 mm², VT 1 1.0 m W1, W2, W3, W4, W5
6 5 Wire, 0.25 mm², YE 1 1.0 m W1, W2, W3, W4, W5

4
examples/ex06.gv generated
View File

@ -1,6 +1,6 @@
graph {
// Graph generated by WireViz 0.4.1
// https://github.com/wireviz/WireViz
// Graph generated by WireViz 0.4
// https://github.com/formatc1702/WireViz
graph [bgcolor="#FFFFFF" fontname=arial nodesep=0.33 rankdir=LR ranksep=2]
node [fillcolor="#FFFFFF" fontname=arial height=0 margin=0 shape=none style=filled width=0]
edge [fontname=arial style=bold]

10
examples/ex06.html generated
View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<meta name="generator" content="WireViz 0.4.1 - https://github.com/wireviz/WireViz">
<meta name="generator" content="WireViz 0.4 - https://github.com/formatc1702/WireViz">
<title>ex06</title>
<style>
@ -716,28 +716,28 @@
<tr>
<td class="bom_col_id">2</td>
<td class="bom_col_description">Wire, 0.25 mm², PK</td>
<td class="bom_col_qty">1</td>
<td class="bom_col_qty">1.0</td>
<td class="bom_col_unit">m</td>
<td class="bom_col_designators">W1, W2, W3, W4, W5</td>
</tr>
<tr>
<td class="bom_col_id">3</td>
<td class="bom_col_description">Wire, 0.25 mm², TQ</td>
<td class="bom_col_qty">1</td>
<td class="bom_col_qty">1.0</td>
<td class="bom_col_unit">m</td>
<td class="bom_col_designators">W1, W2, W3, W4, W5</td>
</tr>
<tr>
<td class="bom_col_id">4</td>
<td class="bom_col_description">Wire, 0.25 mm², VT</td>
<td class="bom_col_qty">1</td>
<td class="bom_col_qty">1.0</td>
<td class="bom_col_unit">m</td>
<td class="bom_col_designators">W1, W2, W3, W4, W5</td>
</tr>
<tr>
<td class="bom_col_id">5</td>
<td class="bom_col_description">Wire, 0.25 mm², YE</td>
<td class="bom_col_qty">1</td>
<td class="bom_col_qty">1.0</td>
<td class="bom_col_unit">m</td>
<td class="bom_col_designators">W1, W2, W3, W4, W5</td>
</tr>

4
examples/ex07.gv generated
View File

@ -1,6 +1,6 @@
graph {
// Graph generated by WireViz 0.4.1
// https://github.com/wireviz/WireViz
// Graph generated by WireViz 0.4
// https://github.com/formatc1702/WireViz
graph [bgcolor="#FFFFFF" fontname=arial nodesep=0.33 rankdir=LR ranksep=2]
node [fillcolor="#FFFFFF" fontname=arial height=0 margin=0 shape=none style=filled width=0]
edge [fontname=arial style=bold]

2
examples/ex07.html generated
View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<meta name="generator" content="WireViz 0.4.1 - https://github.com/wireviz/WireViz">
<meta name="generator" content="WireViz 0.4 - https://github.com/formatc1702/WireViz">
<title>ex07</title>
<style>

4
examples/ex08.gv generated
View File

@ -1,6 +1,6 @@
graph {
// Graph generated by WireViz 0.4.1
// https://github.com/wireviz/WireViz
// Graph generated by WireViz 0.4
// https://github.com/formatc1702/WireViz
graph [bgcolor="#FFFFFF" fontname=arial nodesep=0.33 rankdir=LR ranksep=2]
node [fillcolor="#FFFFFF" fontname=arial height=0 margin=0 shape=none style=filled width=0]
edge [fontname=arial style=bold]

2
examples/ex08.html generated
View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<meta name="generator" content="WireViz 0.4.1 - https://github.com/wireviz/WireViz">
<meta name="generator" content="WireViz 0.4 - https://github.com/formatc1702/WireViz">
<title>ex08</title>
<style>

4
examples/ex09.gv generated
View File

@ -1,6 +1,6 @@
graph {
// Graph generated by WireViz 0.4.1
// https://github.com/wireviz/WireViz
// Graph generated by WireViz 0.4
// https://github.com/formatc1702/WireViz
graph [bgcolor="#FFFFFF" fontname=arial nodesep=0.33 rankdir=LR ranksep=2]
node [fillcolor="#FFFFFF" fontname=arial height=0 margin=0 shape=none style=filled width=0]
edge [fontname=arial style=bold]

2
examples/ex09.html generated
View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<meta name="generator" content="WireViz 0.4.1 - https://github.com/wireviz/WireViz">
<meta name="generator" content="WireViz 0.4 - https://github.com/formatc1702/WireViz">
<title>ex09</title>
<style>

4
examples/ex10.gv generated
View File

@ -1,6 +1,6 @@
graph {
// Graph generated by WireViz 0.4.1
// https://github.com/wireviz/WireViz
// Graph generated by WireViz 0.4
// https://github.com/formatc1702/WireViz
graph [bgcolor="#FFFFFF" fontname=arial nodesep=0.33 rankdir=LR ranksep=2]
node [fillcolor="#FFFFFF" fontname=arial height=0 margin=0 shape=none style=filled width=0]
edge [fontname=arial style=bold]

2
examples/ex10.html generated
View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<meta name="generator" content="WireViz 0.4.1 - https://github.com/wireviz/WireViz">
<meta name="generator" content="WireViz 0.4 - https://github.com/formatc1702/WireViz">
<title>ex10</title>
<style>

4
examples/ex11.gv generated
View File

@ -1,6 +1,6 @@
graph {
// Graph generated by WireViz 0.4.1
// https://github.com/wireviz/WireViz
// Graph generated by WireViz 0.4
// https://github.com/formatc1702/WireViz
graph [bgcolor="#FFFFFF" fontname=arial nodesep=0.33 rankdir=LR ranksep=2]
node [fillcolor="#FFFFFF" fontname=arial height=0 margin=0 shape=none style=filled width=0]
edge [fontname=arial style=bold]

2
examples/ex11.html generated
View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<meta name="generator" content="WireViz 0.4.1 - https://github.com/wireviz/WireViz">
<meta name="generator" content="WireViz 0.4 - https://github.com/formatc1702/WireViz">
<title>ex11</title>
<style>

4
examples/ex12.gv generated
View File

@ -1,6 +1,6 @@
graph {
// Graph generated by WireViz 0.4.1
// https://github.com/wireviz/WireViz
// Graph generated by WireViz 0.4
// https://github.com/formatc1702/WireViz
graph [bgcolor="#FFFFFF" fontname=arial nodesep=0.33 rankdir=LR ranksep=2]
node [fillcolor="#FFFFFF" fontname=arial height=0 margin=0 shape=none style=filled width=0]
edge [fontname=arial style=bold]

2
examples/ex12.html generated
View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<meta name="generator" content="WireViz 0.4.1 - https://github.com/wireviz/WireViz">
<meta name="generator" content="WireViz 0.4 - https://github.com/formatc1702/WireViz">
<title>ex12</title>
<style>

4
examples/ex13.gv generated
View File

@ -1,6 +1,6 @@
graph {
// Graph generated by WireViz 0.4.1
// https://github.com/wireviz/WireViz
// Graph generated by WireViz 0.4
// https://github.com/formatc1702/WireViz
graph [bgcolor="#FFFFFF" fontname=arial nodesep=0.33 rankdir=LR ranksep=2]
node [fillcolor="#FFFFFF" fontname=arial height=0 margin=0 shape=none style=filled width=0]
edge [fontname=arial style=bold]

2
examples/ex13.html generated
View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<meta name="generator" content="WireViz 0.4.1 - https://github.com/wireviz/WireViz">
<meta name="generator" content="WireViz 0.4 - https://github.com/formatc1702/WireViz">
<title>ex13</title>
<style>

4
examples/ex14.gv generated
View File

@ -1,6 +1,6 @@
graph {
// Graph generated by WireViz 0.4.1
// https://github.com/wireviz/WireViz
// Graph generated by WireViz 0.4
// https://github.com/formatc1702/WireViz
graph [bgcolor="#FFFFFF" fontname=arial nodesep=0.33 rankdir=LR ranksep=2]
node [fillcolor="#FFFFFF" fontname=arial height=0 margin=0 shape=none style=filled width=0]
edge [fontname=arial style=bold]

2
examples/ex14.html generated
View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<meta name="generator" content="WireViz 0.4.1 - https://github.com/wireviz/WireViz">
<meta name="generator" content="WireViz 0.4 - https://github.com/formatc1702/WireViz">
<title>ex14</title>
<style>

View File

@ -0,0 +1,7 @@
connectors:
{%- for i in range(1, 5) %}
X{{i}}:
type: Molex KK 254
subtype: female
pinlabels: [GND, RX, TX]
{%- endfor %}

21
examples/jinja/top.yml Normal file
View File

@ -0,0 +1,21 @@
{% include 'connectors.yml' %}
cables:
{%- for i in range(1, 3) %}
W{{i}}:
gauge: 0.25 mm2
length: 0.2
color_code: DIN
wirecount: 3
shield: true
{%- endfor %}
connections:
-
- X1: [1,2,3]
- W1: [1,2,3]
- X2: [1,2,3]
-
- X3: [1,2,3]
- W2: [1,2,3]
- X4: [1,2,3]

View File

@ -22,12 +22,12 @@ setup(
"pyyaml",
"pillow",
"graphviz",
"jinja2",
],
license="GPLv3",
keywords="cable connector hardware harness wiring wiring-diagram wiring-harness",
url=APP_URL,
package_dir={"": "src"},
package_data={CMD_NAME: ["templates/*.html"]},
packages=find_packages("src"),
entry_points={
"console_scripts": [

View File

@ -91,6 +91,7 @@ class Image:
# See also HTML doc at https://graphviz.org/doc/info/shapes.html#html
def __post_init__(self):
if self.fixedsize is None:
# Default True if any dimension specified unless self.scale also is specified.
self.fixedsize = (self.width or self.height) and self.scale is None
@ -165,6 +166,7 @@ class Connector:
additional_components: List[AdditionalComponent] = field(default_factory=list)
def __post_init__(self) -> None:
if isinstance(self.image, dict):
self.image = Image(**self.image)
@ -274,6 +276,7 @@ class Cable:
additional_components: List[AdditionalComponent] = field(default_factory=list)
def __post_init__(self) -> None:
if isinstance(self.image, dict):
self.image = Image(**self.image)
@ -383,6 +386,7 @@ class Cable:
to_name: Optional[Designator],
to_pin: NoneOrMorePinIndices,
) -> None:
from_pin = int2tuple(from_pin)
via_wire = int2tuple(via_wire)
to_pin = int2tuple(to_pin)

View File

@ -8,6 +8,7 @@ from pathlib import Path
from typing import Any, List, Union
from graphviz import Graph
from wireviz import APP_NAME, APP_URL, __version__, wv_colors
from wireviz.DataClasses import (
Cable,
@ -16,10 +17,10 @@ from wireviz.DataClasses import (
MatePin,
Metadata,
Options,
Side,
Tweak,
Side,
)
from wireviz.svgembed import embed_svg_images, embed_svg_images_file
from wireviz.svgembed import embed_svg_images_file
from wireviz.wv_bom import (
HEADER_MPN,
HEADER_PN,
@ -43,10 +44,11 @@ from wireviz.wv_gv_html import (
)
from wireviz.wv_helper import (
awg_equiv,
file_write_text,
flatten2d,
is_arrow,
mm2_equiv,
open_file_read,
open_file_write,
tuplelist2tsv,
)
from wireviz.wv_html import generate_html_output
@ -57,14 +59,12 @@ OLD_CONNECTOR_ATTR = {
"autogenerate": "is replaced with new syntax in v0.4",
}
def check_old(node: str, old_attr: dict, args: dict) -> None:
"""Raise exception for any outdated attributes in args."""
for attr, descr in old_attr.items():
if attr in args:
raise ValueError(f"'{attr}' in {node}: '{attr}' {descr}")
@dataclass
class Harness:
metadata: Metadata
@ -172,7 +172,7 @@ class Harness:
bgcolor=wv_colors.translate_color(self.options.bgcolor, "HEX"),
nodesep="0.33",
fontname=self.options.fontname,
) # TODO: Add graph attribute: charset="utf-8",
)
dot.attr(
"node",
shape="none",
@ -186,6 +186,7 @@ class Harness:
dot.attr("edge", style="bold", fontname=self.options.fontname)
for connector in self.connectors.values():
# If no wires connected (except maybe loop wires)?
if not (connector.ports_left or connector.ports_right):
connector.ports_left = True # Use left side pins.
@ -252,9 +253,6 @@ class Harness:
pinhtml.append(" </table>")
if len(pinhtml) == 2: # Table start and end with no rows between?
pinhtml = ["<!-- all pins hidden -->"] # Avoid Graphviz error
html = [
row.replace("<!-- connector table -->", "\n".join(pinhtml))
for row in html
@ -283,7 +281,6 @@ class Harness:
dot.edge(
f"{connector.name}:p{loop[0]}{loop_side}:{loop_dir}",
f"{connector.name}:p{loop[1]}{loop_side}:{loop_dir}",
label=" ", # Work-around to avoid over-sized loops.
)
# determine if there are double- or triple-colored wires in the harness;
@ -295,6 +292,7 @@ class Harness:
)
for cable in self.cables.values():
html = []
awg_fmt = ""
@ -532,38 +530,6 @@ class Harness:
fillcolor=translate_color(bgcolor, "HEX"),
)
# mates
for mate in self.mates:
if mate.shape[-1] == ">":
dir = "both" if mate.shape[0] == "<" else "forward"
else:
dir = "back" if mate.shape[0] == "<" else "none"
if isinstance(mate, MatePin):
color = "#000000"
elif isinstance(mate, MateComponent):
color = "#000000:#000000"
else:
raise Exception(f"{mate} is an unknown mate")
from_connector = self.connectors[mate.from_name]
to_connector = self.connectors[mate.to_name]
if isinstance(mate, MatePin) and from_connector.style != "simple":
from_pin_index = from_connector.pins.index(mate.from_pin)
from_port_str = f":p{from_pin_index+1}r"
else: # MateComponent or style == 'simple'
from_port_str = ""
if isinstance(mate, MatePin) and to_connector.style != "simple":
to_pin_index = to_connector.pins.index(mate.to_pin)
to_port_str = f":p{to_pin_index+1}l"
else: # MateComponent or style == 'simple'
to_port_str = ""
code_from = f"{mate.from_name}{from_port_str}:e"
code_to = f"{mate.to_name}{to_port_str}:w"
dot.attr("edge", color=color, style="dashed", dir=dir)
dot.edge(code_from, code_to)
def typecheck(name: str, value: Any, expect: type) -> None:
if not isinstance(value, expect):
raise Exception(
@ -629,9 +595,51 @@ class Harness:
typecheck("tweak.append", self.tweak.append, str)
dot.body.append(self.tweak.append)
# Tweak processing above must be the last before returning dot.
# Please don't insert any code that might change the dot contents
# after tweak processing.
for mate in self.mates:
if mate.shape[0] == "<" and mate.shape[-1] == ">":
dir = "both"
elif mate.shape[0] == "<":
dir = "back"
elif mate.shape[-1] == ">":
dir = "forward"
else:
dir = "none"
if isinstance(mate, MatePin):
color = "#000000"
elif isinstance(mate, MateComponent):
color = "#000000:#000000"
else:
raise Exception(f"{mate} is an unknown mate")
from_connector = self.connectors[mate.from_name]
if (
isinstance(mate, MatePin)
and self.connectors[mate.from_name].style != "simple"
):
from_pin_index = from_connector.pins.index(mate.from_pin)
from_port_str = f":p{from_pin_index+1}r"
else: # MateComponent or style == 'simple'
from_port_str = ""
if (
isinstance(mate, MatePin)
and self.connectors[mate.to_name].style != "simple"
):
to_pin_index = to_connector.pins.index(mate.to_pin)
to_port_str = (
f":p{to_pin_index+1}l"
if isinstance(mate, MatePin)
and self.connectors[mate.to_name].style != "simple"
else ""
)
else: # MateComponent or style == 'simple'
to_port_str = ""
code_from = f"{mate.from_name}{from_port_str}:e"
to_connector = self.connectors[mate.to_name]
code_to = f"{mate.to_name}{to_port_str}:w"
dot.attr("edge", color=color, style="dashed", dir=dir)
dot.edge(code_from, code_to)
return dot
@ -656,7 +664,7 @@ class Harness:
return data.read()
@property
def svg(self): # TODO?: Verify xml encoding="utf-8" in SVG?
def svg(self):
graph = self.graph
return embed_svg_images(graph.pipe(format="svg").decode("utf-8"), Path.cwd())
@ -691,7 +699,7 @@ class Harness:
# BOM output
bomlist = bom_list(self.bom())
if "tsv" in fmt:
file_write_text(f"{filename}.bom.tsv", tuplelist2tsv(bomlist))
open_file_write(f"{filename}.bom.tsv").write(tuplelist2tsv(bomlist))
if "csv" in fmt:
# TODO: implement CSV output (preferrably using CSV library)
print("CSV output is not yet supported")

View File

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
# Please don't import anything in this file to avoid issues when it is imported in setup.py
__version__ = "0.4.1"
__version__ = "0.4"
CMD_NAME = "wireviz" # Lower case command and module name
APP_NAME = "WireViz" # Application name in texts meant to be human readable
APP_URL = "https://github.com/wireviz/WireViz"
APP_URL = "https://github.com/formatc1702/WireViz"

View File

@ -8,20 +8,6 @@ from typing import Union
mime_subtype_replacements = {"jpg": "jpeg", "tif": "tiff"}
# TODO: Share cache and code between data_URI_base64() and embed_svg_images()
def data_URI_base64(file: Union[str, Path], media: str = "image") -> str:
"""Return Base64-encoded data URI of input file."""
file = Path(file)
b64 = base64.b64encode(file.read_bytes()).decode("utf-8")
uri = f"data:{media}/{get_mime_subtype(file)};base64, {b64}"
# print(f"data_URI_base64('{file}', '{media}') -> {len(uri)}-character URI")
if len(uri) > 65535:
print(
"data_URI_base64(): Warning: Browsers might have different URI length limitations"
)
return uri
def embed_svg_images(svg_in: str, base_path: Union[str, Path] = Path.cwd()) -> str:
images_b64 = {} # cache of base64-encoded images
@ -59,8 +45,8 @@ def embed_svg_images_file(
) -> None:
filename_in = Path(filename_in).resolve()
filename_out = filename_in.with_suffix(".b64.svg")
filename_out.write_text( # TODO?: Verify xml encoding="utf-8" in SVG?
filename_out.write_text(
embed_svg_images(filename_in.read_text(), filename_in.parent)
) # TODO: Use encoding="utf-8" in both read_text() and write_text()
)
if overwrite:
filename_out.replace(filename_in)

View File

@ -1,52 +0,0 @@
# HTML Output Templates
This is the standard folder where WireViz looks for an HTML output template file.
## Which HTML Output Template File is Used?
A named HTML output template can optionally be specified as
`metadata.template.name` in the YAML input:
```yaml
metadata:
template:
name: din-6771
```
In the case above, WireViz will search for a template file named
`din-6771.html` in these folders:
1. In the same folder as the YAML input file.
2. In this standard template folder.
If no HTML output template is specified, the `simple` template is assumed
(i.e. filename `simple.html`, and in this case,
only the standard template folder is searched).
## Placeholders in HTML Output Templates
HTML output template files might contain placeholders that will be replaced by
generated text by WireViz when producing HTML output based on such a template.
A placeholder starts with `<!-- %`, followed by a keyword, and finally `% -->`.
Note that there must be one single space between `--` and `%` at both ends.
| Placeholder | Replaced by |
| --- | --- |
| `<!-- %generator% -->` | The application name, version, and URL |
| `<!-- %fontname% -->` | The value of `options.fontname` |
| `<!-- %bgcolor% -->` | The HEX color translation of `options.bgcolor` |
| `<!-- %filename% -->` | The output path and filename without extension |
| `<!-- %filename_stem% -->` | The output filename without path nor extension |
| `<!-- %bom% -->` | BOM as HTML table with headers at top |
| `<!-- %bom_reversed% -->` | Reversed BOM as HTML table with headers at bottom |
| `<!-- %sheet_current% -->` | `1` (multi-page documents not yet supported) |
| `<!-- %sheet_total% -->` | `1` (multi-page documents not yet supported) |
| `<!-- %diagram% -->` | Embedded SVG diagram as valid HTML |
| `<!-- %diagram_png_b64% -->` | Embedded base64 encoded PNG diagram as URI |
| `<!-- %{item}% -->` | String or numeric value of `metadata.{item}` |
| `<!-- %{item}_{i}% -->` | Category number `{i}` within dict value of `metadata.{item}` |
| `<!-- %{item}_{i}_{key}% -->` | Value of `metadata.{item}.{category}.{key}` |
| `<!-- %template_sheetsize% -->` | Value of `metadata.template.sheetsize` |
Note that `{item}`, `{category}` and `{key}` in the description above can be
any valid YAML key, and `{i}` is an integer representing the 1-based index of
category entries in a dict `metadata.{item}` entry.
The `{` and `}` characters are not literally part of the syntax, just used in
this documentation to enclose the variable parts of the keywords.

View File

@ -179,7 +179,7 @@
</head>
<body>
<div id="page">
<div id="frame" class="<!-- %template_sheetsize% -->">
<div id="frame" class="sheetsize_default">
<div id="diagram">

View File

@ -1,7 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import platform
import sys
from pathlib import Path
from typing import Any, Dict, List, Tuple, Union
@ -15,14 +14,12 @@ from wireviz.DataClasses import Metadata, Options, Tweak
from wireviz.Harness import Harness
from wireviz.wv_helper import (
expand,
file_read_text,
get_single_key_and_value,
is_arrow,
open_file_read,
smart_file_resolve,
)
from . import APP_NAME
def parse(
inp: Union[Path, str, Dict],
@ -89,10 +86,6 @@ def parse(
raise Exception("No output formats or return types specified")
yaml_data, yaml_file = _get_yaml_data_and_path(inp)
if not isinstance(yaml_data, dict):
raise TypeError(
f"Expected a dict as top-level YAML input, but got: {type(yaml_data)}"
)
if output_formats:
# need to write data to file, determine output directory and filename
output_dir = _get_output_dir(yaml_file, output_dir)
@ -124,7 +117,10 @@ def parse(
# When title is not given, either deduce it from filename, or use default text.
if "title" not in harness.metadata:
harness.metadata["title"] = output_name or f"{APP_NAME} diagram and BOM"
if yaml_file is None:
harness.metadata["title"] = "WireViz diagram and BOM"
else:
harness.metadata["title"] = Path(yaml_file).stem
# add items
# parse YAML input file ====================================================
@ -209,6 +205,7 @@ def parse(
expected_type = alternating_types[1 - alternating_types.index(expected_type)]
for connection_set in connection_sets:
# figure out number of parallel connections within this set
connectioncount = []
for entry in connection_set:
@ -408,21 +405,14 @@ def _get_yaml_data_and_path(inp: Union[str, Path, Dict]) -> (Dict, Path):
try:
yaml_path = Path(inp).expanduser().resolve(strict=True)
# if no FileNotFoundError exception happens, get file contents
yaml_str = file_read_text(yaml_path)
except (FileNotFoundError, OSError, ValueError) as e:
# if inp is a long YAML string, Pathlib will normally raise
# FileNotFoundError or OSError(errno = ENAMETOOLONG) when
# trying to expand and resolve it as a path, but in Windows
# might ValueError or OSError(errno = EINVAL or None) be raised
# instead in some cases (depending on the Python version).
# Catch these specific errors, but raise any others.
yaml_str = open_file_read(yaml_path).read()
except (FileNotFoundError, OSError) as e:
# if inp is a long YAML string, Pathlib will raise OSError: [errno.ENAMETOOLONG]
# when trying to expand and resolve it as a path.
# Catch this error, but raise any others
from errno import ENAMETOOLONG
from errno import EINVAL, ENAMETOOLONG
if type(e) is OSError and e.errno not in (EINVAL, ENAMETOOLONG, None):
print(
f"OSError(errno={e.errno}) in Python {sys.version} at {platform.platform()}"
)
if type(e) is OSError and e.errno != ENAMETOOLONG:
raise e
# file does not exist; assume inp is a YAML string
yaml_str = inp

View File

@ -204,9 +204,7 @@ def generate_bom(harness: "Harness") -> List[BOMEntry]:
bom.append(
{
**group_entries[0],
"qty": int(total_qty)
if float(total_qty).is_integer()
else round(total_qty, 3),
"qty": round(total_qty, 3),
"designators": sorted(set(designators)),
}
)

View File

@ -3,6 +3,7 @@
import os
import sys
from pathlib import Path
import jinja2
import click
@ -11,7 +12,7 @@ if __name__ == "__main__":
import wireviz.wireviz as wv
from wireviz import APP_NAME, __version__
from wireviz.wv_helper import file_read_text
from wireviz.wv_helper import open_file_read
format_codes = {
# "c": "csv",
@ -50,6 +51,13 @@ epilog += ", ".join([f"{key} ({value.upper()})" for key, value in format_codes.i
type=Path,
help="YAML file to prepend to the input file (optional).",
)
@click.option(
"-I",
"--include-path",
default=None,
type=Path,
help="Include path used for Jinja2 templates",
)
@click.option(
"-o",
"--output-dir",
@ -71,7 +79,7 @@ epilog += ", ".join([f"{key} ({value.upper()})" for key, value in format_codes.i
default=False,
help=f"Output {APP_NAME} version and exit.",
)
def wireviz(file, format, prepend, output_dir, output_name, version):
def wireviz(file, format, prepend, include_path, output_dir, output_name, version):
"""
Parses the provided FILE and generates the specified outputs.
"""
@ -111,10 +119,19 @@ def wireviz(file, format, prepend, output_dir, output_name, version):
raise Exception(f"File does not exist:\n{prepend_file}")
print("Prepend file:", prepend_file)
prepend_input += file_read_text(prepend_file) + "\n"
prepend_input += open_file_read(prepend_file).read() + "\n"
else:
prepend_input = ""
searchpath = [Path(f).parent for f in filepaths]
if include_path is not None:
searchpath.append(include_path)
env = jinja2.Environment(
loader=jinja2.FileSystemLoader(searchpath=searchpath),
)
# run WireVIz on each input file
for file in filepaths:
file = Path(file)
@ -130,7 +147,11 @@ def wireviz(file, format, prepend, output_dir, output_name, version):
"Output file: ", f"{Path(_output_dir / _output_name)}.{output_formats_str}"
)
yaml_input = file_read_text(file)
template = env.get_template(file.name)
yaml_input = template.render()
with open(Path(_output_dir / (_output_name + '.rendered.yml')), 'w') as f:
f.write(yaml_input)
file_dir = file.parent
yaml_input = prepend_input + yaml_input

View File

@ -113,31 +113,18 @@ def clean_whitespace(inp):
def open_file_read(filename):
"""Open utf-8 encoded text file for reading - remember closing it when finished"""
# TODO: Intelligently determine encoding
return open(filename, "r", encoding="UTF-8")
def open_file_write(filename):
"""Open utf-8 encoded text file for writing - remember closing it when finished"""
return open(filename, "w", encoding="UTF-8")
def open_file_append(filename):
"""Open utf-8 encoded text file for appending - remember closing it when finished"""
return open(filename, "a", encoding="UTF-8")
def file_read_text(filename: str) -> str:
"""Read utf-8 encoded text file, close it, and return the text"""
return Path(filename).read_text(encoding="utf-8")
def file_write_text(filename: str, text: str) -> int:
"""Write utf-8 encoded text file, close it, and return the number of characters written"""
return Path(filename).write_text(text, encoding="utf-8")
def is_arrow(inp):
"""
Matches strings of one or multiple `-` or `=` (but not mixed)
@ -157,7 +144,7 @@ def aspect_ratio(image_src):
try:
from PIL import Image
with Image.open(image_src) as image:
image = Image.open(image_src)
if image.width > 0 and image.height > 0:
return image.width / image.height
print(f"aspect_ratio(): Invalid image size {image.width} x {image.height}")

View File

@ -2,16 +2,15 @@
import re
from pathlib import Path
from typing import Callable, Dict, List, Union
from typing import Dict, List, Union
from wireviz import APP_NAME, APP_URL, __version__, wv_colors
from wireviz.DataClasses import Metadata, Options
from wireviz.svgembed import data_URI_base64
from wireviz.wv_gv_html import html_line_breaks
from wireviz.wv_helper import (
file_read_text,
file_write_text,
flatten2d,
open_file_read,
open_file_write,
smart_file_resolve,
)
@ -22,6 +21,7 @@ def generate_html_output(
metadata: Metadata,
options: Options,
):
# load HTML template
templatename = metadata.get("template", {}).get("name")
if templatename:
@ -34,14 +34,14 @@ def generate_html_output(
# fall back to built-in simple template if no template was provided
templatefile = Path(__file__).parent / "templates/simple.html"
html = file_read_text(templatefile) # TODO?: Warn if unexpected meta charset?
html = open_file_read(templatefile).read()
# embed SVG diagram (only if used)
def svgdata() -> str:
return re.sub( # TODO?: Verify xml encoding="utf-8" in SVG?
# embed SVG diagram
with open_file_read(f"{filename}.tmp.svg") as file:
svgdata = re.sub(
"^<[?]xml [^?>]*[?]>[^<]*<!DOCTYPE [^>]*>",
"<!-- XML and DOCTYPE declarations from SVG file removed -->",
file_read_text(f"{filename}.tmp.svg"),
file.read(),
1,
)
@ -80,27 +80,13 @@ def generate_html_output(
"<!-- %generator% -->": f"{APP_NAME} {__version__} - {APP_URL}",
"<!-- %fontname% -->": options.fontname,
"<!-- %bgcolor% -->": wv_colors.translate_color(options.bgcolor, "hex"),
"<!-- %filename% -->": str(filename),
"<!-- %filename_stem% -->": Path(filename).stem,
"<!-- %diagram% -->": svgdata,
"<!-- %bom% -->": bom_html,
"<!-- %bom_reversed% -->": bom_html_reversed,
"<!-- %sheet_current% -->": "1", # TODO: handle multi-page documents
"<!-- %sheet_total% -->": "1", # TODO: handle multi-page documents
"<!-- %template_sheetsize% -->": metadata.get("template", {}).get(
"sheetsize", ""
),
}
def replacement_if_used(key: str, func: Callable[[], str]) -> None:
"""Append replacement only if used in html."""
if key in html:
replacements[key] = func()
replacement_if_used("<!-- %diagram% -->", svgdata)
replacement_if_used(
"<!-- %diagram_png_b64% -->", lambda: data_URI_base64(f"{filename}.png")
)
# prepare metadata replacements
if metadata:
for item, contents in metadata.items():
@ -111,11 +97,14 @@ def generate_html_output(
if isinstance(entry, Dict):
replacements[f"<!-- %{item}_{index+1}% -->"] = str(category)
for entry_key, entry_value in entry.items():
replacements[
f"<!-- %{item}_{index+1}_{entry_key}% -->"
] = html_line_breaks(str(entry_value))
elif isinstance(entry, (str, int, float)):
pass # TODO?: replacements[f"<!-- %{item}_{category}% -->"] = html_line_breaks(str(entry))
replacements[f"<!-- %{item}_{index+1}_{entry_key}% -->"] = (
html_line_breaks(str(entry_value))
)
replacements['"sheetsize_default"'] = '"{}"'.format(
metadata.get("template", {}).get("sheetsize", "")
)
# include quotes so no replacement happens within <style> definition
# perform replacements
# regex replacement adapted from:
@ -127,4 +116,4 @@ def generate_html_output(
pattern = re.compile("|".join(replacements_escaped))
html = pattern.sub(lambda match: replacements[match.group(0)], html)
file_write_text(f"{filename}.html", html)
open_file_write(f"{filename}.html").write(html)

View File

@ -1,6 +1,6 @@
graph {
// Graph generated by WireViz 0.4.1
// https://github.com/wireviz/WireViz
// Graph generated by WireViz 0.4
// https://github.com/formatc1702/WireViz
graph [bgcolor="#FFFFFF" fontname=arial nodesep=0.33 rankdir=LR ranksep=2]
node [fillcolor="#FFFFFF" fontname=arial height=0 margin=0 shape=none style=filled width=0]
edge [fontname=arial style=bold]

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<meta name="generator" content="WireViz 0.4.1 - https://github.com/wireviz/WireViz">
<meta name="generator" content="WireViz 0.4 - https://github.com/formatc1702/WireViz">
<title>tutorial01</title>
<style>

View File

@ -1,6 +1,6 @@
graph {
// Graph generated by WireViz 0.4.1
// https://github.com/wireviz/WireViz
// Graph generated by WireViz 0.4
// https://github.com/formatc1702/WireViz
graph [bgcolor="#FFFFFF" fontname=arial nodesep=0.33 rankdir=LR ranksep=2]
node [fillcolor="#FFFFFF" fontname=arial height=0 margin=0 shape=none style=filled width=0]
edge [fontname=arial style=bold]

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<meta name="generator" content="WireViz 0.4.1 - https://github.com/wireviz/WireViz">
<meta name="generator" content="WireViz 0.4 - https://github.com/formatc1702/WireViz">
<title>tutorial02</title>
<style>

View File

@ -1,6 +1,6 @@
graph {
// Graph generated by WireViz 0.4.1
// https://github.com/wireviz/WireViz
// Graph generated by WireViz 0.4
// https://github.com/formatc1702/WireViz
graph [bgcolor="#FFFFFF" fontname=arial nodesep=0.33 rankdir=LR ranksep=2]
node [fillcolor="#FFFFFF" fontname=arial height=0 margin=0 shape=none style=filled width=0]
edge [fontname=arial style=bold]

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<meta name="generator" content="WireViz 0.4.1 - https://github.com/wireviz/WireViz">
<meta name="generator" content="WireViz 0.4 - https://github.com/formatc1702/WireViz">
<title>tutorial03</title>
<style>

View File

@ -1,6 +1,6 @@
graph {
// Graph generated by WireViz 0.4.1
// https://github.com/wireviz/WireViz
// Graph generated by WireViz 0.4
// https://github.com/formatc1702/WireViz
graph [bgcolor="#FFFFFF" fontname=arial nodesep=0.33 rankdir=LR ranksep=2]
node [fillcolor="#FFFFFF" fontname=arial height=0 margin=0 shape=none style=filled width=0]
edge [fontname=arial style=bold]

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<meta name="generator" content="WireViz 0.4.1 - https://github.com/wireviz/WireViz">
<meta name="generator" content="WireViz 0.4 - https://github.com/formatc1702/WireViz">
<title>tutorial04</title>
<style>

View File

@ -1,6 +1,6 @@
graph {
// Graph generated by WireViz 0.4.1
// https://github.com/wireviz/WireViz
// Graph generated by WireViz 0.4
// https://github.com/formatc1702/WireViz
graph [bgcolor="#FFFFFF" fontname=arial nodesep=0.33 rankdir=LR ranksep=2]
node [fillcolor="#FFFFFF" fontname=arial height=0 margin=0 shape=none style=filled width=0]
edge [fontname=arial style=bold]

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<meta name="generator" content="WireViz 0.4.1 - https://github.com/wireviz/WireViz">
<meta name="generator" content="WireViz 0.4 - https://github.com/formatc1702/WireViz">
<title>tutorial05</title>
<style>

View File

@ -1,6 +1,6 @@
graph {
// Graph generated by WireViz 0.4.1
// https://github.com/wireviz/WireViz
// Graph generated by WireViz 0.4
// https://github.com/formatc1702/WireViz
graph [bgcolor="#FFFFFF" fontname=arial nodesep=0.33 rankdir=LR ranksep=2]
node [fillcolor="#FFFFFF" fontname=arial height=0 margin=0 shape=none style=filled width=0]
edge [fontname=arial style=bold]

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<meta name="generator" content="WireViz 0.4.1 - https://github.com/wireviz/WireViz">
<meta name="generator" content="WireViz 0.4 - https://github.com/formatc1702/WireViz">
<title>tutorial06</title>
<style>

View File

@ -1,6 +1,6 @@
Id Description Qty Unit Designators
1 Connector, Molex KK 254, female, 4 pins 6 X1, X2, X3, X4, X5, X6
2 Wire, 0.25 mm², PK 1 m W1, W2, W3, W4, W5
3 Wire, 0.25 mm², TQ 1 m W1, W2, W3, W4, W5
4 Wire, 0.25 mm², VT 1 m W1, W2, W3, W4, W5
5 Wire, 0.25 mm², YE 1 m W1, W2, W3, W4, W5
2 Wire, 0.25 mm², PK 1.0 m W1, W2, W3, W4, W5
3 Wire, 0.25 mm², TQ 1.0 m W1, W2, W3, W4, W5
4 Wire, 0.25 mm², VT 1.0 m W1, W2, W3, W4, W5
5 Wire, 0.25 mm², YE 1.0 m W1, W2, W3, W4, W5

1 Id Description Qty Unit Designators
2 1 Connector, Molex KK 254, female, 4 pins 6 X1, X2, X3, X4, X5, X6
3 2 Wire, 0.25 mm², PK 1 1.0 m W1, W2, W3, W4, W5
4 3 Wire, 0.25 mm², TQ 1 1.0 m W1, W2, W3, W4, W5
5 4 Wire, 0.25 mm², VT 1 1.0 m W1, W2, W3, W4, W5
6 5 Wire, 0.25 mm², YE 1 1.0 m W1, W2, W3, W4, W5

View File

@ -1,6 +1,6 @@
graph {
// Graph generated by WireViz 0.4.1
// https://github.com/wireviz/WireViz
// Graph generated by WireViz 0.4
// https://github.com/formatc1702/WireViz
graph [bgcolor="#FFFFFF" fontname=arial nodesep=0.33 rankdir=LR ranksep=2]
node [fillcolor="#FFFFFF" fontname=arial height=0 margin=0 shape=none style=filled width=0]
edge [fontname=arial style=bold]

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<meta name="generator" content="WireViz 0.4.1 - https://github.com/wireviz/WireViz">
<meta name="generator" content="WireViz 0.4 - https://github.com/formatc1702/WireViz">
<title>tutorial07</title>
<style>
@ -716,28 +716,28 @@
<tr>
<td class="bom_col_id">2</td>
<td class="bom_col_description">Wire, 0.25 mm², PK</td>
<td class="bom_col_qty">1</td>
<td class="bom_col_qty">1.0</td>
<td class="bom_col_unit">m</td>
<td class="bom_col_designators">W1, W2, W3, W4, W5</td>
</tr>
<tr>
<td class="bom_col_id">3</td>
<td class="bom_col_description">Wire, 0.25 mm², TQ</td>
<td class="bom_col_qty">1</td>
<td class="bom_col_qty">1.0</td>
<td class="bom_col_unit">m</td>
<td class="bom_col_designators">W1, W2, W3, W4, W5</td>
</tr>
<tr>
<td class="bom_col_id">4</td>
<td class="bom_col_description">Wire, 0.25 mm², VT</td>
<td class="bom_col_qty">1</td>
<td class="bom_col_qty">1.0</td>
<td class="bom_col_unit">m</td>
<td class="bom_col_designators">W1, W2, W3, W4, W5</td>
</tr>
<tr>
<td class="bom_col_id">5</td>
<td class="bom_col_description">Wire, 0.25 mm², YE</td>
<td class="bom_col_qty">1</td>
<td class="bom_col_qty">1.0</td>
<td class="bom_col_unit">m</td>
<td class="bom_col_designators">W1, W2, W3, W4, W5</td>
</tr>

View File

@ -1,6 +1,6 @@
graph {
// Graph generated by WireViz 0.4.1
// https://github.com/wireviz/WireViz
// Graph generated by WireViz 0.4
// https://github.com/formatc1702/WireViz
graph [bgcolor="#FFFFFF" fontname=arial nodesep=0.33 rankdir=LR ranksep=2]
node [fillcolor="#FFFFFF" fontname=arial height=0 margin=0 shape=none style=filled width=0]
edge [fontname=arial style=bold]

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<meta name="generator" content="WireViz 0.4.1 - https://github.com/wireviz/WireViz">
<meta name="generator" content="WireViz 0.4 - https://github.com/formatc1702/WireViz">
<title>tutorial08</title>
<style>