Black --exclude argument not excluding desired file(s)

Johnny Metz picture Johnny Metz · Nov 15, 2019 · Viewed 9k times · Source

Let's say I have the following python file exclude_from_black.py in the root of my project:

print('I want single quotes')

I'm trying to exclude this file from black reformatting but none of the following commands seem to work:

black --exclude="exclude_from_black.py"
black --exclude="exclude_from_black\.py"
black --exclude="exclude\_from\_black\.py"

According to the Documentation the exclude argument takes a regex. What am I doing something wrong here?

Answer

philippbosch picture philippbosch · Dec 11, 2019

I think you should omit the space after --exclude and wrap the regex in /…/.

Try black --exclude '/exclude_from_black\.py/'

Also, for debugging, -v should give some info about which files were excluded.