First time here? Check out the FAQ!
1

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

Hi!

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

[tool.black]
line-length = 120

When I manually run python -m black some/project/file.py 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/file.py 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)?

heyman's avatar
11
heyman
asked 2020-12-03 10:12:26 -0500
Wingware Support's avatar
3.9k
Wingware Support
updated 2020-12-08 16:28:19 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

0

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.

Wingware Support's avatar
3.9k
Wingware Support
answered 2020-12-04 10:40:19 -0500
edit flag offensive 0 remove flag delete link

Comments

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

heyman's avatar 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's avatar 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's avatar 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's avatar 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's avatar heyman (2020-12-11 04:13:08 -0500) edit
add a comment see more comments

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss.

Add Answer