Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit c165985

Browse files
author
William McLendon
committed
Merge branch 'revisit-mr-12' into 'master'
TRILFRAME-121: Partial revert of changes from MR-12 See merge request trilinos-devops-consolidation/code/SetProgramOptions!14
2 parents ec84080 + 6b0d58c commit c165985

File tree

5 files changed

+91
-8
lines changed

5 files changed

+91
-8
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
## [0.3.1] <!-- YYYY-MM-DD --> [Unreleased]
2121
#### Added
2222
#### Changed
23+
- Revert(ish) the modifications from MR12 which removed the error when generating
24+
BASH output if there is an unhandled CMake variable left hanging around.
25+
Rather than make this an unavoidable error though, ExpandVarsInText now inherits
26+
from `configparserenhanced.ExceptionControl` and will raise a "MINOR"
27+
`exception_control_event` (i.e., throws if `exception_control_level` is 4 or greater).
28+
We also tie this _ecl_ to the _ecl_ of the `SetProgramOptions` class so changing this
29+
will affect whether or not the exception is raised or if the output returned is an
30+
empty string.
2331
#### Deprecated
2432
#### Removed
2533
#### Fixed

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ Merge Request Process
3636
4. Update unit tests to fully test your additions. We aim for 100% coverage on this project.
3737
5. Ensure unit tests and documentation build cleanly by running `exec-tests.sh`, `exec-makedoc.sh`
3838
and the _example_ applications in the repository.
39+
6. Run the `exec-reformat.py` script in the repository's root directory to update all formatting
40+
using the **[YAPF][2]** tool. This is optional but STRONGLY encouraged, we reserve the right to
41+
reject a merge request if this hasn't been run.
3942

4043
Code of Conduct
4144
===============

src/setprogramoptions/SetProgramOptions.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
sys.exit("Python %s.%s or later is required.\n" % (MIN_PYTHON))
7171

7272
from configparserenhanced import *
73+
import configparserenhanced.ExceptionControl
7374

7475
from .common import *
7576

@@ -92,7 +93,7 @@ class _VARTYPE_UNKNOWN(object):
9293

9394

9495

95-
class ExpandVarsInText(object):
96+
class ExpandVarsInText(ExceptionControl):
9697
"""
9798
Utility to identify and format variables that are found in a text string.
9899
@@ -106,7 +107,16 @@ class ExpandVarsInText(object):
106107
they're declaring. These are a variables declared in a *pseudo-language* not bash.
107108
"""
108109

