Skip to content

Commit 55926cd

Browse files
authored
Merge pull request #3246 from vkarak/feat/table-hide-columns
[feat] Introduce new option `--table-hide-columns` for hiding columns in tabular data output
2 parents aeb309e + 00ac7e0 commit 55926cd

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

docs/manpage.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ Miscellaneous options
11321132

11331133
.. option:: --table-format=csv|plain|pretty
11341134

1135-
Set the formatting of tabular output printed by options :option:`--performance-compare`, :option:`--performance-report` and the options controlling the stored sessions.
1135+
Set the formatting of tabular output printed by the options :option:`--performance-compare`, :option:`--performance-report` and the options controlling the stored sessions.
11361136

11371137
The acceptable values are the following:
11381138

@@ -1142,6 +1142,12 @@ Miscellaneous options
11421142

11431143
.. versionadded:: 4.7
11441144

1145+
.. option:: --table-hide-columns=COLUMNS
1146+
1147+
Hide the specified comma-separated list of columns from the tabular output printed by the options :option:`--performance-compare`, :option:`--performance-report` and the options controlling the stored sessions.
1148+
1149+
.. versionadded:: 4.7
1150+
11451151
.. option:: --upgrade-config-file=OLD[:NEW]
11461152

11471153
Convert the old-style configuration file ``OLD``, place it into the new file ``NEW`` and exit.

reframe/frontend/cli.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,19 @@ def __enter__(self):
218218
return self
219219

220220
def __exit__(self, exc_type, exc_val, exc_tb):
221-
logging.getprofiler().print_report(self.__logger.debug)
222221
if exc_type is SystemExit:
223222
# Allow users to exit inside the context manager
223+
logging.getprofiler().exit_region()
224+
logging.getprofiler().print_report(self.__logger.debug)
224225
return
225226

226227
if isinstance(exc_val, self.__exceptions):
227228
self.__logger.error(f'{self.__message}: {exc_val}')
228229
self.__logger.verbose(
229230
''.join(traceback.format_exception(exc_type, exc_val, exc_tb))
230231
)
232+
logging.getprofiler().exit_region()
233+
logging.getprofiler().print_report(self.__logger.debug)
231234
sys.exit(self.__exitcode)
232235

233236

@@ -631,6 +634,11 @@ def main():
631634
help='Table formatting',
632635
envvar='RFM_TABLE_FORMAT', configvar='general/table_format'
633636
)
637+
misc_options.add_argument(
638+
'--table-hide-columns', metavar='COLS', action='store',
639+
help='Hide specific columns from the final table',
640+
envvar='RFM_TABLE_HIDE_COLUMNS', configvar='general/table_hide_columns'
641+
)
634642
misc_options.add_argument(
635643
'-v', '--verbose', action='count',
636644
help='Increase verbosity level of output',
@@ -997,15 +1005,12 @@ def restrict_logging():
9971005

9981006
if options.performance_compare:
9991007
namepatt = '|'.join(options.names)
1000-
try:
1008+
with exit_gracefully_on_error('failed to generate performance report',
1009+
printer):
10011010
printer.table(
10021011
reporting.performance_compare(options.performance_compare,
10031012
namepatt=namepatt)
10041013
)
1005-
except errors.ReframeError as err:
1006-
printer.error(f'failed to generate performance report: {err}')
1007-
sys.exit(1)
1008-
else:
10091014
sys.exit(0)
10101015

10111016
# Show configuration after everything is set up

reframe/frontend/printer.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,15 @@ def table(self, data, **kwargs):
276276

277277
kwargs.setdefault('headers', 'firstrow')
278278
kwargs.setdefault('tablefmt', tablefmt)
279-
self.info(tabulate(data, **kwargs))
279+
kwargs.setdefault('numalign', 'right')
280+
hide_columns = rt.runtime().get_option('general/0/table_hide_columns')
281+
if hide_columns and kwargs['headers'] == 'firstrow' and data:
282+
hide_columns = hide_columns.split(',')
283+
colidx = [i for i, col in enumerate(data[0])
284+
if col not in hide_columns]
285+
286+
tab_data = [[rec[col] for col in colidx] for rec in data]
287+
else:
288+
tab_data = data
289+
290+
self.info(tabulate(tab_data, **kwargs))

unittests/test_cli.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,15 @@ def assert_no_crash(returncode, stdout, stderr, exitcode=0):
12981298
*run_reframe2(action=f'--describe-stored-testcases={uuid}')
12991299
)
13001300

1301+
# Check hiding of table column
1302+
stdout = assert_no_crash(*run_reframe2(
1303+
action=f'--list-stored-testcases={uuid}',
1304+
more_options=['--table-hide-columns=SysEnv,Nodelist,UUID']
1305+
))[1]
1306+
assert 'SysEnv' not in stdout
1307+
assert 'Nodelist' not in stdout
1308+
assert 'UUID' not in stdout
1309+
13011310
# List test cases by time period
13021311
ts_start = session_json['session_info']['time_start']
13031312
assert_no_crash(

0 commit comments

Comments
 (0)