Skip to content
Merged

Dev #65

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
2 changes: 1 addition & 1 deletion simulations/simul_flow_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

flow.add_arrow_style(stem="-", brackets=("[", "]"), separator=",", tip=">")
flow.add_arrow_style(stem="=", brackets=("{", "}"), separator=";", tip=")")
flow.ready()
flow.compile_arrow_patterns()
print(flow.arrows)
tests = [
"/all",
Expand Down
2 changes: 1 addition & 1 deletion simulations/simul_flow_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
Trigger = flow.triggers()
flow.add_arrow_style(stem="-", brackets=("[", "]"), separator=",", tip=">")
flow.add_arrow_style(stem="=", brackets=("{", "}"), separator=";", tip=")")
flow.ready() # regex
flow.compile_arrow_patterns() # regex

# List of available Action classes
ACTIONS = [Move, Stay, Test]
Expand Down
2 changes: 1 addition & 1 deletion summoner/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def _apply_config(self, config: dict[str,Union[str,dict[str,Union[str,dict]]]]):
self.logger.warning(f"queue_maxsize < concurrency_limit; back-pressure will throttle producers at {self.send_queue_maxsize}")

def initialize(self):
self._flow.ready()
self._flow.compile_arrow_patterns()

def flow(self) -> Flow:
return self._flow
Expand Down
18 changes: 18 additions & 0 deletions summoner/protocol/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from typing import Optional, Any, Pattern
from .triggers import load_triggers
from .process import Node, ArrowStyle, ParsedRoute
from typing_extensions import deprecated
import warnings

# variable names or commands used in flow transitions
_TOKEN_RE = re.compile(r"""
Expand Down Expand Up @@ -216,7 +218,23 @@ def _parse_standalone(self, text: str) -> ParsedRoute:
style=None
)

def compile_arrow_patterns(self):
"""
Compile (or recompile) regex patterns from the current arrow styles.
Safe to call multiple times; no effect if already compiled.
"""
if self.in_use:
self._prepare_regex()

@deprecated("Flow.ready() is deprecated. Use Flow.compile_arrow_patterns() instead. "
"When using SummonerClient, patterns are compiled automatically during registration.")
def ready(self):
warnings.warn(
"Flow.ready() is deprecated; use Flow.compile_arrow_patterns() instead. "
"In SummonerClient, you generally don't need to call this.",
category=DeprecationWarning,
stacklevel=2,
)
if self.in_use:
self._prepare_regex()

Expand Down
1 change: 1 addition & 0 deletions summoner/protocol/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def cast_v0_0_1(val: Any, expected: Any) -> Any:
# Register version 0.0.1
register_envelope_version("0.0.1", parse_v0_0_1, cast_v0_0_1)
register_envelope_version("1.0.0", parse_v0_0_1, cast_v0_0_1)
register_envelope_version("1.0.1", parse_v0_0_1, cast_v0_0_1)


def wrap_with_types(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def make_flow():
flow.activate()
flow.add_arrow_style(stem="-", brackets=("[", "]"), separator=",", tip=">")
flow.add_arrow_style(stem="=", brackets=("{", "}"), separator=";", tip=")")
flow.ready()
flow.compile_arrow_patterns()
return flow


Expand Down
2 changes: 1 addition & 1 deletion tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def test_collect_activations_simple_case():
# Setup flow and parsed route for "A --> B"
flow = Flow().activate()
flow.add_arrow_style("-", ("[", "]"), ",", ">")
flow.ready()
flow.compile_arrow_patterns()
pr = flow.parse_route("A --> B")
# Fake receiver function
async def fn(msg):
Expand Down