Skip to content

Commit 3279ab1

Browse files
committed
Support f-strings in BO MessageMap
Fixes #2
1 parent fa425f6 commit 3279ab1

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

src/intersystems_pyprod/_parser.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from ._method_stubs import STUBS
1414

15+
1516
TARGET_SUPERCLASSES = [
1617
"InboundAdapter",
1718
"BusinessService",
@@ -215,7 +216,7 @@ def generate_custom_classes(tree, script_name, folder_name, iris_package_name, o
215216

216217
all_classes = {}
217218
for cls_name, supercls, node, hostname in classes:
218-
props_lines, settings_list, message_map_methods = extract_props_and_settings(node, real_path)
219+
props_lines, settings_list, message_map_methods = extract_props_and_settings(node, real_path, loaded_module)
219220
props_block = "\n".join(props_lines) if props_lines else ""
220221
params_settings = f'Parameter SETTINGS = "{",".join(settings_list)}";' if settings_list else ""
221222
param_lines = extract_params(node)
@@ -424,7 +425,7 @@ def message_map_xdata(MessageMap):
424425

425426

426427

427-
def extract_props_and_settings(node: ast.ClassDef, real_path):
428+
def extract_props_and_settings(node: ast.ClassDef, real_path, loaded_module):
428429

429430
props, settings, message_map_method = [], [], []
430431

@@ -440,10 +441,8 @@ def extract_props_and_settings(node: ast.ClassDef, real_path):
440441
else:
441442
continue
442443

443-
if target_node.id.lower() == "messagemap":
444-
message_map_as_dictionary = {
445-
k.value: v.value for k, v in zip(call_node.keys, call_node.values)
446-
}
444+
if snake_to_pascal(msg_map:= target_node.id) == "MessageMap":
445+
message_map_as_dictionary = getattr(getattr(loaded_module,node.name),msg_map)
447446
message_map_as_xdata_string = message_map_xdata(message_map_as_dictionary)
448447
props.append(message_map_as_xdata_string)
449448
for msg_type, method in message_map_as_dictionary.items():
@@ -531,15 +530,15 @@ def find_ossubclasses(tree):
531530
return result
532531

533532

534-
def generate_os_classes(tree, script_name, folder_name, iris_package_name, output, script_path, manual, real_path, python_library):
533+
def generate_os_classes(tree, script_name, folder_name, iris_package_name, output, script_path, manual, real_path, python_library, loaded_module):
535534
classes = find_ossubclasses(tree)
536535
class_tmpl = STUBS.get("ClassDefinition")
537536
common_oninit = STUBS.get("Common", {}).get("OnInit", "")
538537
bp_oninit = STUBS.get("Common", {}).get("OnInitBP", "")
539538

540539
all_classes = {}
541540
for cls_name, supercls, node in classes:
542-
props_lines, settings_list, message_map_methods = extract_props_and_settings(node, real_path)
541+
props_lines, settings_list, message_map_methods = extract_props_and_settings(node, real_path, loaded_module)
543542
props_block = "\n".join(props_lines) if props_lines else ""
544543
params_settings = f'Parameter SETTINGS = "{",".join(settings_list)}";' if settings_list else ""
545544
param_lines = extract_params(node)
@@ -990,6 +989,7 @@ def main(argv: list[str] = None):
990989
args.manual,
991990
real_path,
992991
python_library,
992+
loaded_module
993993
)
994994

995995
# Custom subclasses of your runtime types

tests/helpers/AllPyComponents/AllPyComponents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def OnRequest(self, request):
5151
class CustomBO(BusinessOperation):
5252
ADAPTER = IRISParameter("AllPyComponents.CustomOutAdapter")
5353
MessageMap = {
54-
"AllPyComponents.MyJsonData": "BOmethod1",
54+
f"{iris_package_name}.MyJsonData": "BOmethod1",
5555
"AllPyComponents.MyPickleData": "BOmethod2"
5656
}
5757

0 commit comments

Comments
 (0)