Skip to content

hyfi.__cli__

This module contains the command line interface for the hyfi package. It is implemented using the hydra package. You can run the CLI by executing the hyfi command.

Command line interface for HyFI

cli_main(cfg)

Main function for the command line interface. Initializes Hydra and instantiates the class. Prints the configuration to standard out if verbose is set to True

Parameters:

Name Type Description Default
cfg DictConfig

Configuration dictionary to be used for instantiation

required

Returns:

Type Description
None

None if everything went fine otherwise an error is raised

None

to indicate the reason for the failure

Source code in hyfi/__cli__.py
def cli_main(cfg: DictConfig) -> None:
    """
    Main function for the command line interface.
    Initializes Hydra and instantiates the class.
    Prints the configuration to standard out if verbose is set to True

    Args:
        cfg: Configuration dictionary to be used for instantiation

    Returns:
        None if everything went fine otherwise an error is raised
        to indicate the reason for the failure
    """
    hyfi = HyFI(**cfg)

    # Print out the command line interface for the application.
    if hyfi.verbose:
        app_name = hyfi.app_name
        print(f"## Command Line Interface for {app_name} ##")

        # Prints the configuration to the console.
        if hyfi.resolve:
            logger.info("## hydra configuration resolved ##")
            hyfi.print(cfg)
        else:
            logger.info("## hydra configuration ##")
            print(hyfi.to_yaml(cfg))

        logger.info("Hydra working directory : %s", os.getcwd())
        logger.info("Orig working directory  : %s", hydra.utils.get_original_cwd())

    hyfi.run_config(config=cfg, dryrun=hyfi.dryrun)
    hyfi.terminate()

hydra_main(config_path=None, config_name=None, overrides=None, plugins=None)

Main function for the command line interface of Hydra

Parameters:

Name Type Description Default
config_path Optional[str]

The config path, a directory where Hydra will search for config files. This path is added to Hydra's searchpath. Relative paths are interpreted relative to the declaring python file. Alternatively, you can use the prefix pkg:// to specify a python package to add to the searchpath. If config_path is None no directory is added to the Config search path.

None
config_name Optional[str]

The name of the config (usually the file name without the .yaml extension)

None
Source code in hyfi/__cli__.py
def hydra_main(
    config_path: Optional[str] = None,
    config_name: Optional[str] = None,
    overrides: Optional[List[str]] = None,
    plugins: Optional[List[str]] = None,
) -> None:
    """
    Main function for the command line interface of Hydra

    Args:
        config_path: The config path, a directory where Hydra will search for
                        config files. This path is added to Hydra's searchpath.
                        Relative paths are interpreted relative to the declaring python
                        file. Alternatively, you can use the prefix `pkg://` to specify
                        a python package to add to the searchpath.
                        If config_path is None no directory is added to the Config search path.
        config_name: The name of the config (usually the file name without the .yaml extension)
    """
    hyfi_main(config_path, config_name, overrides, plugins)

hyfi_main(config_path=None, config_name=None, overrides=None, plugins=None)

Main function for the command line interface of Hydra

Parameters:

Name Type Description Default
config_path Optional[str]

The config path, a directory where Hydra will search for config files. This path is added to Hydra's searchpath. Relative paths are interpreted relative to the declaring python file. Alternatively, you can use the prefix pkg:// to specify a python package to add to the searchpath. If config_path is None no directory is added to the Config search path.

None
config_name Optional[str]

The name of the config (usually the file name without the .yaml extension)

None
Source code in hyfi/__cli__.py
def hyfi_main(
    config_path: Optional[str] = None,
    config_name: Optional[str] = None,
    overrides: Optional[List[str]] = None,
    plugins: Optional[List[str]] = None,
) -> None:
    """
    Main function for the command line interface of Hydra

    Args:
        config_path: The config path, a directory where Hydra will search for
                        config files. This path is added to Hydra's searchpath.
                        Relative paths are interpreted relative to the declaring python
                        file. Alternatively, you can use the prefix `pkg://` to specify
                        a python package to add to the searchpath.
                        If config_path is None no directory is added to the Config search path.
        config_name: The name of the config (usually the file name without the .yaml extension)
    """
    if global_hyfi.user_config_path:
        sys.argv.append(f"--config-dir={global_hyfi.user_config_path}")
    if not config_path:
        config_path = global_hyfi.config_module_path
    if not config_name:
        config_name = global_hyfi.config_name
    if not plugins:
        plugins = global_hyfi.plugins
    if global_hyfi.package_name != global_hyfi.hyfi_package_name:
        overrides = overrides or []
        override = f"about={global_hyfi.package_name}"
        if override not in overrides:
            overrides.append(override)
            logger.debug(
                "Overriding `about` config group with `%s`",
                global_hyfi.package_name,
            )
    hyfi_hydra_main(
        config_path=config_path,
        config_name=config_name,
        version_base=global_hyfi.hydra_version_base,
        overrides=overrides,
        plugins=plugins,
    )(cli_main)()