You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/index.md
+52-10Lines changed: 52 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -92,15 +92,15 @@ variable, use `fix_code`:
92
92
93
93
`yamlfix`uses the `maison` library to find and parse configuration from standard locations, and can additionally be configured through environment variables.
94
94
95
-
Any configuration found in the [YamlfixConfig class](./reference/#yamlfix.model.YamlfixConfig) can be set through your projects `pyproject.toml`, a custom `toml`-file or through the environment by providing an environment variable like `{yamlfix_env_prefix}_{yamlfix_config_key}`.
95
+
Any configuration found in the [YamlfixConfig class](./reference/#yamlfix.model.YamlfixConfig) can be set through your projects' `pyproject.toml`, a `.yamlfix.toml` file, a custom `toml`-file or through the environment by providing an environment variable like `{yamlfix_env_prefix}_{yamlfix_config_key}`.
96
96
97
97
Configuration options that are provided through environment variables have higher priority than options provided through configuration files and will override those keys.
98
98
99
99
All provided [configuration options](#configuration-options), be it through `pyproject.toml`, config-files or env-vars, will be parsed by `pydantic`, so the target value type (str, bool, int, etc.) will be enforced, even if the provided value has the wrong type (for example all env vars in linux systems are strings, but pydantic will parse them to bools/numbers where necessary).
100
100
101
-
## Auto-Configure through `pyproject.toml`
101
+
## Auto-Configure through `pyproject.toml` or `.yamlfix.toml`
102
102
103
-
The `maison` library will automatically pick up your `yamlfix` configuration through your projects `pyproject.toml`. It will look in the section named `tool.yamlfix` and apply the provided [configuration options](#configuration-options). For example:
103
+
The `maison` library will automatically pick up your `yamlfix` configuration through your projects' `pyproject.toml`. It will look in the section named `tool.yamlfix` and apply the provided [configuration options](#configuration-options). For example:
104
104
105
105
```toml
106
106
# pyproject.toml
@@ -111,15 +111,57 @@ line_length = 80
111
111
none_representation = "null"
112
112
```
113
113
114
-
## Provide config-files
114
+
When running `yamlfix` as a standalone cli application it might be desireable to provide a config file containing just the configuration related to `yamlfix`. The `maison` library will therefore also read `.yamlfix.toml` and `yamlfix.toml` if they exist. No section headers are necessary for these configuration files, as the expected behaviour is, that those files contain only configuration related to `yamlfix`. For example:
115
115
116
-
When running `yamlfix` as a standalone cli application it might be desireable to provide a config file containing just the configuration related to `yamlfix`. A cli-argument `-c` (`--config-file`) can be provided multiple times to read configuration values from `toml` formatted files. The rightmost value-files override the value-files preceding them, only trumped by environment variables. No section headers are necessary for these configuration files, as the expected behaviour is, that those files contain only configuration related to `yamlfix`. For example:
116
+
```toml
117
+
# .yamlfix.toml
118
+
allow_duplicate_keys = true
119
+
line_length = 80
120
+
none_representation = "null"
121
+
```
122
+
123
+
The configurations from `pyproject.toml`, `yamlfix.toml`, and `.yamlfix.toml` are merged from left to right. This means that settings in `yamlfix.toml` override those in `pyproject.toml` and settings in `.yamlfix.toml` override those in `pyproject.toml` and `yamlfix.toml`. Environment variables override all settings set in configuration files. For example:
124
+
125
+
```toml
126
+
# pyproject.toml
127
+
allow_duplicate_keys = false
128
+
line_length = 100
129
+
preserve_quotes = false
130
+
```
131
+
132
+
```toml
133
+
# yamlfix.toml
134
+
allow_duplicate_keys = true
135
+
preserve_quotes = true
136
+
```
137
+
138
+
```toml
139
+
# .yamlfix.toml
140
+
preserve_quotes = false
141
+
```
142
+
143
+
These provided configuration files would result in a merged runtime-configuration of:
144
+
```toml
145
+
# merged configuration
146
+
allow_duplicate_keys = true
147
+
line_length = 100
148
+
preserve_quotes = false
149
+
```
150
+
151
+
## Custom config-files
152
+
153
+
A cli-argument `-c` (`--config-file`) can be provided multiple times to read configuration values from `toml` formatted files. If `-c` is provided, the default configuration files are ignored. The rightmost value-files override the value-files preceding them, only trumped by environment variables. No section headers are necessary for these configuration files, as the expected behaviour is, that those files contain only configuration related to `yamlfix`. For example:
Configure the base config-path that `maison` will look for a `pyproject.toml` configuration file. This path is traversed upwards until such a file is found.
313
+
Configure the base config-path that `maison` will look for a `pyproject.toml`, `.yamlfix.toml`, or `yamlfix.toml` configuration file. This path is traversed upwards until such a file is found.
0 commit comments