Black: how to only include Python files while using *

Created on 16 Apr 2019  路  1Comment  路  Source: psf/black

This is question I guess. I'm trying to run black on all Python files in a repository using:

black --check *

Which seems like a pretty common use-case. But there are .json (and other non-Python) files in that main directory and they are getting caught too. I tried excluding JSON files specifically:

black --check --exclude '\.json$' *

But that didn't change anything. I understand that the include/exclude options only happen for recursively reformatting and that maybe because they are in the root directory they aren't thought of as recursive targets.

This basically gets me what I want but it feels like there's a better way and I'm missing something obvious:

find . -name \*\.py |xargs black --check

Operating system: MacOS Mojave
Python version: 3.6
Black version: 19.3b0
Does also happen on master: yes

To answer the last question, you have two options:

  1. Use the online formatter at https://black.now.sh/?version=master, which will use the latest master branch.
  2. Or run black on your machine:

    • create a new virtualenv (make sure it's the same Python version);

    • clone this repository;

    • run pip install -e .;

    • make sure it's sane by running python setup.py test; and

    • run black like you did last time.

Most helpful comment

Uh, yeah I figured it out 2 minutes later:

black --check .

>All comments

Uh, yeah I figured it out 2 minutes later:

black --check .

Was this page helpful?
0 / 5 - 0 ratings