Pyjoyment.Plugin.Config - Python-ish configuration plugin¶
# myapp.conf (it's just Python ending with a dict)
{
# Just a value
'foo': 'bar',
# Nested data structures are fine too
'baz': ['♥'],
# You have full access to the application
'music_dir': app.home.child('music'),
}
# Pyjoyment
config = app.plugin('Config')
print(config['foo'])
# Pyjoyment.Lite
config = plugin('Config')
print(config['foo'])
# foo.html.ep
%= config()['foo']
# The configuration is available application-wide
config = app.config()
print(config['foo'])
# Everything can be customized with options
config = plugin('Config', file='/etc/myapp.stuff')
Pyjoyment.Plugin.Config is a Python-ish configuration plugin.
The configuration file is Python code, and the value of its last expression,
a dict, is the configuration; the statements before it can import modules and
prepare values. The application object can be accessed via app. A
default configuration filename in the application home directory will be
generated from the value of Pyjoyment.Pyjoyment_App.moniker
($moniker.conf). You can extend the normal configuration file
$moniker.conf with mode specific ones like $moniker.$mode.conf,
which will be detected automatically.
These configuration values are currently reserved:
config_overrideIf this configuration value has been set in
Pyjoyment.Pyjoyment_App.config()when this plugin is loaded, it will not do anything besides loading deployment specific plugins.
plugins
'plugins': [{'SetUserGroup': {'user': 'sri', 'group': 'staff'}}]
One or more deployment specific plugins that should be loaded right after
this plugin has been loaded.
The code of this plugin is a good example for learning to build new plugins, you’re welcome to fork it.
See Pyjoyment.Plugins for a list of plugins that are available by
default.
Options¶
Pyjoyment.Plugin.Config supports the following options.
default
# Pyjoyment.Lite
plugin('Config', default={'foo': 'bar'})
Default configuration, making configuration files optional.
ext
# Pyjoyment.Lite
plugin('Config', ext='stuff')
File extension for generated configuration filenames, defaults to conf.
file
# Pyjoyment.Lite
plugin('Config', file='myapp.conf')
plugin('Config', file='/etc/foo.stuff')
Path to configuration file, absolute or relative to the application home
directory, defaults to the value of the PYJO_CONFIG environment variable
or $moniker.conf in the application home directory.
See also¶
Pyjoyment, https://mojolicious.org.
Ported from Mojolicious::Plugin::Config of Mojolicious 9.49.
Classes¶
- class Pyjoyment.Plugin.Config.Pyjoyment_Plugin_Config[source]¶
Pyjoyment.Plugin.Configinherits all methods fromPyjoyment.Pluginand implements the following new ones.- load(file: str, conf: dict[str, Any], app: Pyjoyment_App) dict[str, Any][source]¶
plugin.load(file, conf, app)
Loads configuration file and passes the content to
parse().def load(self, file, conf, app): ... return self.parse(content, file, conf, app)
- parse(content: str, file: str, conf: dict[str, Any], app: Pyjoyment_App) dict[str, Any][source]¶
plugin.parse(content, file, conf, app)
Parse configuration file.
def parse(self, content, file, conf, app): ... return config
- register(app: Pyjoyment_App, conf: dict[str, Any] | None = None) dict[str, Any][source]¶
config = plugin.register(Pyjoyment.new()) config = plugin.register(Pyjoyment.new(), {'file': '/etc/app.conf'})
Register plugin in
Pyjoymentapplication and merge configuration.