peterjc / flake8-black

flake8 plugin to run black for checking Python coding style
MIT License
166 stars 10 forks source link

Making flake8-black a pre-commit.com plugins #19

Closed avivajpeyi closed 4 years ago

avivajpeyi commented 4 years ago

I would like to use flake8-black as a precommit plugin (https://pre-commit.com/hooks.html). I have tried to set it up, but think I am making a mistake:

pre-commit run -a
[INFO] Initializing environment for https://github.com/avivajpeyi/flake8-black.
[INFO] Installing environment for https://github.com/avivajpeyi/flake8-black.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
flake8-black.............................................................Failed
hookid: flake8-black

Executable `flake8_black.py` not found

Would the flak8-black team have any suggestions?

peterjc commented 4 years ago

The python file flake8_black.py is not intended to be executed directly, only via flake8.

Looking at the pre-commit.com page you linked to, this example looks most relevant:

https://github.com/asottile/cheetah_lint/blob/master/.pre-commit-config.yaml https://github.com/asottile/cheetah_lint/blob/master/.pre-commit-hooks.yaml

However, you are probably better off just calling black --check directly without the need for flake8 or the flake8-black plugin.

i.e. Something based on this but adding the --check argument (rather than the default of just editing the files)?

https://github.com/psf/black/blob/master/.pre-commit-hooks.yaml

avivajpeyi commented 4 years ago

Ok, so you are suggesting to use black and flake8 instead of flake8-black:

-   id: black
    name: black
    description: runs black 
    entry: black --check
    language: python
-   id: flake
    name: flake
    description: runs flake8
    entry: flake8 --check
    language: python
peterjc commented 4 years ago

Calling black --check is one solution, it does not need flake8 at all.

You could still use flake8-black just like any other flake8 plugin - I don't know of a good example to point you at, but the key is probably just adding the plugin as a dependency to ensure it is installed too.

asottile commented 4 years ago

to use flake8 with plugins you'd use (for example):

repos:
-   repo: https://gitlab.com/pycqa/flake8
    rev: 3.7.9
    hooks:
    -   id: flake8
        additional_dependencies: [flake8-black==...]
peterjc commented 4 years ago

Thank you all for your input. Closing pull request having added a line to the README saying that with pre-commit you do not need flake8-black. I'm going to try this myself sooner or later...