bag.settings module
Facilitate materialization of resources indicated in configuration.
-
class bag.settings.SettingsReader(adict)[source]
Bases: object
Convenient for reading configuration settings in an app.
However, with Python 3.6+ I have used the pydantic library
with better results.
-
bool(key, default=None, required=False)[source]
Return a boolean setting value.
-
read(key, default=None, required=False)[source]
Return setting value, or default
if missing.
Raise RuntimeError if required
is true and value is empty.
-
resolve(key, default=None, required=False)[source]
Return the variable or module indicated in the setting value.
Therefore the setting value should be a resource specification
such as some.module:SomeClass
.
-
resolve_path(key, default=None, required=False)[source]
Return a pathlib.Path corresponding to the setting value.
Example argument: "my.python.module:some/subdirectory"
-
bag.settings.asbool(s)[source]
Convert the argument to a boolean.
Return the boolean value True
if the case-lowered value of string
input s
is a truthy string. If s
is already one of the
boolean values True
or False
, return it.
-
bag.settings.read_ini_files(*config_files, encoding='utf-8')[source]
Get a settings object (dict-like) by reading some config_files
.
-
bag.settings.resolve(resource_spec)[source]
Return the variable referred to in the resource_spec
string.
Example resource_spec: "my.python.module:some_callable"
.
-
bag.settings.resolve_path(resource_spec)[source]
Return a pathlib.Path corresponding to the resource_spec
string.
Example argument: "my.python.module:some/subdirectory"
Similar: from pyramid.resource import abspath_from_asset_spec