From c029796bf1352528d4fcb3d9044e098720b88f5f Mon Sep 17 00:00:00 2001 From: Jiri Pavela Date: Wed, 2 Oct 2024 13:25:22 +0200 Subject: [PATCH] Fix issue with empty CLI stats headers The --stats-headers option was set to empty string by default, which created an empty stats header record due to missing if statement. --- perun/cli_groups/import_cli.py | 2 +- perun/profile/imports.py | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/perun/cli_groups/import_cli.py b/perun/cli_groups/import_cli.py index 5714d38b..5c875eb8 100755 --- a/perun/cli_groups/import_cli.py +++ b/perun/cli_groups/import_cli.py @@ -44,7 +44,7 @@ "--stats-headers", "-t", nargs=1, - default="", + default=None, metavar="[STAT_HEADER+]", help="Describes the stats headers associated with imported profiles specified directly in CLI. " "A stats header has the form of 'NAME[|COMPARISON_TYPE[|UNIT[|AGGREGATE_BY[|DESCRIPTION]]]]'.", diff --git a/perun/profile/imports.py b/perun/profile/imports.py index 5ba984fd..a8e3ef3f 100755 --- a/perun/profile/imports.py +++ b/perun/profile/imports.py @@ -41,7 +41,7 @@ class _PerfProfileSpec: @vcs_kit.lookup_minor_version def import_perf_from_record( import_entries: list[str], - stats_headers: str, + stats_headers: str | None, minor_version: str, with_sudo: bool = False, **kwargs: Any, @@ -86,7 +86,7 @@ def import_perf_from_record( @vcs_kit.lookup_minor_version def import_perf_from_script( import_entries: list[str], - stats_headers: str, + stats_headers: str | None, minor_version: str, **kwargs: Any, ) -> None: @@ -117,7 +117,7 @@ def import_perf_from_script( @vcs_kit.lookup_minor_version def import_perf_from_stack( import_entries: list[str], - stats_headers: str, + stats_headers: str | None, minor_version: str, **kwargs: Any, ) -> None: @@ -466,7 +466,7 @@ def _parse_metadata_json(metadata_path: Path) -> list[profile.ProfileMetadata]: def _parse_perf_import_entries( - import_entries: list[str], cli_stats_headers: str + import_entries: list[str], cli_stats_headers: str | None ) -> tuple[list[_PerfProfileSpec], list[profile.ProfileStat]]: """Parses perf import entries and stats. @@ -494,9 +494,12 @@ def _parse_perf_import_entries( :return: parsed profiles and stats. """ - stats = [ - profile.ProfileStat.from_string(*stat.split("|")) for stat in cli_stats_headers.split(",") - ] + stats = [] + if cli_stats_headers is not None: + stats = [ + profile.ProfileStat.from_string(*stat.split("|")) + for stat in cli_stats_headers.split(",") + ] cli_stats_len = len(stats) import_dir = Path(config.lookup_key_recursively("import.dir", os.getcwd()))