Skip to content
Draft
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
269 changes: 203 additions & 66 deletions pixi.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ classifiers = [
requires-python = ">=3.10"
dependencies = [
"defusedxml",
"ewokscore<5",
"reportlab",
"typing-extensions; python_version < '3.11'",
"xmltodict",
"pyelk @ git+https://github.com/LudoBroche/pyelk.git@ewoksdraw-modifications",
"ewokscore @ git+https://github.com/ewoks-kit/ewokscore",
]

[project.urls]
Expand Down
7 changes: 4 additions & 3 deletions src/ewoksdraw/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from pathlib import Path

from ewokscore.graph import TaskGraph
from ewokscore.graph.inputs import _get_all_node_inputs
from ewokscore.graph.inputs import _get_all_task_output_names
from ewokscore.graph.inputs import node_inputs as get_node_inputs

from .svg.svg_canvas import SvgCanvas
from .svg.svg_task import SvgTask
Expand All @@ -15,14 +15,15 @@
def build_svg_task_group(graph: TaskGraph) -> SvgTaskGroup:
svg_tasks = {}
for node_id, node_attrs in graph.graph.nodes.items():
node_inputs = _get_all_node_inputs(node_id, node_attrs)
node_inputs = get_node_inputs(node_id, node_attrs)
node_outputs = _get_all_task_output_names(
node_attrs["task_type"], node_attrs["task_identifier"]
)
svg_tasks[node_id] = SvgTask(
task_name=node_id,
input_names=[n.name for n in node_inputs],
input_names=[n.name for n in node_inputs.inputs],
output_names=node_outputs,
import_error=bool(node_inputs.import_error),
)
return SvgTaskGroup(svg_tasks, horizontal_gap=GAP, group_id=str(graph.graph_id))

Expand Down
4 changes: 2 additions & 2 deletions src/ewoksdraw/css_styles/css_background.css

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran prettier on the CSS in a separate commit to have consistent formatting of the CSS

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.background {
fill: var(--bg-color);
}
fill: var(--bg-color);
}
14 changes: 7 additions & 7 deletions src/ewoksdraw/css_styles/css_link_cubic_bezier.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.link_cubic_bezier {
fill: none;
stroke: var(--stroke-color);
stroke-width: 1.5;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: none;
}
fill: none;
stroke: var(--stroke-color);
stroke-width: 1.5;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: none;
}
2 changes: 1 addition & 1 deletion src/ewoksdraw/css_styles/css_task_anchor_link.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.task_anchor_link {
fill: var(--link-color);
fill: var(--link-color);
}
14 changes: 9 additions & 5 deletions src/ewoksdraw/css_styles/css_task_box.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
.task_box {
fill: var(--transparent);
stroke: var(--stroke-color);
stroke-width: var(--stroke-width);
rx: 0.5%;
ry: 0.5%;
fill: var(--transparent);
stroke: var(--stroke-color);
stroke-width: var(--stroke-width);
rx: 0.5%;
ry: 0.5%;
}

.task_box[data-import-error=''] {
stroke: var(--error);
}
4 changes: 4 additions & 0 deletions src/ewoksdraw/css_styles/css_task_line.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
stroke: var(--stroke-color);
stroke-width: var(--stroke-width);
}

