From 30a11633edaa40b396807715618f6d4be8d83da1 Mon Sep 17 00:00:00 2001 From: Ronnie Dutta <61982285+MetRonnie@users.noreply.github.com> Date: Thu, 11 Apr 2024 13:06:48 +0100 Subject: [PATCH] Better handle `ItemNotFoundError` when printing platforms config --- cylc/flow/cfgspec/globalcfg.py | 17 ++++++++++------- tests/functional/cylc-config/09-platforms.t | 1 - .../cylc-config/10-platform-expansion.t | 1 - 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/cylc/flow/cfgspec/globalcfg.py b/cylc/flow/cfgspec/globalcfg.py index 3c01ff52729..666192bc045 100644 --- a/cylc/flow/cfgspec/globalcfg.py +++ b/cylc/flow/cfgspec/globalcfg.py @@ -1994,21 +1994,23 @@ def platform_dump( """Print informations about platforms currently defined. """ if print_platform_names: - with suppress(ItemNotFoundError): - self.dump_platform_names(self) + self.dump_platform_names(self) if print_platforms: - with suppress(ItemNotFoundError): - self.dump_platform_details(self) + self.dump_platform_details(self) @staticmethod def dump_platform_names(cfg) -> None: """Print a list of defined platforms and groups. """ + # Platforms is always defined with at least localhost platforms = '\n'.join(cfg.get(['platforms']).keys()) - platform_groups = '\n'.join(cfg.get(['platform groups']).keys()) print(f'{PLATFORM_REGEX_TEXT}\n\nPlatforms\n---------', file=stderr) print(platforms) - print('\n\nPlatform Groups\n--------------', file=stderr) + try: + platform_groups = '\n'.join(cfg.get(['platform groups']).keys()) + except ItemNotFoundError: + return + print('\nPlatform Groups\n--------------', file=stderr) print(platform_groups) @staticmethod @@ -2016,4 +2018,5 @@ def dump_platform_details(cfg) -> None: """Print platform and platform group configs. """ for config in ['platforms', 'platform groups']: - printcfg({config: cfg.get([config], sparse=True)}) + with suppress(ItemNotFoundError): + printcfg({config: cfg.get([config], sparse=True)}) diff --git a/tests/functional/cylc-config/09-platforms.t b/tests/functional/cylc-config/09-platforms.t index b0624db31c8..3fc90201aec 100755 --- a/tests/functional/cylc-config/09-platforms.t +++ b/tests/functional/cylc-config/09-platforms.t @@ -54,7 +54,6 @@ They are searched from the bottom up, until the first match is found. Platforms --------- - Platform Groups -------------- __HEREDOC__ diff --git a/tests/functional/cylc-config/10-platform-expansion.t b/tests/functional/cylc-config/10-platform-expansion.t index 519639146d1..7ae9a85f881 100755 --- a/tests/functional/cylc-config/10-platform-expansion.t +++ b/tests/functional/cylc-config/10-platform-expansion.t @@ -40,7 +40,6 @@ foo bar... baz\d\d qux\S\S - __HEREDOC__ exit