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

-e/--exclude doesn't work with pre-commit #60

Open
valentincalomme opened this issue Oct 13, 2020 · 11 comments
Open

-e/--exclude doesn't work with pre-commit #60

valentincalomme opened this issue Oct 13, 2020 · 11 comments
Assignees
Labels
bug Something isn't working help wanted Help! I have a full time job and would love contributions!

Comments

@valentincalomme
Copy link

Environment

  • interrogate version: 1.3.1
  • Operating System(s): Windows
  • Python version(s): 3.7.7

Description of the bug

Using the -e/--exclude argument works perfectly fine when using interrogate directly on the command line. However, when I pass it in my .pre-commit-config.yaml file like so:

- repo: https://github.com/econchick/interrogate
      rev: 1.3.1 # or master if you're bold
      hooks:
          - id: interrogate
            args: [--exclude=tests, --fail-under=100]

The argument doesn't seem to take effect. So far, I have resulted to using --ignore-regex which does work and achieves the same goal. Still, strange that --exclude doesn't seem to work. Maybe I am doing something wrong?

What you expected to happen

I expected --exclude to work using pre-commit.

@valentincalomme valentincalomme added bug Something isn't working needs triage Issue needs triaging labels Oct 13, 2020
@econchick
Copy link
Owner

Seems like a reasonable expectation :) Thanks for the issue! I'll try to set some time aside over the next week to look deeper into this.

@econchick econchick added help wanted Help! I have a full time job and would love contributions! and removed needs triage Issue needs triaging labels Oct 13, 2020
@valentincalomme
Copy link
Author

Thanks a lot!

I am a bit curious about why it doesn't work. One of my guesses is that I am pointed to a directory that doesn't exist given the working directory within pre-commit. But since interrogate doesn't throw an error when an exclude pattern isn't found, I can't know for sure.

For my use case, it isn't the most urgent since I can simply ignore test files/functions using a regex.

@econchick
Copy link
Owner

Defining exclude in your project's configuration then provide it as an argument to pre-commit could also help if you don't want to get too complicated with regexes (I do that). You can also use pre-commit's exclude functionality, too (similarly, I do that for sanity, even though it's in my pyproject.toml). But yeah I'm definitely curious too, it should work.

@valentincalomme
Copy link
Author

valentincalomme commented Oct 13, 2020

That's indeed why it's strange. I defined exclude in my pyproject.toml and it works perfectly fine when I use run interrogate. But when I define it the same way in pre-commit, it doesn't seem to pick it up.

@MarcoGorelli
Copy link
Contributor

MarcoGorelli commented Oct 18, 2020

In case it's useful to you, as a stopgap solution, you could use pre-commit's own exclude:

- repo: https://github.com/econchick/interrogate
      rev: 1.3.1 # or master if you're bold
      hooks:
          - id: interrogate
            args: [--fail-under=100]
            exclude: ^tests/

@s-weigand
Copy link
Contributor

s-weigand commented Nov 29, 2020

My solution is adding pass_filenames to the hook

  - repo: https://github.com/econchick/interrogate
    rev: 1.3.2
    hooks:
      - id: interrogate
        args: [-vv, --config=pyproject.toml]
        pass_filenames: false

That way interrogate runs as if you were running it from CLI.

Maybe this should be part of the defaults for the hook?

@sshishov
Copy link

The same issue as in isort fixed by PR 939 and black fixed by PR 1032

Same problem was happening with flake8 and happening now with typos

@joshdunnlime
Copy link

My solution is adding pass_filenames to the hook

  - repo: https://github.com/econchick/interrogate
    rev: 1.3.2
    hooks:
      - id: interrogate
        args: [-vv, --config=pyproject.toml]
        pass_filenames: false

That way interrogate runs as if you were running it from CLI.

Maybe this should be part of the defaults for the hook?

This saved me a LOT of pain. Thank you

@mathbr10
Copy link

For me this is happening with every argument -i, -I, -m. Any of them work in pre-commit

@ayushthe1
Copy link

has this issue been fixed yet ?

@dandluu
Copy link

dandluu commented Apr 24, 2024

I also have an issue when I set this in my propject.toml. I think it could be exclusive to the test folder.

In my toml I have for interrogate:

# propject.toml
[tool.interrogate]
ignore-init-method = true
ignore-init-module = false
ignore-magic = false
ignore-semiprivate = false
ignore-private = false
ignore-property-decorators = false
ignore-module = false
ignore-nested-functions = false
ignore-nested-classes = true
ignore-setters = false
exclude = ["tests", "setup.py", "docs", "build", "cicd_scripts", ".vscode"]
ignore-regex = ["^get$", "^mock_.*", ".*BaseClass.*"]
fail-under = 80
verbose = 2
quiet = false
whitelist-regex = []
color = true
generate-badge = "."
badge-format = "svg"

Running pre-commit run --all-files will fail as it includes the tests folder, however if I run interrogate -c pyproject.toml
It will show pass and tests will not be included the output.

However, in my .pre-commit-config.yaml

If I provide:

# .pre-commit-config.yaml
- repo: https://github.com/econchick/interrogate
    rev: 1.7.0
    hooks:
      - id: interrogate
        args: [-c, pyproject.toml]
        exclude: tests

pre-commit run --all-files will properly exclude tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Help! I have a full time job and would love contributions!
Projects
None yet
Development

No branches or pull requests

9 participants