Ask Your Question

Auto-reformatting using Black doesn't use config in pyproject.toml

asked 2020-12-03 10:12:26 -0500

heyman gravatar image

updated 2020-12-08 16:28:19 -0500


I have configured the line-length for Black in a pyproject.toml:

line-length = 120

When I manually run python -m black some/project/ this is respected. However when I turn on auto reformatting using Black (set to "Whole Files Before Save") the specified line-length doesn't seem to be respected, and that results in a different output that what is produced by running python -m black some/project/ manually.

I suspect that Black might be invoked using the -c or --code flag with the whole file source being passed into it. That could explain why the issue happens, since Black won't know where to look for the config file.

Is this possible to fix somehow, or is it possible to add custom command line flags to the black command that WingPro executes (that I could use to manually add a --config flag)?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-12-04 10:40:19 -0500

Wing runs black on a temporary file in the tmp directory so black isn't finding the pyproject.toml.

If you enable the Enforce Line Length option in Wing's auto-formatter setting, a --line-length=# will be added to the black command line. The line length is set in the Editor > Line Wrapping preferences.

edit flag offensive delete link more


Thanks for the tip! How about other Black configuration settings?

heyman gravatar image heyman  ( 2020-12-08 05:02:51 -0500 )edit

Which options do you want to set? The point of Black is that it isn't really configurable and just does things the one sensible/correct way (or so they claim) so I don't think it has any support other than reading a pyproject.toml and we'ld have to find and copy that into the temp directory for that to work. I've tagged this a a feature request...

Wingware Support gravatar image Wingware Support  ( 2020-12-08 16:27:48 -0500 )edit

The option I'm currently looking to specify - apart from line length, that is already possible to set like you pointed out (thanks!) - is include and exclude.

heyman gravatar image heyman  ( 2020-12-11 04:03:37 -0500 )edit

For example, I'd like to add only the project directory to the included directories, so that if I edit a file outside of the project (that I've jumped into using "goto definition"), it doesn't reformat the whole external file.

heyman gravatar image heyman  ( 2020-12-11 04:07:47 -0500 )edit

Also, I think it makes much more sense to read the line-length from the pyproject.toml if one is declared there.

heyman gravatar image heyman  ( 2020-12-11 04:13:08 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2020-12-03 10:12:26 -0500

Seen: 639 times

Last updated: Dec 04 '20