From 98f91ad436fac1bbbd35a74d5cf73b4022455f24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6hm?= Date: Fri, 5 Jan 2024 16:54:01 +0100 Subject: [PATCH 1/2] Fixes vara-cs view --commit-hash option conversion --- varats/varats/tools/driver_casestudy.py | 7 ++++++- varats/varats/ts_utils/click_param_types.py | 14 +++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/varats/varats/tools/driver_casestudy.py b/varats/varats/tools/driver_casestudy.py index 2f40a8409..364ddc69d 100644 --- a/varats/varats/tools/driver_casestudy.py +++ b/varats/varats/tools/driver_casestudy.py @@ -69,6 +69,7 @@ TypedChoice, EnumChoice, create_multi_case_study_choice, + ShortCommitHashParamType, ) from varats.utils.git_util import ( get_initial_commit, @@ -555,7 +556,11 @@ def __casestudy_package( @click.option( "--project", required=True, help="Project to view result files for." ) -@click.option("--commit-hash", help="Commit hash to view result files for.") +@click.option( + "--commit-hash", + type=ShortCommitHashParamType(), + help="Commit hash to view result files for." +) @click.option( "--newest-only", is_flag=True, diff --git a/varats/varats/ts_utils/click_param_types.py b/varats/varats/ts_utils/click_param_types.py index f080fa4e7..e278ead69 100644 --- a/varats/varats/ts_utils/click_param_types.py +++ b/varats/varats/ts_utils/click_param_types.py @@ -5,6 +5,7 @@ import click from benchbuild.experiment import ExperimentRegistry +from click import ParamType from varats.data.discover_reports import initialize_reports from varats.experiments.discover_experiments import initialize_experiments @@ -17,6 +18,7 @@ ) from varats.ts_utils.cli_util import CLIOptionTy, convert_value, make_cli_option from varats.utils.exceptions import ConfigurationLookupError +from varats.utils.git_util import ShortCommitHash if tp.TYPE_CHECKING: # pylint: disable=unused-import @@ -184,8 +186,18 @@ def create_multi_experiment_type_choice( return TypedMultiChoice(value_dict) +class ShortCommitHashParamType(ParamType): + name = "ShortCommitHash" + + def convert(self, value, param, ctx) -> ShortCommitHash: + if isinstance(value, ShortCommitHash): + return value + + return ShortCommitHash(value) + + # ------------------------------------------------------------------------------ -# Predefined CLI Options +# Predefined plot/table CLI Options # ------------------------------------------------------------------------------ REQUIRE_CASE_STUDY: CLIOptionTy = convert_value( From ea64163f562a7a3a84a03b8492c55243d55cdc85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6hm?= Date: Fri, 5 Jan 2024 17:06:54 +0100 Subject: [PATCH 2/2] Add missing type annotations --- varats/varats/ts_utils/click_param_types.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/varats/varats/ts_utils/click_param_types.py b/varats/varats/ts_utils/click_param_types.py index e278ead69..bbd0e6042 100644 --- a/varats/varats/ts_utils/click_param_types.py +++ b/varats/varats/ts_utils/click_param_types.py @@ -187,9 +187,13 @@ def create_multi_experiment_type_choice( class ShortCommitHashParamType(ParamType): + """Click parameter type for commit hashes.""" name = "ShortCommitHash" - def convert(self, value, param, ctx) -> ShortCommitHash: + def convert( + self, value: tp.Union[str, ShortCommitHash], + param: tp.Optional[click.Parameter], ctx: tp.Optional[click.Context] + ) -> ShortCommitHash: if isinstance(value, ShortCommitHash): return value