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

Test PR to check GitHub Actions for new/images #2

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 13 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
tutorial/
if-no-files-found: error

21 changes: 17 additions & 4 deletions src/wireviz/DataClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 3 additions & 6 deletions src/wireviz/Harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)],
'<!-- connector table -->' 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))
Expand Down Expand Up @@ -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)],
'<!-- wire table -->',
[html_image(cable.image)],
[html_caption(cable.image)]]
*html_image_rows(cable.image)]
# fmt: on

rows.extend(get_additional_component_table(self, cable))
Expand Down
6 changes: 6 additions & 0 deletions src/wireviz/wv_gv_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down