slm.settings¶
These settings utilities help us compose settings across multiple files.
Warning
These functions only work when called from a settings file because they operate on the calling scope. Do not call these functions from any other location.
- slm.settings.split_email_str(email)[source]¶
Split an email string into display name and email address.
If there is no display name it will be the empty string.
- slm.settings.env(**kwargs)[source]¶
Fetch the
environ.Envobject that should be used to configure settings. If an environment file exists it will be read in. The environment file precendence is:The path in the environment variable SLM_ENV
BASE_DIR / .env
- Returns:
The
FileAwareEnvobject configured to read our environment variables and files.- Return type:
- slm.settings.base_dir(scope=None)[source]¶
Fetch the
BASE_DIR, this will raise anImproperlyConfiguredexception if it does not exist yet.- Parameters:
scope – The settings scope (do not pass if calling from a settings file)
- Returns:
The
BASE_DIRas apathlib.Pathobject.- Raises:
ImproperlyConfiguredifBASE_DIRis not defined.- Return type:
- slm.settings.set_default(var_name, default, set_if_none=True)[source]¶
Set the value of the given variable in the calling scope to a default value if it has been not been previously defined.
- slm.settings.is_defined(var_name)[source]¶
Returns true if the given variable has been defined in the calling scope.
- slm.settings.get_setting(var_name, default=<class 'slm.settings._NotGiven'>)[source]¶
Returns the value of the setting if it exists, if it does not exist the value given to default is returned. If no default value is given and the setting does not exist a NameError is raised
- slm.settings.slm_path(value, must_exist=False, mk_dirs=False)[source]¶
Resolve a configuration path. If the path is relative it will be resolved under
BASE_DIR. If the value is falsey it will be returned as-is even ifmust_existis set.- Parameters:
value (str) – The path as a string
must_exist (bool) – If True, raise an
ImproperlyConfiguredif the path does not exist.mk_dirs (bool) – If True and the path is relative to
BASE_DIRcreate the path as a directory if it does not already exist.
- Raises:
ImproperlyConfiguredifBASE_DIRis needed but not defined, or does not exist or ifmust_existisTruebut the path does not exist.- Return type:
str | None
- slm.settings.slm_path_must_exist(value, *, must_exist=True, mk_dirs=False)¶
A shortcut for
slm_path()withmust_exist=True.
- slm.settings.slm_path_mk_dirs_must_exist(value, *, must_exist=True, mk_dirs=True)¶
A shortcut for
slm_path()withmust_exist=Trueandmk_dirs=True.
- slm.settings.unset(var_name)[source]¶
Unset the value of the given variable in the calling scope.
- Parameters:
var_name (str) – The name of the variable to unset in the calling scope.