typerdrive Settings modules
typerdrive.settings.attach
Provide a decorator that attaches the typerdrive
settings to a typer
command function.
Attributes
Classes
Functions
attach_settings
attach_settings(
settings_model: type[BaseModel],
*,
validation: Validation = Validation.BEFORE,
persist: bool = False,
show: bool = False,
) -> Callable[
[ContextFunction[P, T]], ContextFunction[P, T]
]
Attach the typerdrive
settings to the decorated typer
command function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
validation
|
Validation
|
Indicates when validation should happen in the decorator:
|
BEFORE
|
persist
|
bool
|
If set, the settings values will be stored in the settings file |
False
|
show
|
bool
|
If set, show the current settings after running the function |
False
|
Source code in src/typerdrive/settings/attach.py
get_settings
Get the settings instance from the TyperdriveContext
.
Source code in src/typerdrive/settings/attach.py
get_settings_manager
Retrieve the SettingsManager
from the TyperdriveContext
.
Source code in src/typerdrive/settings/attach.py
get_settings_value
Get a particular settings value from the TyperdriveContext
.
Source code in src/typerdrive/settings/attach.py
typerdrive.settings.commands
Provide commands that can be added to a typer
app to manage settings.
Classes
Functions
add_bind
Add the bind
command to the given typer
app.
Source code in src/typerdrive/settings/commands.py
add_reset
Add the reset
command to the given typer
app.
Source code in src/typerdrive/settings/commands.py
add_settings_subcommand
Add all settings
commands to the given app.
Source code in src/typerdrive/settings/commands.py
add_show
Add the show
command to the given typer
app.
Source code in src/typerdrive/settings/commands.py
add_unset
Add the unset
command to the given typer
app.
Source code in src/typerdrive/settings/commands.py
add_update
Add the update
command to the given typer
app.
Source code in src/typerdrive/settings/commands.py
bind
Bind all settings for the app.
Source code in src/typerdrive/settings/commands.py
reset
Remove all settings from the app.
show
unset
Remove some settings from the app.
Source code in src/typerdrive/settings/commands.py
update
Update some settings for the app.
Source code in src/typerdrive/settings/commands.py
typerdrive.settings.exceptions
Provide exceptions specific to the settings feature of typerdrive
.
Classes
SettingsDisplayError
Bases: SettingsError
Indicates that there was a problem showing the settings.
Source code in src/typerdrive/settings/exceptions.py
SettingsError
Bases: TyperdriveError
The base exception for settings errors.
Source code in src/typerdrive/settings/exceptions.py
SettingsInitError
Bases: SettingsError
Indicates that there was a problem initializing the settings.
Source code in src/typerdrive/settings/exceptions.py
SettingsResetError
Bases: SettingsError
Indicates that there was a problem resetting a settings value.
Source code in src/typerdrive/settings/exceptions.py
SettingsSaveError
Bases: SettingsError
Indicates that there was a problem saving the settings to disk.
Source code in src/typerdrive/settings/exceptions.py
SettingsUnsetError
Bases: SettingsError
Indicates that there was a problem unsetting a settings value.
Source code in src/typerdrive/settings/exceptions.py
SettingsUpdateError
Bases: SettingsError
Indicates that there was a problem updating a settings value.
Source code in src/typerdrive/settings/exceptions.py
typerdrive.settings.manager
Provide a class for managing the typerdrive
settings feature.
Classes
SettingsManager
Manage settings for the typerdrive
app.
Source code in src/typerdrive/settings/manager.py
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 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
|
Attributes
invalid_warnings
instance-attribute
Tracks which fields of the settings instance are invalid
settings_instance
instance-attribute
An instance of the settings_model
that holds the app's current settings
settings_model
instance-attribute
A pydantic
model type that defines the app's settings
settings_path
instance-attribute
The path to the file where settings are persisted
Functions
__init__
Source code in src/typerdrive/settings/manager.py
construct_instance
Source code in src/typerdrive/settings/manager.py
pretty
Return a pretty representation of the settings.
Source code in src/typerdrive/settings/manager.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 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 194 195 196 197 198 199 200 201 202 |
|
reset
Reset the settings back to defaults.
save
Write the current settings to disk.
Source code in src/typerdrive/settings/manager.py
set_warnings
Given a ValidationError
, extract the field names and messages to the invalid_warnings
dict.
Source code in src/typerdrive/settings/manager.py
unset
Remove all the settings corresponding to the provided keys.
Source code in src/typerdrive/settings/manager.py
update
Update the app settings given the provided key/value pairs.
If validation fails, the invalid_warngings
will be updated, but all valid fields will remain set.
Source code in src/typerdrive/settings/manager.py
validate
Validate the current settings values.
If invalid, ValidationError
exceptions will be raised