Pyjoyment.Plugin.TOMLConfig - TOML configuration plugin

# myapp.toml (it's just TOML with embedded Python)
%# 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') %>'

[db]
host = "localhost"

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

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

Pyjoyment.Plugin.TOMLConfig is a TOML configuration plugin that preprocesses its input with Pyjo.Template and parses it with tomllib of the standard library.

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

A path goes into a literal string of TOML, in single quotes, which keeps the backslashes of a path of Windows, where a basic string in double quotes takes them for escapes.

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

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.TOMLConfig inherits all options from Pyjoyment.Plugin.JSONConfig.

See also

Pyjoyment, https://mojolicious.org.

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

Classes

class Pyjoyment.Plugin.TOMLConfig.Pyjoyment_Plugin_TOMLConfig[source]

Pyjoyment.Plugin.TOMLConfig 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 tomllib.

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.