From 5156e8752b3d4899520ae2e4f3cfdfe3d25c4af1 Mon Sep 17 00:00:00 2001 From: KV Date: Fri, 19 Jul 2024 19:04:01 +0200 Subject: [PATCH 1/3] Add Image.create() class method Allowing str and list input types in addition to None and dict. --- src/wireviz/DataClasses.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/wireviz/DataClasses.py b/src/wireviz/DataClasses.py index d14e4459..778ee288 100644 --- a/src/wireviz/DataClasses.py +++ b/src/wireviz/DataClasses.py @@ -113,6 +113,21 @@ def __post_init__(self): if self.width: self.height = self.width / aspect_ratio(self.src) + @classmethod + def create(cls, input: Union[None, dict, str, List[Union[dict, str]]]): + """Create class instance(s) from alternative YAML input types""" + if input in (None, "", []): + return None + if isinstance(input, list): + return [cls.create(entry) for entry in input] + if isinstance(input, str): + input = {"src": input} + if isinstance(input, dict): + return cls(**input) + raise TypeError( + f"Expected None, dict, str, or list as Image input, but got {type(input)}" + ) + @dataclass class AdditionalComponent: @@ -165,8 +180,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) + self.image = Image.create(self.image) self.ports_left = False self.ports_right = False @@ -274,8 +288,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) + self.image = Image.create(self.image) if isinstance(self.gauge, str): # gauge and unit specified try: From e193700ee49db6fbfea48e834c1249cef4898444 Mon Sep 17 00:00:00 2001 From: KV Date: Fri, 19 Jul 2024 19:07:28 +0200 Subject: [PATCH 2/3] Add and use html_image_rows() --- src/wireviz/Harness.py | 9 +++------ src/wireviz/wv_gv_html.py | 6 ++++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index c4af2364..fba7bee6 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -34,9 +34,8 @@ from wireviz.wv_gv_html import ( html_bgcolor, html_bgcolor_attr, - html_caption, html_colorbar, - html_image, + html_image_rows, html_line_breaks, nested_html_table, remove_links, @@ -203,8 +202,7 @@ def create_graph(self) -> Graph: translate_color(connector.color, self.options.color_mode) if connector.color else None, html_colorbar(connector.color)], '' if connector.style != 'simple' else None, - [html_image(connector.image)], - [html_caption(connector.image)]] + *html_image_rows(connector.image)] # fmt: on rows.extend(get_additional_component_table(self, connector)) @@ -326,8 +324,7 @@ def create_graph(self) -> Graph: translate_color(cable.color, self.options.color_mode) if cable.color else None, html_colorbar(cable.color)], '', - [html_image(cable.image)], - [html_caption(cable.image)]] + *html_image_rows(cable.image)] # fmt: on rows.extend(get_additional_component_table(self, cable)) diff --git a/src/wireviz/wv_gv_html.py b/src/wireviz/wv_gv_html.py index ec80aa74..574bd2d1 100644 --- a/src/wireviz/wv_gv_html.py +++ b/src/wireviz/wv_gv_html.py @@ -64,6 +64,12 @@ def html_colorbar(color: Color) -> str: return html_bgcolor(color, ' width="4"') if color else None +def html_image_rows(image): + from wireviz.wv_bom import make_list + + return sum([[[html_image(i)], [html_caption(i)]] for i in make_list(image)], []) + + def html_image(image): from wireviz.DataClasses import Image From d5224bbdc89a3c0bb20cabd84ad3f52d2b717856 Mon Sep 17 00:00:00 2001 From: Martin Rieder <74277074+martinrieder@users.noreply.github.com> Date: Mon, 14 Oct 2024 19:19:49 +0200 Subject: [PATCH 3/3] Update deprecated GitHub Actions and add Python versions (#408) Running 6 different Python versions (3.7 to 3.12) in parallel now. NOTE: This is in conflict with #309, but can be resolved easily in a later PR. GitHub Actions require an update: - actions/upload-artifact@v3 is scheduled for deprecation on November 30, 2024. - Similarly, v1/v2 are scheduled for deprecation on June 30, 2024. - Updating this comes with a breaking change in upload-artifact@v4: Uploading to the same named Artifact multiple times. Due to how Artifacts are created in this new version, it is no longer possible to upload to the same named Artifact multiple times. You must either split the uploads into multiple Artifacts with different names, or only upload once. Otherwise you will encounter an error. The artifact .zip files therefore have the python version added to their name. --- .github/workflows/main.yml | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 301ac18a..368d0977 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,29 +4,32 @@ on: [push, pull_request, workflow_dispatch] jobs: build: - runs-on: ubuntu-latest strategy: - max-parallel: 4 + max-parallel: 6 matrix: - python-version: [3.7, 3.8] + os: [ubuntu-latest] + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] + runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Setup Graphviz - uses: ts-graphviz/setup-graphviz@v1 + uses: ts-graphviz/setup-graphviz@v2 - name: Install dependencies run: | python -m pip install --upgrade pip pip install . - name: Create Examples - run: PYTHONPATH=$(pwd)/src:$PYTHONPATH cd src/wireviz/ && python build_examples.py + run: PYTHONPATH=$(pwd)/src/wireviz:$PYTHONPATH cd src/wireviz/ && python build_examples.py - name: Upload examples, demos, and tutorials - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: - name: examples-and-tutorials + name: examples-and-tutorials-v${{ matrix.python-version }} path: | examples/ - tutorial/ \ No newline at end of file + tutorial/ + if-no-files-found: error +