interrogate
interrogate copied to clipboard
-e/--exclude doesn't work with pre-commit
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.
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.
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.
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.
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.
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/
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?
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
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
For me this is happening with every argument -i, -I, -m. Any of them work in pre-commit
has this issue been fixed yet ?
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.