-
-
Notifications
You must be signed in to change notification settings - Fork 123
Description
Splitting this out from #785 as it is a separate ask:
I was expecting to be able to use these config options in
pyproject.toml
Originally posted by ulgens in #785
The env vars should also be configurable via pyproject.toml settings
Config story
We currently have src/config.rs where .pre-commit-config.yaml is read in to define both the config schema (the concern of this issue) and the hooks to be provisioned (to be handled separately in #785).
We need to now use it to intercept the env vars we currently directly take from the env in src/env_vars.rs, and instead have config.rs be our source of truth for env configurable vars (i.e. they can be set in the env but overridden by the config).
- Note that this has historically been a deliberate decision to restrict configuration of prek's predecessor pre-commit, as in issues like #2696:
nope, it can only be set through the command line or an environment variable
This follows the hierarchical control of libraries like pydantic-settings or figment (both these libraries refer to the sources of configuration settings the "providers"
- "Hierarchical" here means that the CLI flags overrule the env vars if both are set
The hierarchy would be:
- CLI flags
pyproject.toml.pre-commit-config.yaml- Env vars
That's the global hierarchy though: we're going to start with a separation of config (pyproject.toml/env vars) from hook definitions (just .pre-commit-config.yaml for now).
We have one config item that can be set by both CLI flags and env vars:
--color=PREK_COLOR
That's configured in the clap CLI arg parser itself via the env attribute
Lines 144 to 152 in 3ff564e
| /// Whether to use color in output. | |
| #[arg( | |
| global = true, | |
| long, | |
| value_enum, | |
| env = EnvVars::PREK_COLOR, | |
| default_value_t = ColorChoice::Auto, | |
| )] | |
| pub(crate) color: ColorChoice, |
This gets quite complicated: I am wondering if maybe figment would be a good solution for us...
- Test PR to see cargo-bloat result: feat: add pyproject.toml config provider #1179
prek.toml
A follow-on PR can introduce prek.toml, which would mean we had 5 potential 'providers'.
- I'd let
prek.tomloverridepyproject.tomllike how.cargo/config.tomloverridesCargo.toml.