I am using Black inside PyCharm to format my Python code.
I am using the Black-Pycharm plugin, unfortunately, selecting code and applying Black on it (Code > Reformat Code (BLACK)
) cuts all my lines at 88 characters (the default limit for Black).
I want to change this limit to cut the lines at 80 characters. I tried two different ways:
Changing the Black exe path in the "Black plugin settings" from
~/.local/bin/black
to~/.local/bin/black -l80
, but applying Black with PyCharm outputs this error:BlackPycharm: Cannot run program "/home/BCT/.local/bin/black -l80": error=2, File or folder not found
Using Black as an 'External Tool' in Pycharm (as described here), and specifying the line length in the arguments text box. This successfully applies Black on my file with the desired character limit, but:
- It automatically saves/replaces my file with the new formatted file, I can't undo the change.
- I can't apply Black on a portion of code only.
Do you know ways to use Black with:
- The ability to specify a desired line length
- The ability to reformat only a portion of code
at the same time ?
EDIT: Apparently PyCharm cannot use Black for only a portion of code...