Reference
Defines the ProjectConfig
and provides accessors to get config values.
Source code in src/maison/config.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
config_path: Optional[Union[Path, List[Path]]]
property
¶
Return a list of the path(s) to the config source(s).
Returns:
Type | Description |
---|---|
Optional[Union[Path, List[Path]]] |
|
Optional[Union[Path, List[Path]]] | sources if |
Optional[Union[Path, List[Path]]] | source if |
config_schema: Optional[Type[ConfigSchema]]
property
writable
¶
Return the config_schema
.
Returns:
Type | Description |
---|---|
Optional[Type[ConfigSchema]] | the |
discovered_config_paths: List[Path]
property
¶
Return a list of the paths to the config sources found on the filesystem.
Returns:
Type | Description |
---|---|
List[Path] | a list of the paths to the config sources |
__init__(project_name, starting_path=None, source_files=None, config_schema=None, merge_configs=False)
¶
Initialize the config.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project_name | str | the name of the project, to be used to find the right section in the config file | required |
starting_path | Optional[Path] | an optional starting path to start the search for config file | None |
source_files | Optional[List[str]] | an optional list of source config filenames or absolute paths to search for. If none is provided then | None |
config_schema | Optional[Type[ConfigSchema]] | an optional | None |
merge_configs | bool | an optional boolean to determine whether configs should be merged if multiple are found | False |
Source code in src/maison/config.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
__repr__()
¶
Return the repr.
Returns:
Type | Description |
---|---|
str | the representation |
Source code in src/maison/config.py
51 52 53 54 55 56 57 |
|
__str__()
¶
Return the str.
Returns:
Type | Description |
---|---|
str | the representation |
Source code in src/maison/config.py
59 60 61 62 63 64 65 |
|
get_option(option_name, default_value=None)
¶
Return the value of a config option.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
option_name | str | the config option for which to return the value | required |
default_value | Optional[Any] | an option default value if the option isn't set | None |
Returns:
Type | Description |
---|---|
Optional[Any] | The value of the given config option or |
Source code in src/maison/config.py
163 164 165 166 167 168 169 170 171 172 173 174 175 |
|
to_dict()
¶
Return a dict of all the config options.
Returns:
Type | Description |
---|---|
Dict[str, Any] | a dict of the config options |
Source code in src/maison/config.py
93 94 95 96 97 98 99 |
|
validate(config_schema=None, use_schema_values=True)
¶
Validate the configuration.
Warning
Using this method with use_schema_values
set to True
will cast values to whatever is defined in the schema. For example, for the following schema:
class Schema(ConfigSchema):
foo: str
Validating a config with:
{"foo": 1}
Will result in:
{"foo": "1"}
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_schema | Optional[Type[ConfigSchema]] | an optional | None |
use_schema_values | bool | an optional boolean to indicate whether the result of passing the config through the schema should overwrite the existing config values, meaning values are cast to types defined in the schema as described above, and default values defined in the schema are used. | True |
Returns:
Type | Description |
---|---|
Dict[str, Any] | the config values |
Raises:
Type | Description |
---|---|
NoSchemaError | when validation is attempted but no schema has been provided |
Source code in src/maison/config.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|