From 0397288a84ef1a00736f2d6c5d1c3fd0a212b7c7 Mon Sep 17 00:00:00 2001 From: johaGL Date: Fri, 26 Jan 2024 15:57:14 +0100 Subject: [PATCH] fix(help menu): hydra guided, deleted click usage --- src/dimet/__main__.py | 24 ++++++------- src/dimet/config/config.yaml | 13 +++---- src/dimet/config/hydra/help/dimet_help.yaml | 38 +++++++++++++++++++++ 3 files changed, 56 insertions(+), 19 deletions(-) create mode 100644 src/dimet/config/hydra/help/dimet_help.yaml diff --git a/src/dimet/__main__.py b/src/dimet/__main__.py index 47ba33e..516302b 100644 --- a/src/dimet/__main__.py +++ b/src/dimet/__main__.py @@ -9,12 +9,11 @@ import hydra -from dimet.method import Method from omegaconf import DictConfig, OmegaConf from dimet.data import Dataset +from dimet.method import Method -import click logger = logging.getLogger(__name__) @@ -34,18 +33,17 @@ def main_run_analysis(cfg: DictConfig) -> None: method.run(cfg, dataset) -@click.command(context_settings=dict( - help_option_names=['-h', '--help']) # needed to recognize -h as well +def fully_empty_args_custom_message() -> None: + custom_message: str = ( + "\nDIMet is a tool for the Differential analysis of " + "targeted Isotope-labeled Metabolomics data. \n\n Please type " + "'python -m dimet --help' or 'python -m dimet -h' for usage.\n" ) -@click.option('-cd', type=str, required=True, - help="Directory containing the general configuration " - "(see -cn)") -@click.option('-cn', type=str, required=True, - help="File name of the general configuration " - "(only one .yaml file name)") -def main_run_analysis__or_display_help(cd, cn) -> None: - main_run_analysis() # run: hydra handles further arguments validation + print(custom_message) if __name__ == "__main__": - main_run_analysis__or_display_help() + if len(sys.argv) <= 1: + fully_empty_args_custom_message() + else: + main_run_analysis() diff --git a/src/dimet/config/config.yaml b/src/dimet/config/config.yaml index a338f1d..a924851 100644 --- a/src/dimet/config/config.yaml +++ b/src/dimet/config/config.yaml @@ -3,16 +3,17 @@ hydra: chdir: true run: dir: ../outputs/${now:%Y-%m-%d}/${now:%H-%M-%S}/${analysis.dataset.label}-${analysis.method.label} - -# Notes: -# This config.yaml file is never used by the code, but remains here as template. -# All the method/*.yaml files YES THEY ARE USED by the code + + +# This config.yaml file is used by the code when calling --help defaults: - - analysis: abundance_plot + # - analysis: abundance_plot # deactivated as it blocks the --help display - _self_ + - override hydra/help: dimet_help + figure_path: figures table_path: tables -# check https://hydra.cc/docs/patterns/specializing_config/ for more info about this +# check https://hydra.cc/docs/patterns/specializing_config/ for more info about this \ No newline at end of file diff --git a/src/dimet/config/hydra/help/dimet_help.yaml b/src/dimet/config/hydra/help/dimet_help.yaml new file mode 100644 index 0000000..af72056 --- /dev/null +++ b/src/dimet/config/hydra/help/dimet_help.yaml @@ -0,0 +1,38 @@ +# App name, override to match the name your app is known by +app_name: DIMet + +# Help header, customize to describe your app to your users +header: Welcome to ${hydra.help.app_name}! + +footer: |- + Powered by Hydra (https://hydra.cc) + Use --hydra-help to view Hydra specific help + +template: |- + ${hydra.help.header} + + DIMet is a tool for the Differential analysis of targeted Isotope-labeled Metabolomics data + + Usage: python -m dimet [options] + + optional arguments: + -cd, --config-dir Directory name where the general configuration is located (see -cn) + -cn, --config-name File name of the general configuration, only one .yaml file name + -h, --help Show this help message and exit + + + == Available analyses == + $APP_CONFIG_GROUPS + + ${hydra.help.footer} + + +# Basic Hydra flags: +# $FLAGS_HELP +# +# Config groups, choose one of: +# $APP_CONFIG_GROUPS: All config groups that does not start with hydra/. +# $HYDRA_CONFIG_GROUPS: All the Hydra config groups (starts with hydra/) +# +# Configuration generated with overrides: +# $CONFIG : Generated config