Skip to content

Use Click to parse configuration #395

@lemon24

Description

@lemon24

We currently have a hand-rolled configuration loader added in #177 that accomplishes two things:

  • it can be used from the CLI and from the web app
  • it allows merging options from multiple contexts (default, CLI, web app), including list options (plugins)

However, it also has a bunch of issues:

  • the config format is bad (it targets arguments to make_reader(), with CLI defaults tacked on; also, the contexts thing is overkill)
  • overriding make_reader() options from the CLI is cumbersome
  • it's orthogonal to plugin loading (and for CLI / web app plugins, it doesn't help at all)
  • you can't set arbitrary options via environment variables (now we support 5 hardcoded variables in 2 separate places)

Instead, we could use Click to parse configuration for everyone, since it already mostly does most of the work:

  • setting default_map from a config file can provide defaults for all options of all commands
    • => single configuration format, that of the CLI; the web app can use the serve options
    • we can still merge defaults and command-line values using option callbacks, where it makes sense
    • overriding options from the CLI / environment variables comes out of the box
    • we can load plugins (e.g. @click.option(..., type=pkgutil.resolve_name))
  • it's possible to get Click to load the config and environment variables without invoking the commands
    • => free config parser (including for the web app)
    • perhaps we can also use TOML instead (tomllib is in stdlib)

The downside is that we can only set the make_reader() options that are exposed in the CLI (great incentive for parity :P).

Prototype here: LINK. (https://github.com/phha/click_config_file does kinda the same thing, but only the first part.)

Related issues:

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions