interrogate icon indicating copy to clipboard operation
interrogate copied to clipboard

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

Open valentincalomme opened this issue 4 years ago • 11 comments

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 avatar Oct 13 '20 18:10 valentincalomme

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 avatar Oct 13 '20 19:10 econchick

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.

valentincalomme avatar Oct 13 '20 19:10 valentincalomme

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.

econchick avatar Oct 13 '20 19:10 econchick

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.

valentincalomme avatar Oct 13 '20 19:10 valentincalomme

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/

MarcoGorelli avatar Oct 18 '20 18:10 MarcoGorelli

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?

s-weigand avatar Nov 29 '20 18:11 s-weigand

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

sshishov avatar May 28 '22 18:05 sshishov

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

joshdunnlime avatar Jul 11 '22 11:07 joshdunnlime

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

mathbr10 avatar Aug 31 '22 20:08 mathbr10

has this issue been fixed yet ?

ayushthe1 avatar Dec 21 '23 19:12 ayushthe1

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.

dandluu avatar Apr 24 '24 20:04 dandluu