.task_line[data-import-error=''] {
stroke: var(--error);
}
6 changes: 3 additions & 3 deletions src/ewoksdraw/css_styles/css_task_text_io.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.task_text_io {
font-family: Helvetica, sans-serif;
fill: var(--text-color);
}
font-family: Helvetica, sans-serif;
fill: var(--text-color);
}
6 changes: 3 additions & 3 deletions src/ewoksdraw/css_styles/css_task_title.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.task_title {
font-family: Helvetica, sans-serif;
fill: var(--text-color);
}
font-family: Helvetica, sans-serif;
fill: var(--text-color);
}
15 changes: 8 additions & 7 deletions src/ewoksdraw/css_styles/root.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
.ewoksdraw {
--bg-color: rgb(0, 0, 0);
--link-color: rgb(176, 147, 255);
--stroke-color: rgb(255, 255, 255);
--stroke-width: 1;
--text-color: rgb(255, 255, 255);
--transparent: rgba(0, 0, 0, 0)
}
--bg-color: rgb(0, 0, 0);
--link-color: rgb(176, 147, 255);
--error: rgb(255, 0, 0);
--stroke-color: rgb(255, 255, 255);
--stroke-width: 1;
--text-color: rgb(255, 255, 255);
--transparent: rgba(0, 0, 0, 0);
}
5 changes: 5 additions & 0 deletions src/ewoksdraw/svg/svg_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(
task_name: str,
input_names: list[str],
output_names: list[str],
import_error: bool = False,
):
super().__init__(group_id=task_name)

Expand All @@ -46,13 +47,17 @@ def __init__(
self._interspace_input_output = IO_INTER_IO_MARGIN
self._title = SvgTaskTitle(text=task_name, x=0, y=0)
self._box = SvgTaskBox(x=0, y=0)
if import_error:
self._box.set_attr("data-import-error", "")
self._inputs = SvgTaskIOGroup(
list_io=input_names, io_type="input", vertical_spacing=8
)
self._outputs = SvgTaskIOGroup(
list_io=output_names, io_type="output", vertical_spacing=8
)
self._line_title = SvgTaskLine(x1=0, y1=0, x2=0, y2=0)
if import_error:
self._line_title.set_attr("data-import-error", "")
self._init_elements()

def _init_elements(self) -> None:
Expand Down
41 changes: 41 additions & 0 deletions src/ewoksdraw/tests/resources/workflow1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"graph": { "id": "demo", "label": "demo", "schema_version": "1.2" },
"nodes": [
{
"id": "task1a",
"default_inputs": [
{ "name": "a", "value": 0 },
{ "name": "b", "value": 10 }
],
"task_type": "class",
"task_identifier": "ewokscore.tests.examples.tasks.sumtask.SumTask"
},
{
"id": "task1b",
"default_inputs": [
{ "name": "a", "value": 1 },
{ "name": "b", "value": 2 }
],
"task_type": "class",
"task_identifier": "ewokscore.tests.examples.tasks.sumtask.SumTask"
},
{
"id": "task2",
"default_inputs": [{ "name": "delay", "value": 1 }],
"task_type": "class",
"task_identifier": "not.a.task"
}
],
"links": [
{
"source": "task1a",
"target": "task2",
"data_mapping": [{ "target_input": "result", "source_output": "a" }]
},
{
"source": "task1b",
"target": "task2",
"data_mapping": [{ "source_output": "result", "target_input": "b" }]
}
]
}
19 changes: 19 additions & 0 deletions src/ewoksdraw/tests/test_graph_to_svg.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from pathlib import Path
from xml.etree.ElementTree import Element

Expand Down Expand Up @@ -34,3 +35,21 @@ def test_groups_are_matching_nodes(graph_name: str, tmp_path: Path) -> None:
for node_name in ewoksgraph.graph.nodes:
svg_task = _find_svg_group(task_group, str(node_name))
assert svg_task[0].text == node_name


def test_workflow_with_non_importable_task(tmp_path: Path, caplog) -> None:
output_path = tmp_path / "workflow1.svg"

ewoksgraph = load_graph(Path(__file__).parent / "resources" / "workflow1.json")

with caplog.at_level(logging.WARNING):
graph_to_svg(ewoksgraph, output_path)

assert "Cannot import 'not.a.task': No module named 'not'" in caplog.text
assert output_path.is_file()

tree = ElementTree.parse(output_path)
task_group = _find_svg_group(tree.getroot(), str(ewoksgraph.graph_id))
for node_name in ewoksgraph.graph.nodes:
svg_task = _find_svg_group(task_group, str(node_name))
assert svg_task[0].text == node_name
Loading