Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local repo hooks not reading config files #1177

Closed
wesley-smith opened this issue Oct 17, 2019 · 4 comments
Closed

Local repo hooks not reading config files #1177

wesley-smith opened this issue Oct 17, 2019 · 4 comments
Labels

Comments

@wesley-smith
Copy link

I'm trying to run Black and Flake8 in a repository where devs and the CI system will already have these packages installed in a virtual environment. As such, I don't want pre-commit to worry about cloning/installing these repos.

I think the right way to do this is to configure a repo: local block, which has mostly worked for me so far. Here is what I have in .pre-commit-config.yaml:

repos:
-   repo: local
    hooks:
    - id: black
      name: black
      entry: python -m black
      language: system
      types: [python]
    - id: flake8
      name: flake8
      entry: python -m flake8
      language: system
      types: [python]

The problem I'm having is that neither of these tools are reading the config files that I have stored in the repository for them, i.e. pyproject.toml for Black and setup.cfg for Flake8. I've even gone so far as to specify the configuration settings as arguments to the hook, e.g. args: [--exclude=<exclude-regex>], but that still doesn't register the behavior I'd expect. The arguments appear to be passed to the script, but the formatting and linting doesn't match the configuration it should be getting.

My assumption is that each of these commands essentially maps to a shell invocation of the entry. For instance, the black hook should come out to python -m black <args> <staged-files>, launched from the same directory as the config files .pre-commit-config.yaml and pyproject.toml.

Am I mistaking how this should work, or is there something iffy going on here?

pre-commit --version
pre-commit 1.18.3

Thanks in advance!

@asottile
Copy link
Member

I suspect you're confused how black works -- flake8 has identical behaviour -- you want to use pre-commit's exclude: ....

My assumption is that each of these commands essentially maps to a shell invocation of the entry. For instance, the black hook should come out to python -m black , launched from the same directory as the config files .pre-commit-config.yaml and pyproject.toml.

your assumption is correct and documented -- have you tried python -m black file1.py file2.py ...? you should see the same exact behaviour

@wesley-smith
Copy link
Author

Perfect. My confusion was with files excluded by black and flake8 by not excluded by pre-commit. When I moved these exclusions into .pre-commit-config.yaml everything worked as expected.

Thanks for the quick help!

@asottile
Copy link
Member

cheers -- thanks for the issue!

@denkasyanov
Copy link

It seems another option now is to set force-exclude in pyproject.toml. It didn't work with black==19.10b0 but did work with master.
Related docs for black: https://black.readthedocs.io/en/latest/installation_and_usage.html?highlight=force-exclude#command-line-options.
Related PR in black: psf/black#1032

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants