From ccc9d0ebf8eb5b161c83d85060e741dd66bac44f Mon Sep 17 00:00:00 2001 From: Martin Rieder <74277074+martinrieder@users.noreply.github.com> Date: Sun, 14 Jul 2024 21:44:53 +0200 Subject: [PATCH 1/8] Update main.yml for Create Examples GH Actions actions/upload-artifact@v3 is scheduled for deprecation on November 30, 2024. Learn more. Similarly, v1/v2 are scheduled for deprecation on June 30, 2024. Please update your workflow to use v4 of the artifact actions. --- .github/workflows/main.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 301ac18a..ad0521db 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,25 +8,26 @@ jobs: strategy: max-parallel: 4 matrix: - python-version: [3.7, 3.8] + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] 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@v3 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 setuptools 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 path: | examples/ - tutorial/ \ No newline at end of file + tutorial/ From c18e31140d2085f27c31f104ea6560656e5def8d Mon Sep 17 00:00:00 2001 From: Martin Rieder <74277074+martinrieder@users.noreply.github.com> Date: Sun, 14 Jul 2024 22:07:46 +0200 Subject: [PATCH 2/8] Fix uploading artifacts 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. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ad0521db..d40903b6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,7 +27,7 @@ jobs: - name: Upload examples, demos, and tutorials uses: actions/upload-artifact@v4 with: - name: examples-and-tutorials + name: examples-and-tutorials-${{ matrix.os }}-${{ matrix.version }} path: | examples/ tutorial/ From c54835a0b485377a06e0fb9e4b0e7ded2d3f7acb Mon Sep 17 00:00:00 2001 From: Martin Rieder <74277074+martinrieder@users.noreply.github.com> Date: Sun, 14 Jul 2024 22:14:13 +0200 Subject: [PATCH 3/8] Fix matrix references --- .github/workflows/main.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d40903b6..06df9455 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,11 +4,12 @@ on: [push, pull_request, workflow_dispatch] jobs: build: - runs-on: ubuntu-latest strategy: max-parallel: 4 matrix: + 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@v4 - name: Set up Python ${{ matrix.python-version }} @@ -27,7 +28,7 @@ jobs: - name: Upload examples, demos, and tutorials uses: actions/upload-artifact@v4 with: - name: examples-and-tutorials-${{ matrix.os }}-${{ matrix.version }} + name: examples-and-tutorials-v${{ matrix.python-version }} path: | examples/ tutorial/ From 9420b1a9ecde7739d73ec0dbbe8f86d6abc12919 Mon Sep 17 00:00:00 2001 From: Martin Rieder <74277074+martinrieder@users.noreply.github.com> Date: Sun, 14 Jul 2024 22:21:04 +0200 Subject: [PATCH 4/8] Parallelize matrix runs --- .github/workflows/main.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 06df9455..6afb4d12 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,7 +5,7 @@ on: [push, pull_request, workflow_dispatch] jobs: build: strategy: - max-parallel: 4 + max-parallel: 6 matrix: os: [ubuntu-latest] python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] @@ -21,7 +21,6 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install setuptools pip install . - name: Create Examples run: PYTHONPATH=$(pwd)/src/wireviz:$PYTHONPATH cd src/wireviz/ && python build_examples.py From f5f73178c7e48270acb80daaec6e95f33987addb Mon Sep 17 00:00:00 2001 From: Martin Rieder <74277074+martinrieder@users.noreply.github.com> Date: Sun, 14 Jul 2024 22:23:46 +0200 Subject: [PATCH 5/8] Update setup-python@v5 --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6afb4d12..c24a2db5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Setup Graphviz From 4abd7abcd3b5ea04bbd5904651790cad8c8dfd78 Mon Sep 17 00:00:00 2001 From: Martin Rieder <74277074+martinrieder@users.noreply.github.com> Date: Mon, 15 Jul 2024 03:22:03 +0200 Subject: [PATCH 6/8] Add if-no-files-found: error --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c24a2db5..368d0977 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -31,3 +31,5 @@ jobs: path: | examples/ tutorial/ + if-no-files-found: error + From ee1beebd1a1cec4ebd5f865b9c0da6e6c07d843d Mon Sep 17 00:00:00 2001 From: KV Date: Fri, 19 Jul 2024 19:04:01 +0200 Subject: [PATCH 7/8] 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 23955101339b6c1a1617145fa94a2ac2feb1bda5 Mon Sep 17 00:00:00 2001 From: KV Date: Fri, 19 Jul 2024 19:07:28 +0200 Subject: [PATCH 8/8] 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