Skip to content

Commit

Permalink
Update Formatting Tools (#182)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
adam-grant-hendry and adamgranthendry committed Jun 29, 2022
1 parent a84558f commit a3886c2
Show file tree
Hide file tree
Showing 15 changed files with 254 additions and 99 deletions.
2 changes: 1 addition & 1 deletion .ci/azure-pipelines.yml
Expand Up @@ -52,7 +52,7 @@ stages:
inputs:
versionSpec: '3.7'
- script: |
pip install codespell pydocstyle
pip install codespell pydocstyle[toml]
make doctest
displayName: 'Run doctest'
Expand Down
4 changes: 4 additions & 0 deletions .codespellrc
@@ -0,0 +1,4 @@
[codespell]
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*
ignore-words-list = lod,byteorder,flem,parm,doubleclick,revered,PullRequest
quiet-level = 3
42 changes: 42 additions & 0 deletions .flake8
@@ -0,0 +1,42 @@
[flake8]
max-line-length = 88
exclude =
__pycache__,
.venv,
.cache,
.eggs
.git,
.tox,
*.egg-info,
*.pyc,
*.pyi,
build,
dist,
# This is adopted from VTK
pyvistaqt/rwi.py,
# Only lint source files
tests/*.py,
docs/*.py,
# Ignore errors here in this commit (fix in future PR)
pyvistaqt/*.py,
setup.py
max-complexity = 10
doctests = true
extend-ignore =
# whitespace before ':'
E203,
# line break before binary operator
W503,
# line length too long
E501,
# do not assign a lambda expression, use a def
E731,
# missing class docstring; use ``__init__`` docstring instead
D101,
# missing docstring in magic method
D105,
# Qt uses camelCase
N802
per-file-ignores =
# Allow re-export of modules at package level
__init__.py:F401
10 changes: 10 additions & 0 deletions .isort.cfg
@@ -1,6 +1,16 @@
[settings]
profile=black
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
use_parentheses=True
line_length=88
ensure_newline_before_comments=True
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
108 changes: 108 additions & 0 deletions .pre-commit-config.yaml
@@ -0,0 +1,108 @@
repos:
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
args: [
"--config=pyproject.toml"
]

- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
args: [
"--check",
"--settings=.isort.cfg"
]

- repo: https://github.com/pre-commit/mirrors-mypy
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:
- id: flake8
additional_dependencies: [
"flake8-black==0.3.2",
"flake8-isort==4.1.1",
"flake8-quotes==3.3.1",
]
args: [
"--config=.flake8"
]

- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
- id: codespell
args: [
"docs examples examples_flask pyvista tests",
"*.py *.rst *.md",
]

- repo: https://github.com/pycqa/pydocstyle
rev: 6.1.1
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
hooks:
- id: check-merge-conflict
- id: debug-statements
- id: no-commit-to-branch
args: [--branch, main]

# this validates our github workflow files
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.16.1
hooks:
- id: check-github-workflows

- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
args:
[
"-rn", # Only display messages
"-sn", # Don't display the score
"--rcfile=.pylintrc", # Specify rc file
]
- id: pycodestyle
name: pycodestyle
entry: pycodestyle
language: system
types: [python]
args:
[
"--config=./\\.pycodestyle",
]
8 changes: 8 additions & 0 deletions .pycodestyle
@@ -0,0 +1,8 @@
[pycodestyle]
ignore = E501,
E203,
W503
exclude = tests/*.py,
docs/*.py,
rwi.py
filename = pyvistaqt/*.py
93 changes: 16 additions & 77 deletions .pylintrc
Expand Up @@ -3,18 +3,25 @@
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code.
extension-pkg-whitelist=vtk
extension-pkg-whitelist=vtk,
PyQt5,
PySide2,
PyQt6,
PySide6

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

# Add files or directories to the blacklist. They should be base names, not
# paths.
ignore=CVS
ignore=rwi.py,
conf.py,
conftest.py,
setup.py # ignore and fix in future PR

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

# Python code to execute, usually for sys.path manipulation such as
# pygtk.require().
Expand Down Expand Up @@ -60,89 +67,21 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use "--disable=all --enable=classes
# --disable=W".
disable=print-statement,
parameter-unpacking,
unpacking-in-except,
old-raise-syntax,
backtick,
long-suffix,
old-ne-operator,
old-octal-literal,
import-star-module-level,
non-ascii-bytes-literal,
raw-checker-failed,
disable=raw-checker-failed,
bad-inline-option,
locally-disabled,
file-ignored,
suppressed-message,
useless-suppression,
deprecated-pragma,
use-symbolic-message-instead,
apply-builtin,
basestring-builtin,
buffer-builtin,
cmp-builtin,
coerce-builtin,
execfile-builtin,
file-builtin,
long-builtin,
raw_input-builtin,
reduce-builtin,
standarderror-builtin,
unicode-builtin,
xrange-builtin,
coerce-method,
delslice-method,
getslice-method,
setslice-method,
no-absolute-import,
old-division,
dict-iter-method,
dict-view-method,
next-method-called,
metaclass-assignment,
indexing-exception,
raising-string,
reload-builtin,
oct-method,
hex-method,
nonzero-method,
cmp-method,
input-builtin,
round-builtin,
intern-builtin,
unichr-builtin,
map-builtin-not-iterating,
zip-builtin-not-iterating,
range-builtin-not-iterating,
filter-builtin-not-iterating,
using-cmp-argument,
eq-without-hash,
div-method,
idiv-method,
rdiv-method,
exception-message-attribute,
invalid-str-codec,
sys-max-int,
bad-python3-import,
deprecated-string-function,
deprecated-str-translate-call,
deprecated-itertools-function,
deprecated-types-field,
next-method-defined,
dict-items-not-iterating,
dict-keys-not-iterating,
dict-values-not-iterating,
deprecated-operator-function,
deprecated-urllib-function,
xreadlines-attribute,
deprecated-sys-function,
exception-escape,
comprehension-escape,
bad-continuation,
arguments-differ,
no-name-in-module,
no-member
no-member,
# Redundant alias imports required for type hinting by PEP 484
useless-import-alias,
# Qt uses PascalCase
invalid-name,

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

0 comments on commit a3886c2

Please sign in to comment.