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`
- `pydocstyle`

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/pydocstyle:
  + python/mypy#4008 (comment)
  + https://pre-commit.com/#hooks-pass_filenames
  • Loading branch information
adamgranthendry committed Jun 28, 2022
1 parent a914a24 commit a07f259
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 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
17 changes: 16 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,22 @@ repos:
rev: v0.961
hooks:
- id: mypy
# `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
language: system
pass_filenames: false
args: [
"--config-file",
"mypy.ini",
"@mypy_checklist.txt"
]


- repo: https://gitlab.com/PyCQA/flake8
rev: 3.9.2
hooks:
Expand Down Expand Up @@ -54,6 +63,12 @@ repos:
hooks:
- id: pydocstyle
additional_dependencies: [toml==0.10.2]
# We use the 'match' and do not want pre-commit to pass
# globbed files
pass_filenames: false
args: [
"--config=pyproject.toml",
]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
Expand Down
24 changes: 22 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,28 @@
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]
match = '(?!(coverage|test_|rwi)).*[.]py'
match = '''
(?!
(
| tests/
| docs/
| rwi
).*\.py
)
'''

0 comments on commit a07f259

Please sign in to comment.