-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Configuration #65
Comments
I keep the number of command-line options to Would a shell alias work for you instead?
|
mild +1 The way I see it, the main benefit from config files for formatters is to be able to commit them to the repo.
and then remember to say Then you'll have editor integrations (format on save). Ideally you could just have:
If there's no config, then each dev needs to set a custom path to the Long story short, having a config helps with having uniform configuration in a project and saves a few workarounds. OTOH: all this for |
If you do have a config file, don't use |
It's disappointing the PEP doesn't mention setup.cfg at all. It's not clear what the advantage is and doesn't address migration of tooling configuration from the old file to the new file. |
From the perspective of a tool like black, the advantages are (1) TOML is a much nicer format than .cfg, (2) no one has to use setup.cfg, but many projects will have to use pyproject.toml. In particular, it's the only working way to specify build-time dependencies, and it will be where projects specify which build system they're using (see PEP 517) if they don't want to use distutils. (We did consider standardizing setup.cfg of course, but the cfg format is pretty bad, it's specifically supposed to be the config file for setup.py which we're trying to deprecate, and then other projects have also jammed stuff in there in an ad hoc way. Migration is kind of up to individual projects, since there's never been any standard for using setup.cfg so who knows what different projects have done. For a project like pbr that's deeply tied to distutils/setuptools, continuing to use setup.cfg probably makes most sense. For a project like pytest that just use setup.cfg as one of the like 4 places they check for config data, migration probably just means adding pyproject.toml to the list of places they check, and then maybe starting a deprecation cycle for setup.cfg-based config, if they feel like it. And for a project like black, you can ignore all this nonsense altogether and pretend setup.cfg never existed :-).) |
I agree with everything you're saying but this really belongs in the PEP and not a comment on a random issue on a random unrelated project on GitHub. cc @ncoghlan I mostly feel bad for what people like @sigmavirus24 (with Flake8) will have to do to support 3+ distinct configuration files now, having to codify precedence rules and the like. And then, if I take your advice and ignore existence of This is why I am staying away from config files for as long as it will be feasible. |
@ambv yeah, config file support in Flake8 has been a nightmare. My main advice is to support 1 file, that is only ever project local and be done with it. That said, once you've give folks that cookie, they'll want you to support sub-project settings which I'm working towards in Flake8 but I'm not happy about. And no one has asked flake8 for pyproject.toml support yet. Also, I'm not entirely inclined to add support for that until community adoption is higher than what it seems to be today (my intuition is that it's below 5%). |
No tool has to keep their config in pyproject.toml. All in saying is that if you're a project that, today, is considering whether to start putting config into setup.cfg, then you should instead think about whether to put it in pyproject.toml.
I'm sure it's well below that; we're just at the very beginning of the adoption curve. I think right now the only project that uses it is towncrier? But the next pip release (due within the next few weeks) will start reading build dependencies out if it (like |
From a So For As an interim option, something you may want to consider is pointing folks towards the use of |
Eh, if you're going to ask people to add a new config file, they can create a |
I like the Tox idea because it's an integration framework, like CI or editor plugins. Lets people do exactly what they want while I can continue living in my naive zeroconfig fantasy world. |
Really any kind of automation makes that easy, tox, Makefiles, fabfile, pyinvoke, etc. There are lots of options and they're as flexible (and all can be checked-in to source control) as a config file as well as future proof. |
I wanted this feature but just went with adding a 'format' env to tox.ini with "black -l 79 foo" in it and that seems fine to me. (the arguments for 88 char line-length all make sense, but I have a small screen on my laptop and am frequently hacking in vim default-sized 80x25 xterms, so code with line lengths above the stanard pep8 length are difficult for me to deal with) The main reason I wanted it is so that it would be easy for devs with black installed to run |
Given additional functionality in 18.6b0, I'm looking at
When the user runs Better yet though: So unless somebody comes up with a brilliant solution for this, my current inclination is to support one configuration. That configuration would be searched for in the common base directory for all paths passed to While this won't enable people to nicely specify sub-directories which are, say, Python 3.6+ safe or use a custom line length (for tests/ or whatever), they can set up an exclude list in the base configuration for those directories, and configure them separately. That will require running |
|
So I do wish I had considered this in Flake8 a lot sooner. In essence, I think what I plan to do is (when I ever have the time) make it such that one config file can specify paths that have their own rules. This will simplify how we find/understand config but also allow the granularity that people want. In Flake8's case, we have an abstraction called the "StyleGuide" so I was thinking of making one extra layer that manages a set of StyleGuides based on the config file. I'm not sure that helps at all, but that's my 2 pence |
I agonized over this for some time over the weekend. I really don't want Black-specific configuration in the CLI as it creates a number of important issues:
I will hold off with this. For now I recommend sticking to the defaults which makes life easy. If custom integrations are necessary, I recommend one of:
The latter is already described in the documentation under "Version Control Integration". |
FWIW, I think that this is pretty important feature for black. Particularly given that I think within a singular project you're going to end up with people running black in many different locations, for pip I know that if we adopt black, there is a desire to have the following workflows work:
We might potentially also add
So that's 3, maybe 4 mechanisms of invocation, of which 2 of them would require basically just documenting a regex that uses have to copy/paste into their shell or another config file (and then convince them to update it if we ever need to adjust that regex). That's not a great situation to be in. In response to the problems listed in #65 (comment), i'd say:
That being said, I wouldn't support path based configuration. That seems like a rabbit hole of mess that you really don't want to be in. Generally supporting multiple formats for different files seems like a huge edge case (and goes against PEP8 to begin with, since consistency within a project is the most important constraint). |
I wonder what you think of http://flake8.pycqa.org/en/latest/user/options.html @ambv as an example of documenting the CLI and config file options together. |
The multiline regex handling jumped out at me as a little surprising... Maybe you should accept a list here? (TOML has types!) |
Isn’t that just normal Python behavior? You pass a string into the re module?
…Sent from my iPhone
On Jun 6, 2018, at 8:24 PM, Nathaniel J. Smith ***@***.***> wrote:
The multiline regex handling jumped out at me as a little surprising... Maybe you should accept a list here? (TOML has types!)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@njsmith, the configuration file literally passes data to the respective options in Click. I'm actually pretty proud of how concise this ended up being. The The multiline regex enables us to do rather fancy filtering if needed without me having to implement fancy globbing. |
That's how |
The `black` project decided not to support `setup.cfg`, but only `pyproject.toml` (see psf/black#65). In order to avoid multiple configuration places for our `black` defaults, I added this additional configuration file to the repo.
The `black` project decided not to support `setup.cfg`, but only `pyproject.toml` (see psf/black#65). In order to avoid multiple configuration places for our `black` defaults, I added this additional configuration file to the repo.
The `black` project decided not to support `setup.cfg`, but only `pyproject.toml` (see psf/black#65). In order to avoid multiple configuration places for our `black` defaults, I added this additional configuration file to the repo.
It would be nice if there was the option to store black's line length and --safe/--fast options in setup.cfg
The text was updated successfully, but these errors were encountered: