How to configure YAPF to format the same way as Black

2k Views Asked by At

Black won't work on my computer but I want YAPF to function the same way black does. Is there a way to change the custom settings of YAPF to format the exact same way as black? I figure black is industry standard and want to follow that. What settings should I change? Are there any repositories I can just copy?

1

There are 1 best solutions below

0
Grodriguez On

I don't think you can get yapf to behave exactly like black, however the following would be a good start:

  • Select the built-in 'facebook' style
  • Set line-length to 88 characters (like black does)

i.e.:

yapf --style='{based_on_style: facebook, column_limit: 88}' somefile.py

With this you already get similar results to what black would do with the --skip-string-normalization option. It might be possible to get even closer by tweaking some knobs.