54
54
#from textwrap import dedent
55
55
56
56
# For type-hinting
57
- from typing import List , Set , Dict , Tuple , Optional , Iterable
57
+ # from typing import List, Set, Dict, Tuple, Optional, Iterable
58
58
59
59
try : # pragma: no cover
60
60
# @final decorator, requires Python 3.8.x
67
67
import shlex
68
68
69
69
from configparserenhanced import *
70
+ from configparserenhanced import TypedProperty
70
71
71
72
from .SetProgramOptions import SetProgramOptions
72
73
from .SetProgramOptions import ExpandVarsInText
80
81
# ===============================
81
82
82
83
83
-
84
84
class ExpandVarsInTextCMake (ExpandVarsInText ):
85
85
"""
86
86
Extends ``ExpandVarsInText`` class to add in support for a ``CMAKE`` generator.
87
87
"""
88
88
89
+ # Typed Property `_bashgen_unhandled_cmake_var_eventtype`:
90
+ # sets the exception_control_event level for when an unresolved
91
+ # `CMake` var is encountered by the BASH generator.
92
+ _bashgen_unhandled_cmake_var_eventtype = \
93
+ TypedProperty .typed_property ("_bashgen_unhandled_cmake_var_eventtype" ,
94
+ expected_type = str ,
95
+ default = "MINOR" ,
96
+ internal_type = str )
97
+
89
98
def __init__ (self ):
90
99
self .exception_control_level = 3
91
100
@@ -112,9 +121,10 @@ def _fieldhandler_BASH_CMAKE(self, field):
112
121
else :
113
122
# If self.exception_control_level is >= 4 then we'll raise the error
114
123
# instead of sending a warning.
115
- msg = f"Unhandled variable expansion for `{ field .varname } ` in a BASH file."
124
+ # Change this to `CATASTROPHIC` to always throw the error.
125
+ msg = f"Unresolved variable expansion for `{ field .varname } ` in a BASH file."
116
126
msg += " CMake variables are only valid in a CMake fragment file."
117
- self .exception_control_event ("MINOR" , ValueError , msg )
127
+ self .exception_control_event (self . _bashgen_unhandled_cmake_var_eventtype , ValueError , msg )
118
128
output = ""
119
129
return output
120
130
@@ -331,7 +341,7 @@ def handler_initialize(self, section_name: str, handler_parameters) -> int:
331
341
# ---------------------------------------------------------------
332
342
333
343
@ConfigParserEnhanced .operation_handler
334
- def _handler_opt_set_cmake_var (self , section_name , handler_parameters ) -> int :
344
+ def _handler_opt_set_cmake_var (self , section_name : str , handler_parameters ) -> int :
335
345
"""Handler for ``opt-set-cmake-var``
336
346
337
347
Called By: ``configparserenhanced.ConfigParserEnhanced`` parser.
0 commit comments