From 8821bac18a2a9b1c08706e1e428edc2ffb20abf6 Mon Sep 17 00:00:00 2001 From: Jacqueline Deans Date: Mon, 23 Jan 2023 08:50:13 -0600 Subject: [PATCH] Handle empty PYTHON_MODULE in header comment (#1432) --- .../Model-Source-Code.md | 2 +- libexec/trick/pm/html.pm | 2 +- .../RUN_test/unit_test.py | 7 ++++ test/SIM_python_namespace/S_define | 4 ++- test/SIM_python_namespace/models/TrickFood.hh | 32 +++++++++++++++++++ 5 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 test/SIM_python_namespace/models/TrickFood.hh diff --git a/docs/documentation/building_a_simulation/Model-Source-Code.md b/docs/documentation/building_a_simulation/Model-Source-Code.md index 06efc40c..15c56389 100644 --- a/docs/documentation/building_a_simulation/Model-Source-Code.md +++ b/docs/documentation/building_a_simulation/Model-Source-Code.md @@ -162,7 +162,7 @@ The `ICG IGNORE TYPES` field lists the structs or classes to be ignored. Any par ###### `PYTHON_MODULE` -Specifying a `python_module` name will place any class/struct and function definitions in this header file in a python module of the same name. All classes and functions are flattened into the python `trick` namespace by default. This capability allows users to avoid possible name collisions between names when they are flattened. +Specifying a `python_module` name will place any class/struct and function definitions in this header file in a python module of the same name. All classes and functions are flattened into the python `trick` namespace by default. This capability allows users to avoid possible name collisions between names when they are flattened. An empty `python_module` statement will be ignored. ##### Compiler Directives diff --git a/libexec/trick/pm/html.pm b/libexec/trick/pm/html.pm index a6da5c62..d9524373 100644 --- a/libexec/trick/pm/html.pm +++ b/libexec/trick/pm/html.pm @@ -31,7 +31,7 @@ sub extract_trick_header($$$$) { $header{icg_ignore} = $2 if $trick_header =~ /ICG[ _]IGNORE[ _]TYPE(S)?:[^(]*(.*?)\)([A-Z _\t\n\r]+:|[ \t\n\r]*$)/si ; $header{swig} = $1 if $trick_header =~ /SWIG:[^(]*\((.*?)\)([A-Z _\t\n\r]+:|[ \t\n\r]*$)/si ; $header{default_data} = $1 if $trick_header =~ /DEFAULT[ _]DATA:[^(]*(.*?)\)([A-Z _\t\n\r]+:|[ \t\n\r]*$)/si ; - $header{python_module} = $1 if $trick_header =~ /PYTHON[ _]MODULE:[^(]*\((.*?)\)([A-Z _\t\n\r]+:|[ \t\n\r]*$)/si ; + $header{python_module} = $1 if $trick_header =~ /PYTHON[ _]MODULE:[^(]*\((.+?)\)([A-Z _\t\n\r]+:|[ \t\n\r]*$)/si ; $header{programmers} = $1 if $trick_header =~ /PROGRAMMERS:[^(]*(.*?)\)([A-Z _\t\n\r]+:|[ \t\n\r]*$)/si ; $header{language} = $1 if $trick_header =~ /LANGUAGE:[^(]*(.*?)\)([A-Z _\t\n\r]+:|[ \t\n\r]*$)/si ; diff --git a/test/SIM_python_namespace/RUN_test/unit_test.py b/test/SIM_python_namespace/RUN_test/unit_test.py index b50e2da3..00b5c529 100644 --- a/test/SIM_python_namespace/RUN_test/unit_test.py +++ b/test/SIM_python_namespace/RUN_test/unit_test.py @@ -43,6 +43,13 @@ def main(): yummy.yummy = trick.Foo.Doughnuts TRICK_EXPECT_EQ( yummy.yummy , 2, test_suite , "additional file in same namespace" ) + # new class from TrickFood + trickfood = trick.Food() + trickfood.print_me() + TRICK_EXPECT_EQ( trickfood.fast , 2, test_suite , "blank python_module statement" ) + trickfood.fast = trick.Pizza + TRICK_EXPECT_EQ( trickfood.fast , 0, test_suite , "blank python_module statement" ) + if __name__ == "__main__": main() diff --git a/test/SIM_python_namespace/S_define b/test/SIM_python_namespace/S_define index ff42c34c..ec9da89a 100644 --- a/test/SIM_python_namespace/S_define +++ b/test/SIM_python_namespace/S_define @@ -1,6 +1,6 @@ /************************TRICK HEADER************************* PURPOSE: - (blah blah blah) + (Test different combinations of Python modules and C++ namespaces) *************************************************************/ #include "sim_objects/default_trick_sys.sm" @@ -9,6 +9,7 @@ PURPOSE: ##include "FooInnerFood.hh" ##include "BarFood.hh" ##include "FooYummyFood.hh" +##include "TrickFood.hh" class SimObj : public Trick::SimObject { @@ -17,6 +18,7 @@ class SimObj : public Trick::SimObject { Foo::Inner::Food foo_inner_food ; Bar::Food bar_food ; Foo::YummyFood foo_yummyfood ; + Food trick_food; /** Constructor to add the jobs */ SimObj() { diff --git a/test/SIM_python_namespace/models/TrickFood.hh b/test/SIM_python_namespace/models/TrickFood.hh new file mode 100644 index 00000000..0a86c475 --- /dev/null +++ b/test/SIM_python_namespace/models/TrickFood.hh @@ -0,0 +1,32 @@ +/** +@file + +@verbatim +PURPOSE: (Test that an empty PYTHON_MODULE won't cause errors or have any effect.) +PYTHON_MODULE: () +@endverbatim +*******************************************************************************/ + +#ifndef TRICKFOOD_HH +#define TRICKFOOD_HH + +#include + + + +enum Fast { + Pizza, + Burger, + Taco +}; + +class Food { + public: + Food() : fast(Taco) {} + void print_me() { std::cout << "Food::print_me!" << std::endl; } + Fast fast; +}; + + +#endif +