Skip to content

Commit

Permalink
fix(pre-commit): fix file passing errors
Browse files Browse the repository at this point in the history
`pre-commit` is known to override behavior from config files in
certain instances. This commit fixes known issues for:

- `isort`
- `black`
- `mypy`

For relevant details, see:

isort:
  + https://jugmac00.github.io/blog/isort-and-pre-commit-a-friendship-with-obstacles/
  + PyCQA/isort#885

black:
  + psf/black#1584

mypy:
  + python/mypy#4008 (comment)
  + https://pre-commit.com/#hooks-pass_filenames
  • Loading branch information
adamgranthendry committed Jun 28, 2022
1 parent a914a24 commit d040a4d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
9 changes: 8 additions & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ force_grid_wrap=0
use_parentheses=True
line_length=88
ensure_newline_before_comments=True
extend_skip_glob=tests/*.py,docs/*.py,setup.py
extend_skip_glob=tests/*.py,docs/conf.py,setup.py,pyvistaqt/rwi.py
# `pre-comment` doesn't see skips; `filter_files=True` forces it
# to see these files
#
# See:
# - https://jugmac00.github.io/blog/isort-and-pre-commit-a-friendship-with-obstacles/
# - https://github.com/PyCQA/isort/issues/885
filter_files=True
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ repos:
rev: v0.961
hooks:
- id: mypy
language: system
# `pass_filenames` is used to overcome the "duplicate module"
# error from occuring. We are explicitly passing a 'txt'
# file to search. This setting tells `pre-commit` to not do a
# search and pass files to check to mypy, like it normally does.
#
# See:
# - https://github.com/python/mypy/issues/4008#issuecomment-708060733
# - https://pre-commit.com/#hooks-pass_filenames
pass_filenames: false
args: [
"--config-file",
"mypy.ini",
Expand Down
14 changes: 13 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@
line-length = 88
skip-string-normalization = true
target-version = ["py39"]
exclude='\.eggs|\.git|\.mypy_cache|\.tox|\.venv|_build|buck-out|build|dist|node_modules|rwi\.py'
# `pre-comment` doesn't see skips; `force-exclude` forces it
# to see these files
#
# See:
# - https://github.com/psf/black/issues/1584
force-exclude = '''
(
docs/conf\.py
| pyvistaqt/rwi\.py
| tests/.*\.py
| setup.py
)
'''
check = true

[tool.pydocstyle]
Expand Down

0 comments on commit d040a4d

Please sign in to comment.