Skip to content

Commit

Permalink
fix(help menu): hydra guided, deleted click usage
Browse files Browse the repository at this point in the history
  • Loading branch information
johaGL committed Jan 26, 2024
1 parent 20bda79 commit 0397288
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 19 deletions.
24 changes: 11 additions & 13 deletions src/dimet/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -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()
13 changes: 7 additions & 6 deletions src/dimet/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
38 changes: 38 additions & 0 deletions src/dimet/config/hydra/help/dimet_help.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0397288

Please sign in to comment.