config
Read, write and process config files, including handling of module-specific / common config overrides.
assemble_config(args, all_subparsers)
Assemble and arrange a nested-via-module configuration dictionary from parsed command-line arguments to be output as a YAML record.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
Namespace
|
A namespace object containing all parsed command-line arguments. |
required |
all_subparsers |
dict[str, ArgumentParser]
|
A dictionary mapping module names to subparser objects. |
required |
Returns:
Type | Description |
---|---|
dict[str, Any]
|
A dictionary containing configuration information extracted from |
Raises:
Type | Description |
---|---|
ValueError
|
If a module specified in |
Source code in src/nhssynth/cli/config.py
get_default_and_required_args(top_parser, module_parsers)
Get the default and required arguments for the top-level parser and the current run's corresponding list of module parsers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
top_parser |
ArgumentParser
|
The top-level parser (contains common arguments). |
required |
module_parsers |
dict[str, ArgumentParser]
|
The dict of module-level parsers mapped to their names. |
required |
Returns:
Type | Description |
---|---|
tuple[dict[str, Any], list[str]]
|
A tuple containing two elements: - A dictionary containing all arguments and their default values. - A list of key-value-pairs of the required arguments and their associated module. |
Source code in src/nhssynth/cli/config.py
get_modules_to_run(executor)
Get the list of modules to run from the passed executor function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
executor |
Callable
|
The executor function to run. |
required |
Returns:
Type | Description |
---|---|
list[str]
|
A list of module names to run. |
Source code in src/nhssynth/cli/config.py
read_config(args, parser, all_subparsers)
Hierarchically assembles a config argparse.Namespace
object for the inferred modules to run and execute, given a file.
- Load the YAML file containing the config to read from
- Check a valid
run_type
is specified or infer it and determine the list ofmodules_to_run
- Establish the appropriate default configuration set of arguments from the
parser
andall_subparsers
for the determinedmodules_to_run
- Overwrite these with the specified (sub)set of config in the YAML file
- Overwrite again with passed command-line
args
(these are considered 'overrides') - Run the appropriate module(s) or pipeline with the resulting configuration
Namespace
object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
Namespace
|
Namespace object containing arguments from the command line |
required |
parser |
ArgumentParser
|
top-level |
required |
all_subparsers |
dict[str, ArgumentParser]
|
dictionary of |
required |
Returns:
Type | Description |
---|---|
Namespace
|
A Namespace object containing the assembled configuration settings |
Raises:
Type | Description |
---|---|
AssertionError
|
if any required arguments are missing from the configuration file / overrides |
Source code in src/nhssynth/cli/config.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
|
write_config(args, all_subparsers)
Assembles a configuration dictionary from the run config and writes it to a YAML file at the location specified by args.save_config_path
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
Namespace
|
A namespace containing the run's configuration. |
required |
all_subparsers |
dict[str, ArgumentParser]
|
A dictionary containing all subparsers for the config args. |
required |