Pyjoyment.Plugin.INIConfig - INI configuration plugin

# myapp.ini (it's just INI with embedded Python)
%# Just a value
foo = bar

%# You have full access to the application
music_dir = <%= app.home.child('music') %>

[db]
host = localhost

# Pyjoyment
config = app.plugin('INIConfig')
print(config['foo'])

# Pyjoyment.Lite
config = plugin('INIConfig')
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('INIConfig', file='/etc/myapp.conf')

Pyjoyment.Plugin.INIConfig is an INI configuration plugin that preprocesses its input with Pyjo.Template and parses it with Pyjo.INI, whose values are strings.

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.ini). You can extend the normal configuration file $moniker.ini with mode specific ones like $moniker.$mode.ini, which will be detected automatically.

These configuration values are currently reserved:

config_override

If 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

[plugin SetUserGroup]
user = sri
group = staff

One or more deployment specific plugins that should be loaded right after
this plugin has been loaded, a section ``[plugin Name]`` for each, as the
profiles of ``~/.aws/config`` are sections ``[profile name]``, with the
options of the plugin, in the order of the file. A plugin comes once, as
a section that comes again adds its keys.

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.INIConfig inherits all options from Pyjoyment.Plugin.JSONConfig and supports the following new ones.

unquote

# Pyjoyment.Lite
plugin('INIConfig', unquote=True)

Take the quotes around the values off, as PHP does, which Pyjo.INI keeps by default.

See also

Pyjoyment, https://mojolicious.org.

Inspired by Mojolicious::Plugin::NotYAMLConfig of Mojolicious 9.49.

Classes

class Pyjoyment.Plugin.INIConfig.Pyjoyment_Plugin_INIConfig[source]

Pyjoyment.Plugin.INIConfig inherits all methods from Pyjoyment.Plugin.JSONConfig and implements the following new ones.

parse(content: str, file: str, conf: dict[str, Any], app: Pyjoyment_App) → dict[str, Any][source]
plugin.parse(content, file, conf, app)

Process content with render() and parse it with Pyjo.INI, with the sections [plugin Name] as the value plugins.

def parse(self, content, file, conf, app):
    ...
    content = self.render(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/foo.conf'})

Register plugin in Pyjoyment application and merge configuration.