Skip to content

Commit 49e0db8

Browse files
fix writing events to python
1 parent 3f6f316 commit 49e0db8

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

src/python/convert_to_python.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,34 @@ def make_events_data(data: dict) -> list[dict]:
160160
event["expected_arguments"] = signature(event_class).parameters
161161

162162
if "func_evt" in event:
163-
# replace the name of the function by something unique
164-
func_evt = event["func_evt"]
165-
func_evt = func_evt.replace("def func_evt", f"def {event['name']}_func_evt")
166-
event["func_evt"] = f"{event['name']}_func_evt"
167-
event["func_evt_desc"] = func_evt
168-
if "func_act" in event:
169-
# replace the name of the function by something unique
170-
func_act = event["func_act"]
171-
func_act = func_act.replace("def func_act", f"def {event['name']}_func_act")
172-
event["func_act"] = f"{event['name']}_func_act"
173-
event["func_act_desc"] = func_act
163+
# if the whole function in defined in the event, make sure it has a unique identifier
164+
if event["func_evt"].startswith("def"):
165+
# replace the name of the function by something unique
166+
func_evt = event["func_evt_desc"]
167+
func_evt = func_evt.replace(
168+
"def func_evt", f"def {event['name']}_func_evt"
169+
)
170+
event["func_evt"] = f"{event['name']}_func_evt"
171+
event["func_evt_desc"] = func_evt
172+
# otherwise assume it was defined in the global namespace
173+
# and just copy the function identifier
174+
else:
175+
event["func_evt_desc"] = event["func_evt"]
174176

177+
if "func_act" in event:
178+
# if the whole function in defined in the event, make sure it has a unique identifier
179+
if event["func_act"].startswith("def"):
180+
# replace the name of the function by something unique
181+
func_act = event["func_act_desc"]
182+
func_act = func_act.replace(
183+
"def func_act", f"def {event['name']}_func_act"
184+
)
185+
event["func_act"] = f"{event['name']}_func_act"
186+
event["func_act_desc"] = func_act
187+
# otherwise assume it was defined in the global namespace
188+
# and just copy the function identifier
189+
else:
190+
event["func_act_desc"] = event["func_act"]
175191
return data["events"]
176192

177193

src/python/templates/block_macros.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,16 @@
4242

4343
{% macro create_event(event) -%}
4444
{% if "func_evt" in event %}
45+
{% if event["func_evt_desc"].startswith("def") %}
4546
{{ event["func_evt_desc"] }}
4647
{% endif %}
48+
{% endif %}
4749

4850
{% if "func_act" in event %}
51+
{% if event["func_act_desc"].startswith("def") %}
4952
{{ event["func_act_desc"] }}
5053
{% endif %}
54+
{% endif %}
5155

5256
{{ event["name"] }} = {{ event["module_name"] }}.{{ event["class_name"] }}(
5357
{%- for arg in event["expected_arguments"] %}

0 commit comments

Comments
 (0)