Project settings

Settings model

class optimus.conf.model.SettingsModel[source]

Settings model

Basically empty on init, you’ll have to fill it either from kwargs or a module (or an object).

Be aware that on default behavior settings loading methods execute apply_defaults method that will apply default values for some settings but related settings are not updated, you need to take care of them yourself or disabled default values pratice.

_excluded_names

Setting names to exclude from loading methods.

Type:list
_required_settings

Settings names required to be defined from loading methods.

Type:list
validate_name(name)[source]

Filter to validate setting name

Name must be uppercase, not starting with a ‘_’ character and not registred in exluded names.

Parameters:name (string) – Setting name.
Returns:True if name is valid, else False.
Return type:bool
check()[source]

Check every required settings are defined

_default_jinja()[source]

Set default attributes for required settings around Jinja

_default_watchdog()[source]

Set default attributes for required settings Watchdog

_default_webassets()[source]

Set default attributes for required settings around Webassets

_default_babel()[source]

Set default attributes for required settings around Babel

apply_defaults()[source]

Apply default attributes for needed but not required settings.

load_from_kwargs(check=True, defaults=True, **kwargs)[source]

Set setting attribute from given named arguments.

Keyword Arguments:
 
  • check (bool) – True to perform required settings check. Default is True.
  • defaults (bool) – True to set default needed settings.
  • kwargs – Named arguments to load as settings.
Returns:

List of loaded setting names from given arguments.

Return type:

list

load_from_module(settings_module, check=True, defaults=True)[source]

Set setting attribute from given module variables.

Keyword Arguments:
 
  • settings_module (object) – Object to find attributes to load as settings. Every valid attribute names will be used.
  • defaults (bool) – True to set default needed settings.
  • kwargs – Named arguments to load as settings.
Returns:

List of loaded setting names from given module.

Return type:

list

Module loader helpers

optimus.conf.loader.import_project_module(name, basedir=None, finding_module_err='Unable to find module: {0}', import_module_err='Unable to load module: {0}')[source]

Load given module name.

This is the new way technic, project base directory have to be loaded in sys.path with setup_project.setup_project before using it.

Note

  • This keeps deprecated “basedir” arg until migration ends and cleaning.

Note that if you use this function to import successively the same module path, you may need to reload importation with something like this:

mod = import_project_module(name)
mod = importlib.reload(mod)

Else you have unexpected behaviors like the second module returning content from a previously imported similar path module. However, this is a particular case that you may not encounter, this is mostly useful inside unittesting.

Parameters:

name (str) – Module name to retrieve and import.

Keyword Arguments:
 
  • basedir (str) – Base directory from where to find module name. If no base directory is given os.getcwd() is used. Default is None. DEPRECATED: Still there temporary for compatible signature but the basedir is only used from “setup_project”.
  • finding_module_err (str) – Message to output when the given module name is not reachable from basedir.
  • import_module_err (str) – Message to output when the given module name raise exception when loaded.
Returns:

Finded and loaded module.

Return type:

object

optimus.conf.loader.import_settings_module(name, basedir=None)[source]

Shortcut to have specific error message when loading settings module

Parameters:name (str) – Module name to retrieve from basedir. This is Python path to the module from project base directory as loaded from project setup.
Keyword Arguments:
 basedir (str) – Base directory from where to find module name. If no base directory is given os.getcwd() is used. Default is None.
Returns:Finded and loaded module.
Return type:object
optimus.conf.loader.import_pages_module(name, basedir=None)[source]

Shortcut to have specific error message when loading a page module

Parameters:name (str) – Module name to retrieve from basedir. This is Python path to the module from project base directory as loaded from project setup.
Keyword Arguments:
 basedir (str) – Base directory from where to find module name. If no base directory is given os.getcwd() is used. Default is None.
Returns:Finded and loaded module.
Return type:object
optimus.conf.loader.load_settings(settings_module)[source]

Load settings module.

A shortcut to validate required settings are set then fill some missing settings to a default value.

Parameters:settings_module (object) – A settings module to load in model.
Returns:Settings module validated and filled with defaults.
Return type:optimus.conf.model.SettingsModel
optimus.conf.loader.import_settings(name, basedir=None)[source]

Import and load settings module.

Parameters:name (string) – Module name to retrieve from basedir. This is Python path to the module from project base directory as loaded from project setup.
Keyword Arguments:
 basedir (string) – Base directory from where to find module name. If no base directory is given os.getcwd() is used. Default is None.
Returns:Settings module validated and filled with defaults.
Return type:object