def _get_valid_config( config: Optional[Text], mandatory_keys: List[Text], default_config: Text = DEFAULT_CONFIG_PATH, ) -> Text: """Get a config from a config file and check if it is valid. Exit if the config isn't valid. Args: config: Path to the config file. mandatory_keys: The keys that have to be specified in the config file. default_config: default config to use if the file at `config` doesn't exist. Returns: The path to the config file if the config is valid. """ config = get_validated_path(config, "config", default_config) if not os.path.exists(config): print_error( "The config file '{}' does not exist. Use '--config' to specify a " "valid config file." "".format(config)) exit(1) missing_keys = missing_config_keys(config, mandatory_keys) if missing_keys: print_error( "The config file '{}' is missing mandatory parameters: " "'{}'. Add missing parameters to config file and try again." "".format(config, "', '".join(missing_keys))) exit(1) return config # pytype: disable=bad-return-type
def _get_valid_config( config: Optional[Text], mandatory_keys: List[Text], default_config: Text = DEFAULT_CONFIG_PATH, ) -> Text: config = get_validated_path(config, "config", default_config) if not os.path.exists(config): print_error( "The config file '{}' does not exist. Use '--config' to specify a " "valid config file." "".format(config) ) exit(1) missing_keys = missing_config_keys(config, mandatory_keys) if missing_keys: print_error( "The config file '{}' is missing mandatory parameters: " "'{}'. Add missing parameters to config file and try again." "".format(config, "', '".join(missing_keys)) ) exit(1) return config # pytype: disable=bad-return-type
def _get_valid_config(config: Text, mandatory_keys: List[Text]) -> Text: config_path = get_validated_path(config, "config", FALLBACK_CONFIG_PATH) missing_keys = missing_config_keys(config_path, mandatory_keys) if missing_keys: print_warning( "Configuration file '{}' is missing mandatory parameters: " "{}. Filling missing parameters from fallback configuration file: '{}'." "".format(config, ", ".join(missing_keys), FALLBACK_CONFIG_PATH)) _enrich_config(config_path, missing_keys, FALLBACK_CONFIG_PATH) return config_path