110+
def __init__(self):
111+
self.exception_control_level = 4
112+
self.exception_control_compact_warnings = True
113+
109114
class VariableFieldData(object):
115+
"""
116+
This is essentially a dataclass that is used to pass field data around within
117+
the generators, etc. This captures the relevant fields from a given action
118+
entry.
119+
"""
110120
varfield = typed_property('varfield', expected_type=str, req_assign_before_use=True)
111121
varname = typed_property('varname', expected_type=str, req_assign_before_use=True)
112122
vartype = typed_property('vartype', expected_type=str, req_assign_before_use=True)
@@ -514,6 +524,9 @@ def _gen_option_entry(self, option_entry: dict, generator='bash') -> Union[str,
514524
if " " in value:
515525
value = '"' + value + '"'
516526

527+
# Update the var formatter's ECL to match the current value.
528+
self._var_formatter.exception_control_level = self.exception_control_level
529+
517530
# format the value
518531
formatter = self._var_formatter
519532
formatter.generator = generator

src/setprogramoptions/SetProgramOptionsCMake.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@
5252
import shlex
5353

5454
from configparserenhanced import *
55+
5556
from .SetProgramOptions import SetProgramOptions
5657
from .SetProgramOptions import ExpandVarsInText
5758

58-
5959
# ==============================
6060
# F R E E F U N C T I O N S
6161
# ==============================
@@ -71,12 +71,36 @@ class ExpandVarsInTextCMake(ExpandVarsInText):
7171
Extends ``ExpandVarsInText`` class to add in support for a ``CMAKE`` generator.
7272
"""
7373

74+
def __init__(self):
75+
self.exception_control_level = 3
76+
self.exception_control_compact_warnings = True
77+
7478
def _fieldhandler_BASH_CMAKE(self, field):
75-
"""Format CMAKE fields for the BASH generator."""
79+
"""
80+
Format CMAKE fields for the BASH generator.
81+
82+
Args:
83+
field (setprogramoptions.VariableFieldData): Stores the action entry's
84+
parameters and field information.
85+
86+
Raises:
87+
ValueError: A ``ValueError`` can be raised if we have an unresolved
88+
CMake variable in the ``.ini`` file (i.e., ``${FIELDNAME|CMAKE}``).
89+
By "unresolved" we mean that the CMake does not have some entry in
90+
the cache that resolves it down to either text or a BASH environment
91+
variable.
92+
This exception is skipped if ``self.exception_control_level`` is set
93+
to 3 or lower. If it is 4 or higher then the exception is raised.
94+
"""
7695
output = field.varfield
7796
if field.varname in self.owner._var_formatter_cache.keys():
7897
output = self.owner._var_formatter_cache[field.varname].strip('"')
7998
else:
99+
# If self.exception_control_level is >= 4 then we'll raise the error
100+
# instead of sending a warning.
101+
msg = f"Unhandled variable expansion for `{field.varname}` in a BASH file."
102+
msg += " CMake variables are only valid in a CMake fragment file."
103+
self.exception_control_event("MINOR", ValueError, msg)
80104
output = ""
81105
return output
82106

src/setprogramoptions/unittests/test_SetProgramOptionsCMake.py

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,26 +224,61 @@ def test_SetProgramOptionsCMake_gen_option_list_bash_expandvars(self):
224224
print("OK")
225225
return 0
226226

227-
def test_SetProgramOptionsCMake_gen_option_list_bash_expandvars_with_unknown_cmake_var(self):
227+
def test_SetProgramOptionsCMake_gen_option_list_bash_expandvars_with_unknown_cmake_var_ecl3(self):
228228
"""
229-
Test the ``gen_option_list`` method using the ``bash`` generator.
229+
Test the ``gen_option_list`` method using the ``bash`` generator when the ECL for
230+
ExpandVarsInTextCMake is set to 3 or lower. This should generate a WARNING.
230231
"""
231232
parser = self._create_standard_parser()
233+
parser.exception_control_level = 3
232234

233235
print("-----[ TEST BEGIN ]----------------------------------------")
234236
section = "TEST_VAR_EXPANSION_UPDATE_02"
235237
print("Section : {}".format(section))
236238

237-
# parse a section
239+
# parse the section
238240
self._execute_parser(parser, section)
239241

240-
option_list_actual = parser.gen_option_list(section, generator="bash")
242+
# Generate a BASH script representing the instructions in the section.
243+
244+
# what answer do we EXPECT:
241245
option_list_expect = [
242246
'cmake',
243247
'-DCMAKE_CXX_FLAGS:STRING="${LDFLAGS} -foo"',
244-
'-DCMAKE_CXX_FLAGS:STRING="${LDFLAGS} -foo -bar"', '-DCMAKE_F90_FLAGS:STRING=" -baz"'
248+
'-DCMAKE_CXX_FLAGS:STRING="${LDFLAGS} -foo -bar"',
249+
'-DCMAKE_F90_FLAGS:STRING=" -baz"'
245250
]
246251

252+
# Generate the BASH entries:
253+
option_list_actual = parser.gen_option_list(section, generator="bash")
254+
255+
# Verify the results:
256+
self.assertListEqual(option_list_actual, option_list_expect)
257+
258+
print("-----[ TEST END ]------------------------------------------")
259+
260+
print("OK")
261+
return 0
262+
263+
def test_SetProgramOptionsCMake_gen_option_list_bash_expandvars_with_unknown_cmake_var_ecl4(self):
264+
"""
265+
Test the ``gen_option_list`` method using the ``bash`` generator when the ECL
266+
for ExpandVarsInTextCMake is set to 4 or higher. This should raise a ``ValueError``.
267+
"""
268+
parser = self._create_standard_parser()
269+
parser.exception_control_level = 5
270+
271+
print("-----[ TEST BEGIN ]----------------------------------------")
272+
section = "TEST_VAR_EXPANSION_UPDATE_02"
273+
print("Section : {}".format(section))
274+
275+
# parse the section
276+
self._execute_parser(parser, section)
277+
278+
# Generate a BASH script representing the instructions in the section.
279+
with self.assertRaises(ValueError):
280+
option_list_actual = parser.gen_option_list(section, generator="bash")
281+
247282
print("-----[ TEST END ]------------------------------------------")
248283

249284
print("OK")

0 commit comments

Comments
 (0)