Configuration discovering¶
Configurations are registred through files (called configuration file) that are loaded as Python modules where some code can register needed configurations.
Discovering will find these configuration files through project and its enabled applications.
Usually you will want to use automatic discovering with the autodiscover
function, so you just have to initiate it once from your project (like in your
root urls.py
) to load every configuration files.
In some uncommon cases you may need to do discovering yourself from your code,
use the discover
function to do so.
-
rstview.discover.
autodiscover
(filename='rstview_configs')[source]¶ Automatic discovering for available configurations
Before looking at configurations files, registry start from
settings.RSTVIEW_PARSER_FILTER_SETTINGS
items if setted, else an empty Dict.Then it try to load possible root configurations file defined in
settings.RSTVIEW_PARSER_ROOT_CONFIGS
(as a Python path).And finally load each configurations files finded in
settings.INSTALLED_APPS
.Example
1 2
from rstview.discover import autodiscover autodiscover()
This is something you want to be executed early in your project, usually the
urls.py
of your project is the best choice.Keyword Arguments: filename (string) – Module filename to search for. Default to rstview_configs
, so it will search for arstview_configs.py
file at root of every enabled module fromsettings.INSTALLED_APPS
.Returns: List of successfully loaded Python paths. Return type: list
-
rstview.discover.
discover
(module_path, filename=None)[source]¶ Try to discover and load a configuration file from given Python path.
Example
Supposing you made a configuration file at
myproject/myapp/rstview_configs.py
.1 2 3
from rstview.discover import discover discover("myproject.myapp", "rstview_configs")
Parameters: module_path (string) – Python path to scan for filename
module.Keyword Arguments: filename (string) – Optional module filename to search for, default to None
.Raises: Exception
– Raise any occuring exception from loaded Python path.Returns: Python path ( module.filename
) for discovered configuration module. Iffilename
does not exists in module, returnNone
.Return type: string or None