Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v0.4.1 #365

Merged
merged 36 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
9435fc2
Create PR to collect changes for v0.4.1-rc
kvid May 25, 2024
77061a0
Handle OSError(errno=EINVAL) that might be raised in Windows (#346)
kvid May 15, 2024
a89d04d
Add package_data to to setup() call in setup.py (#347)
kvid May 16, 2024
557122c
Look-up mated connectors before mate processing (#358)
kvid May 22, 2024
82751e4
Move mates processing above tweak processing (#358)
kvid May 29, 2024
7ae3fb3
Use output_name as default title (#361)
kvid May 23, 2024
a5f91e9
Add missing import of embed_svg_images (#363)
adaemmer May 24, 2024
2336231
Update APP_URL (#364)
kvid May 25, 2024
f474cdd
Add HTML template placeholders for filename (#371)
kvid May 26, 2024
ea26116
Add HTML template placeholder for diagram_png_base64 (#371)
kvid May 31, 2024
6488eb5
Avoid Graphviz error when hiding all pins (#375)
kvid Jun 5, 2024
088c603
Add documentation on template separator character
formatc1702 Jun 7, 2024
eed00e1
Add changelog for v0.4.1 (WIP)
formatc1702 Jun 7, 2024
795f332
Update changelog (WIP)
kvid Jun 7, 2024
c997bfe
Rename "sheetsize_default" to <!-- %template_sheetsize% --> (#380)
kvid Jun 9, 2024
6d772cf
Add non-empty label to avoid over-sized loops (#381)
kvid Jun 9, 2024
5cedba9
Explain unexpeced top-level type (#383)
kvid Jun 10, 2024
0e8ab7a
Catch also ValueError (#392)
martinrieder Jul 1, 2024
f2a1aa8
Update comment in src/wireviz/wireviz.py (#392)
martinrieder Jul 1, 2024
ee1bd78
Provide more information when raising exception
kvid Jul 4, 2024
70a33ed
Avoid reading diagram file to embed unless used (#371)
kvid May 31, 2024
fc7ea08
Add HTML output templates README.md (#371)
kvid Jun 5, 2024
6ba33fb
Rename diagram_png_base64 to diagram_png_b64 (#371)
kvid Jun 5, 2024
177eb9e
Add link from syntax.md to HTML output templates (#371)
kvid Jun 9, 2024
668ba72
Avoid decimal point and trailing zero for integer BOM quantities (#374)
kvid Jun 2, 2024
858b266
Update src/wireviz/wireviz.py (#383)
kvid Jun 12, 2024
42d10df
Catch OSError also with errno=None (#392)
martinrieder Jun 20, 2024
19cdff1
Avoid ResourceWarning: unclosed file (#395)
kvid Jun 23, 2024
ae03bd6
Add TODOs about utf-8 encoding/charset (#395)
kvid Jul 5, 2024
bde949b
Update changelog
kvid Jul 8, 2024
38ac237
Update changelog a bit more
kvid Jul 12, 2024
828de3f
Apply isort *.py ../../setup.py
kvid Jul 12, 2024
73f56b2
Apply black *.py ../../setup.py
kvid Jul 12, 2024
c73738e
Bump version to 0.4.1
formatc1702 Jul 13, 2024
a57c68a
Rebuild examples
formatc1702 Jul 13, 2024
5428646
Add v0.4.1 release date
formatc1702 Jul 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 65 additions & 43 deletions docs/CHANGELOG.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contribution Guidelines

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

## Submitting a new Issue

Expand All @@ -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/formatc1702/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/wireviz/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
Expand Down
2 changes: 1 addition & 1 deletion docs/buildscript.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!--
The following text is taken from #118
https://github.com/formatc1702/WireViz/pull/118
https://github.com/wireviz/WireViz/pull/118

TODO: write a better explaination -->

Expand Down
6 changes: 6 additions & 0 deletions docs/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ 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.


Expand Down Expand Up @@ -353,6 +355,7 @@ 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

Expand Down Expand Up @@ -387,6 +390,9 @@ If any component is defined in the `connectors` or `cables` sections but not ref
# 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 = '.'
```


Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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": [
Expand Down
95 changes: 44 additions & 51 deletions src/wireviz/Harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Tweak,
Side,
)
from wireviz.svgembed import embed_svg_images_file
from wireviz.svgembed import embed_svg_images, embed_svg_images_file
from wireviz.wv_bom import (
HEADER_MPN,
HEADER_PN,
Expand All @@ -44,11 +44,10 @@
)
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
Expand Down Expand Up @@ -172,7 +171,7 @@ def create_graph(self) -> Graph:
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",
Expand Down Expand Up @@ -253,6 +252,9 @@ def create_graph(self) -> Graph:

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
Expand Down Expand Up @@ -281,6 +283,7 @@ def create_graph(self) -> Graph:
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;
Expand Down Expand Up @@ -530,6 +533,38 @@ def create_graph(self) -> Graph:
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(
Expand Down Expand Up @@ -595,51 +630,9 @@ def typecheck(name: str, value: Any, expect: type) -> None:
typecheck("tweak.append", self.tweak.append, str)
dot.body.append(self.tweak.append)

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)
# 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.

return dot

Expand All @@ -664,7 +657,7 @@ def png(self):
return data.read()

@property
def svg(self):
def svg(self): # TODO?: Verify xml encoding="utf-8" in SVG?
graph = self.graph
return embed_svg_images(graph.pipe(format="svg").decode("utf-8"), Path.cwd())

Expand Down Expand Up @@ -699,7 +692,7 @@ def output(
# BOM output
bomlist = bom_list(self.bom())
if "tsv" in fmt:
open_file_write(f"{filename}.bom.tsv").write(tuplelist2tsv(bomlist))
file_write_text(f"{filename}.bom.tsv", tuplelist2tsv(bomlist))
if "csv" in fmt:
# TODO: implement CSV output (preferrably using CSV library)
print("CSV output is not yet supported")
Expand Down
4 changes: 2 additions & 2 deletions src/wireviz/__init__.py
Original file line number Diff line number Diff line change
@@ -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"
__version__ = "0.4.1-dev"

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/formatc1702/WireViz"
APP_URL = "https://github.com/wireviz/WireViz"
18 changes: 16 additions & 2 deletions src/wireviz/svgembed.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@
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

Expand Down Expand Up @@ -45,8 +59,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(
filename_out.write_text( # TODO?: Verify xml encoding="utf-8" in SVG?
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)
52 changes: 52 additions & 0 deletions src/wireviz/templates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 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.
2 changes: 1 addition & 1 deletion src/wireviz/templates/din-6771.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading