From dfcbffe32295a4ebc0f9ab2c7f979f45d3415dc5 Mon Sep 17 00:00:00 2001 From: Maarten Sebregts Date: Wed, 15 Jul 2026 11:23:23 +0200 Subject: [PATCH] Update timeline annotations Fixes #57 --- ymmsl/v0_2/ports.py | 17 +++++++++-------- ymmsl/v0_2/tests/test_ports.py | 18 ++++++++++-------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/ymmsl/v0_2/ports.py b/ymmsl/v0_2/ports.py index 5bfa6a0..62af6d8 100644 --- a/ymmsl/v0_2/ports.py +++ b/ymmsl/v0_2/ports.py @@ -196,14 +196,14 @@ class Ports: ports: f_init: a o_f: b - +timeline1: + timeline timeline1: o_i: c d s: e - +timeline2: + timeline timeline2: o_i: f s: g h - Note that the + symbol is not a part of the timeline name, it's just there to + Note that 'timeline ' is not a part of the timeline name, it's just there to make it a bit easier to distinguish timelines from operators. On the Python side, this class acts like a dictionary mapping port names to Port @@ -351,17 +351,18 @@ def _yatiml_init( self._add_ports(Operator.S, s) for tl_tag, tl_ports in _yatiml_extra.items(): - if not tl_tag.startswith("+"): + if not tl_tag.startswith("timeline "): raise RuntimeError( f'Invalid operator "{tl_tag}". Please use f_init, o_i, s, or' - " o_f, or prepend a + to the timeline name." + ' o_f, or prepend "timeline " to the timeline name.' ) + tl_tag = tl_tag.removeprefix("timeline ") if "o_i" in tl_ports: - self._add_ports(Operator.O_I, tl_ports["o_i"], tl_tag[1:]) + self._add_ports(Operator.O_I, tl_ports["o_i"], tl_tag) if "s" in tl_ports: - self._add_ports(Operator.S, tl_ports["s"], tl_tag[1:]) + self._add_ports(Operator.S, tl_ports["s"], tl_tag) additional_keys = set(tl_ports.keys()) - {"o_i", "s"} if additional_keys: @@ -406,7 +407,7 @@ def unique(timelines: List[Timeline]) -> List[Timeline]: timeline_attrs: _PortsSubAttrs = OrderedDict() add_ports(timeline_attrs, Operator.O_I, "o_i", timeline) add_ports(timeline_attrs, Operator.S, "s", timeline) - attrs[f"+{timeline}"] = timeline_attrs + attrs[f"timeline {timeline}"] = timeline_attrs add_ports(attrs, Operator.O_F, "o_f", Timeline("")) return attrs diff --git a/ymmsl/v0_2/tests/test_ports.py b/ymmsl/v0_2/tests/test_ports.py index 438358b..96642c7 100644 --- a/ymmsl/v0_2/tests/test_ports.py +++ b/ymmsl/v0_2/tests/test_ports.py @@ -212,10 +212,10 @@ def test_load_ports_with_timelines() -> None: text = ( "f_init: a b\n" "o_f: c\n" - "+timeline1:\n" + "timeline timeline1:\n" " o_i: d\n" " s: e f\n" - "+timeline2:\n" + "timeline timeline2:\n" " o_i: g h\n" ) @@ -245,7 +245,9 @@ def test_load_ports_invalid_operator() -> None: def test_load_ports_invalid_timeline() -> None: load = yatiml.load_function(Ports, Port, Operator, Timeline) - text = "f_init: a b\n+timeline1:\n o_i: d\n s: e f\ntimeline2:\n o_i: g h\n" + text = ( + "f_init: a b\ntimeline timeline1:\n o_i: d\n s: e f\ntimeline2:\n o_i: g h\n" + ) with pytest.raises(yatiml.RecognitionError): load(text) @@ -256,12 +258,12 @@ def test_load_ports_invalid_timeline_operator() -> None: text = ( "f_init: a b\n" - "+timeline1:\n" + "timeline timeline1:\n" " o_i: d\n" " s: e f\n" - "+timeline2:\n" + "timeline timeline2:\n" " o_i: g h\n" - " +timeline3:\n" + " timeline timeline3:\n" " o_i: i\n" ) @@ -326,10 +328,10 @@ def test_dump_ports_with_timelines() -> None: assert text == ( "f_init: init\n" - "+timeline1:\n" + "timeline timeline1:\n" " o_i: out1\n" " s: in1\n" - "+timeline2:\n" + "timeline timeline2:\n" " o_i: out2\n" " s: in2\n" "o_f: final\n"