Skip to content

Commit a3886c2

Browse files
Update Formatting Tools (#182)
* refactor(trove-classifiers): update to python 3.7-3.9 * refactor(linters): add `.flake8` and `.codespellrc` configuration files Also add `PullRequest` to `ignore_words.txt` * feat(pyproject): add `pyproject.toml` Currently, this is only use for configuring linters and formatters (no build file specifications are set). Configuration options for `black` and `pydocstyle` are added here in this commit. * feat(pre-commit): add pre-commit * fix(mypy): add `mypy` dependency to `environment.yml` This supports conda test/build environments. * feat(pylint): Update `.pylintrc` Make this match settings specififed in `Makefile`. * feat(test): align checks All checks are placed in appropriate config files. Test runner scripts point to these so that there exists a single source of truth for all configurations and that the tests performed across systems is the same. This may be adjusted, of course, if different settings must be used on a per-system basis. * feat(requirements): add `toml` This package supports reading `pyproject.toml`, which is required for some of our tests. * fix(pre-commit): fix file passing errors `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 * feat(ignores): ignore specific linting errors Ignore linting errors in source code in this PR. The purpose of this PR is to update linting tools. A future PR will correct the errors. This is done to separate concerns. Co-authored-by: Hendry, Adam <adam.hendry@medtronic.com>
1 parent a84558f commit a3886c2

15 files changed

+254
-99
lines changed

.ci/azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ stages:
5252
inputs:
5353
versionSpec: '3.7'
5454
- script: |
55-
pip install codespell pydocstyle
55+
pip install codespell pydocstyle[toml]
5656
make doctest
5757
displayName: 'Run doctest'
5858

.codespellrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[codespell]
2+
skip = ./.ci/*,./.git/*,./.hypothesis/*,./dist/*,./doc/examples/*,./doc/images/*,./docs/_build/*,./docs/images/*,./tests/tinypages/_build/*,.hypothesis*,*.doctree,*.eot,*.gif,*.html,*.inv,*.ipynb,*.jpg,*.js,*.json,*.mp4,*.mypy_cache/*,*.pickle,*.ply,*.png,*.pyc,*.ttf,*.txt,*.vti,*.vtk,*.vtu,*.woff,*.woff2,*.yml,*/_autosummary/*,*~,*cover,doc/_build/*,flycheck*
3+
ignore-words-list = lod,byteorder,flem,parm,doubleclick,revered,PullRequest
4+
quiet-level = 3

.flake8

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[flake8]
2+
max-line-length = 88
3+
exclude =
4+
__pycache__,
5+
.venv,
6+
.cache,
7+
.eggs
8+
.git,
9+
.tox,
10+
*.egg-info,
11+
*.pyc,
12+
*.pyi,
13+
build,
14+
dist,
15+
# This is adopted from VTK
16+
pyvistaqt/rwi.py,
17+
# Only lint source files
18+
tests/*.py,
19+
docs/*.py,
20+
# Ignore errors here in this commit (fix in future PR)
21+
pyvistaqt/*.py,
22+
setup.py
23+
max-complexity = 10
24+
doctests = true
25+
extend-ignore =
26+
# whitespace before ':'
27+
E203,
28+
# line break before binary operator
29+
W503,
30+
# line length too long
31+
E501,
32+
# do not assign a lambda expression, use a def
33+
E731,
34+
# missing class docstring; use ``__init__`` docstring instead
35+
D101,
36+
# missing docstring in magic method
37+
D105,
38+
# Qt uses camelCase
39+
N802
40+
per-file-ignores =
41+
# Allow re-export of modules at package level
42+
__init__.py:F401

.isort.cfg

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
[settings]
2+
profile=black
23
multi_line_output=3
34
include_trailing_comma=True
45
force_grid_wrap=0
56
use_parentheses=True
67
line_length=88
8+
ensure_newline_before_comments=True
9+
extend_skip_glob=tests/*.py,docs/conf.py,setup.py,pyvistaqt/rwi.py
10+
# `pre-comment` doesn't see skips; `filter_files=True` forces it
11+
# to see these files
12+
#
13+
# See:
14+
# - https://jugmac00.github.io/blog/isort-and-pre-commit-a-friendship-with-obstacles/
15+
# - https://github.com/PyCQA/isort/issues/885
16+
filter_files=True

.pre-commit-config.yaml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: 22.3.0
4+
hooks:
5+
- id: black
6+
args: [
7+
"--config=pyproject.toml"
8+
]
9+
10+
- repo: https://github.com/pycqa/isort
11+
rev: 5.10.1
12+
hooks:
13+
- id: isort
14+
args: [
15+
"--check",
16+
"--settings=.isort.cfg"
17+
]
18+
19+
- repo: https://github.com/pre-commit/mirrors-mypy
20+
rev: v0.961
21+
hooks:
22+
- id: mypy
23+
# `pass_filenames` is used to overcome the "duplicate module"
24+
# error from occuring. We are explicitly passing a 'txt'
25+
# file to search. This setting tells `pre-commit` to not do a
26+
# search and pass files to check to mypy, like it normally does.
27+
#
28+
# See:
29+
# - https://github.com/python/mypy/issues/4008#issuecomment-708060733
30+
# - https://pre-commit.com/#hooks-pass_filenames
31+
language: system
32+
pass_filenames: false
33+
args: [
34+
"--config-file",
35+
"mypy.ini",
36+
"@mypy_checklist.txt"
37+
]
38+
39+
- repo: https://gitlab.com/PyCQA/flake8
40+
rev: 3.9.2
41+
hooks:
42+
- id: flake8
43+
additional_dependencies: [
44+
"flake8-black==0.3.2",
45+
"flake8-isort==4.1.1",
46+
"flake8-quotes==3.3.1",
47+
]
48+
args: [
49+
"--config=.flake8"
50+
]
51+
52+
- repo: https://github.com/codespell-project/codespell
53+
rev: v2.1.0
54+
hooks:
55+
- id: codespell
56+
args: [
57+
"docs examples examples_flask pyvista tests",
58+
"*.py *.rst *.md",
59+
]
60+
61+
- repo: https://github.com/pycqa/pydocstyle
62+
rev: 6.1.1
63+
hooks:
64+
- id: pydocstyle
65+
additional_dependencies: [toml==0.10.2]
66+
# We use the 'match' and do not want pre-commit to pass
67+
# globbed files
68+
pass_filenames: false
69+
args: [
70+
"--config=pyproject.toml",
71+
]
72+
73+
- repo: https://github.com/pre-commit/pre-commit-hooks
74+
rev: v4.3.0
75+
hooks:
76+
- id: check-merge-conflict
77+
- id: debug-statements
78+
- id: no-commit-to-branch
79+
args: [--branch, main]
80+
81+
# this validates our github workflow files
82+
- repo: https://github.com/python-jsonschema/check-jsonschema
83+
rev: 0.16.1
84+
hooks:
85+
- id: check-github-workflows
86+
87+
- repo: local
88+
hooks:
89+
- id: pylint
90+
name: pylint
91+
entry: pylint
92+
language: system
93+
types: [python]
94+
args:
95+
[
96+
"-rn", # Only display messages
97+
"-sn", # Don't display the score
98+
"--rcfile=.pylintrc", # Specify rc file
99+
]
100+
- id: pycodestyle
101+
name: pycodestyle
102+
entry: pycodestyle
103+
language: system
104+
types: [python]
105+
args:
106+
[
107+
"--config=./\\.pycodestyle",
108+
]

.pycodestyle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[pycodestyle]
2+
ignore = E501,
3+
E203,
4+
W503
5+
exclude = tests/*.py,
6+
docs/*.py,
7+
rwi.py
8+
filename = pyvistaqt/*.py

.pylintrc

Lines changed: 16 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,25 @@
33
# A comma-separated list of package or module names from where C extensions may
44
# be loaded. Extensions are loading into the active Python interpreter and may
55
# run arbitrary code.
6-
extension-pkg-whitelist=vtk
6+
extension-pkg-whitelist=vtk,
7+
PyQt5,
8+
PySide2,
9+
PyQt6,
10+
PySide6
711

812
# Specify a score threshold to be exceeded before program exits with error.
913
fail-under=10
1014

1115
# Add files or directories to the blacklist. They should be base names, not
1216
# paths.
13-
ignore=CVS
17+
ignore=rwi.py,
18+
conf.py,
19+
conftest.py,
20+
setup.py # ignore and fix in future PR
1421

1522
# Add files or directories matching the regex patterns to the blacklist. The
1623
# regex matches against base names, not paths.
17-
ignore-patterns=
24+
ignore-patterns=(?=(coverage|test_|rwi)).*[.]py
1825

1926
# Python code to execute, usually for sys.path manipulation such as
2027
# pygtk.require().
@@ -60,89 +67,21 @@ confidence=
6067
# --enable=similarities". If you want to run only the classes checker, but have
6168
# no Warning level messages displayed, use "--disable=all --enable=classes
6269
# --disable=W".
63-
disable=print-statement,
64-
parameter-unpacking,
65-
unpacking-in-except,
66-
old-raise-syntax,
67-
backtick,
68-
long-suffix,
69-
old-ne-operator,
70-
old-octal-literal,
71-
import-star-module-level,
72-
non-ascii-bytes-literal,
73-
raw-checker-failed,
70+
disable=raw-checker-failed,
7471
bad-inline-option,
7572
locally-disabled,
7673
file-ignored,
7774
suppressed-message,
7875
useless-suppression,
7976
deprecated-pragma,
8077
use-symbolic-message-instead,
81-
apply-builtin,
82-
basestring-builtin,
83-
buffer-builtin,
84-
cmp-builtin,
85-
coerce-builtin,
86-
execfile-builtin,
87-
file-builtin,
88-
long-builtin,
89-
raw_input-builtin,
90-
reduce-builtin,
91-
standarderror-builtin,
92-
unicode-builtin,
93-
xrange-builtin,
94-
coerce-method,
95-
delslice-method,
96-
getslice-method,
97-
setslice-method,
98-
no-absolute-import,
99-
old-division,
100-
dict-iter-method,
101-
dict-view-method,
102-
next-method-called,
103-
metaclass-assignment,
104-
indexing-exception,
105-
raising-string,
106-
reload-builtin,
107-
oct-method,
108-
hex-method,
109-
nonzero-method,
110-
cmp-method,
111-
input-builtin,
112-
round-builtin,
113-
intern-builtin,
114-
unichr-builtin,
115-
map-builtin-not-iterating,
116-
zip-builtin-not-iterating,
117-
range-builtin-not-iterating,
118-
filter-builtin-not-iterating,
119-
using-cmp-argument,
120-
eq-without-hash,
121-
div-method,
122-
idiv-method,
123-
rdiv-method,
124-
exception-message-attribute,
125-
invalid-str-codec,
126-
sys-max-int,
127-
bad-python3-import,
128-
deprecated-string-function,
129-
deprecated-str-translate-call,
130-
deprecated-itertools-function,
131-
deprecated-types-field,
132-
next-method-defined,
133-
dict-items-not-iterating,
134-
dict-keys-not-iterating,
135-
dict-values-not-iterating,
136-
deprecated-operator-function,
137-
deprecated-urllib-function,
138-
xreadlines-attribute,
139-
deprecated-sys-function,
140-
exception-escape,
141-
comprehension-escape,
142-
bad-continuation,
14378
arguments-differ,
14479
no-name-in-module,
145-
no-member
80+
no-member,
81+
# Redundant alias imports required for type hinting by PEP 484
82+
useless-import-alias,
83+
# Qt uses PascalCase
84+
invalid-name,
14685

14786
# Enable the message, report, category or checker with the given id(s). You can
14887
# either give multiple identifier separated by comma (,) or put this option

0 commit comments

Comments
 (0)