-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(config): Support --config
in pyproject.toml
#2525
base: main
Are you sure you want to change the base?
Conversation
6698c9f
to
f6e1aad
Compare
Thanks for getting this started as well! Couple of discussion points:
|
I haven't taken a deep look at the code nor played with the feature locally but I do quickly want to mention we should probably somehow indicate we using a configuration file via indirection in verbose mode. Honestly I'm not sure what's up with the weird merging / overriding behaviour here, but I'd suggest to keep it simple for now and just treat a config value in config file (regardless if was explicitly given or implicitly discovered) as a HTTP 302 redirect. |
Question: Should the config be overwritten if it is passed through the CLI option |
I'm confused by what you mean, can you further explain what scenario we're talking about here? Do you mean whether |
There are two ways configs are loaded, (1) they are passed by the user through |
Ah this is relevant because you handled those two cases differently. I'd say treat them the same as a HTTP 302 redirect but for configuration for simplicity. If the config key was found in pyproject.toml, ignore the rest and switch to the file specified. Same thing with the --config option, if present, just start the configuration loading process at its filepath. I feel like adding another merging rule on top of the "CLI options override options defined in a configuration file" merge rule will just overcomplicate things. Afterall --config is intended as an explicit way to force Black to use a specific configuration file (instead of searching for one) and nothing more. If the configuration file specified by Also you know we're on Python Discord right? It might be easier to discuss in the #black-formatter channel ^^ |
Yeah, I am on discord also ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Richard also raised a good point about chaining this value in the original issue. I tend towards chaining being supported, which would require a loop of some sort to follow the TOML files.
Also, I think it would be more consistent to just require all TOMLs to have the same structure, i.e. a tool.black
section instead of some other magical section. That way we could probably simplify the implementation and also solve chain cycles by looping through the files with an iteration threshold.
By chaining do you mean you can specify |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking better already, here's some comments:
0c516ef
to
88c80c2
Compare
You can now specify `config` key in pyproject.toml which does the same job as the CLI option `--config`. The path of config should be relative to the CWD it is running from. If the file is not found or is invalid i.e. it is a folder rather a TOML file it would raise `click.exceptions.FileError`, and if the file can't be parsed it would raise `tomli.TOMLDecodeError`. All black config keys in the custom config should be registered under `[black]` and they would overwrite the config specified in pyproject but not the one specified by `--config` flag while running black with the CLI. Closes psf#1826
There are two ways configs are loaded, (1) they are passed by the user through `--config` flag and (2) the `pyproject.toml` is found in the `src`. So currently when we find the `config` key we check whether if it is found by the config found in `pyproject.toml` or it is found in the one passed by the user via `--config` option. In this commit, the above check has been dropped, and if config key found in any of the config, it would overwrite it no matter what.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not do a hands-on test as I'm far too annoyed right now to do so but here's some initial feedback. We also need to check the pypy coverage drop.
…07/black into feat/pyproject-config
52de08f
to
cb5846e
Compare
This has a merge conflict without an obvious fix, could you take a look? |
491b467
to
092027b
Compare
092027b
to
d9776b8
Compare
@ichard26 are you happy with this PR now? |
Hey all, I'll try to review this soon (especially since IIRC I had some outstanding comments I never shared the last time I looked at this), but I can't make promises. |
@ichard26 any chance to push it forward? |
I was looking for the usecase described in #1826 and came across this PR If I can help with something to push this forward, I'm happy to help |
@ichard26 Just a reminder to take a look please. |
See also #1826 (comment) |
Description
You can now specify
config
key in pyproject.toml which does the same job as the CLI option--config
. The path of config should be relative to the CWD it is running from. If the file is not found or is invalid i.e. it is a folder rather a TOML file it would raiseclick.exceptions.FileError
, and if the file can't be parsed it would raisetomli.TOMLDecodeError
. All black config keys in the custom config should be registered under[black]
and they would overwrite the config specified in pyproject but not the one specified by--config
flag while running black with the CLI.I also did a small update to
.gitignore
by grouping the "test" and addinghtmlcov
to it. Which is generated bycoverage html
and.pytest_cache/
produced when you runpytest .
.Closes #1826
Checklist - did you ...