Skip to content

Commit

Permalink
MNT: update linters (#150)
Browse files Browse the repository at this point in the history
* update

* split

* fix black [skip azp]

* fix isort

* fix

* fix pylint

* add more checks

* fix codespell

* fix

* fix

* fix

* ignore

* remove cruft
  • Loading branch information
GuillaumeFavelier authored Mar 4, 2022
1 parent 698d729 commit 4774de7
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 30 deletions.
38 changes: 26 additions & 12 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,32 @@ on:
jobs:
build:
runs-on: ubuntu-20.04
env:
PYTHON_VERSION: '3.9'
steps:
- uses: actions/checkout@v2
- name: Python Code Quality and Lint
uses: ricardochaves/python-lint@v1.3.0
- uses: actions/setup-python@v2
with:
python-root-list: pyvistaqt
use-pylint: true
extra-pylint-options: --disable=F0401
use-pycodestyle: true
use-flake8: true
use-black: true
use-mypy: true
use-isort: true
extra-pycodestyle-options: --ignore=E501,E203,W503
extra-flake8-options: --ignore=E501,E203,W503
python-version: ${{ env.PYTHON_VERSION }}
name: 'Setup python'
- run: |
python -m pip install --upgrade pip wheel
pip install -r requirements_test.txt
pip install --upgrade black isort pylint pycodestyle mypy flake8 codespell pydocstyle
name: 'Install dependencies with pip'
- run: make black
name: 'Run black'
- run: make isort
name: 'Run isort'
- run: make pylint
name: 'Run pylint'
- run: make pycodestyle
name: 'Run pycodestyle'
- run: make mypy
name: 'Run mypy'
- run: make flake8
name: 'Run flake8'
- run: make codespell
name: 'Run codespell'
- run: make pydocstyle
name: 'Run pydocstyle'
7 changes: 5 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# 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=PyQt5, vtk
extension-pkg-whitelist=vtk

# Specify a score threshold to be exceeded before program exits with error.
fail-under=10
Expand Down Expand Up @@ -139,7 +139,10 @@ disable=print-statement,
deprecated-sys-function,
exception-escape,
comprehension-escape,
bad-continuation
bad-continuation,
arguments-differ,
no-name-in-module,
no-member

# 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
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ PYLINT_DIRS ?= ./pyvistaqt/
MYPY_DIRS ?= ./pyvistaqt/
FLAKE8_DIRS ?= ./pyvistaqt/
CODESPELL_DIRS ?= ./
CODESPELL_SKIP ?= "*.pyc,*.txt,*.gif,*.png,*.jpg,*.ply,*.vtk,*.vti,*.js,*.html,*.doctree,*.ttf,*.woff,*.woff2,*.eot,*.mp4,*.inv,*.pickle,*.ipynb,flycheck*,./.git/*,./.hypothesis/*,*.yml,./docs/_build/*,./docs/images/*,./dist/*,./.ci/*"
CODESPELL_SKIP ?= "*.json,*.pyc,*.txt,*.gif,*.png,*.jpg,*.ply,*.vtk,*.vti,*.js,*.html,*.doctree,*.ttf,*.woff,*.woff2,*.eot,*.mp4,*.inv,*.pickle,*.ipynb,flycheck*,./.git/*,./.hypothesis/*,*.yml,./docs/_build/*,./docs/images/*,./dist/*,./.ci/*"
CODESPELL_IGNORE ?= "ignore_words.txt"
EXTRA_PYCODESTYLE_OPTIONS ?= --ignore="E501,E203,W503"
EXTRA_FLAKE8_OPTIONS ?= --ignore="E501,E203,W503"
Expand All @@ -20,15 +20,15 @@ doctest: codespell pydocstyle

black:
@echo "Running black"
@black $(BLACK_DIRS)
@black --check $(BLACK_DIRS)

isort:
@echo "Running isort"
@isort $(ISORT_DIRS)
@isort --check $(ISORT_DIRS)

pylint:
@echo "Running pylint"
@pylint $(PYLINT_DIRS)
@pylint $(PYLINT_DIRS) --rcfile=.pylintrc

pycodestyle:
@echo "Running pycodestyle"
Expand Down
2 changes: 1 addition & 1 deletion pyvistaqt/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, count: int) -> None:
self.count = count
elif count > 0:
raise TypeError(
"Expected type of `count` to be `int` but got: {}".format(type(count))
f"Expected type of `count` to be `int` but got: {type(count)}"
)
else:
raise ValueError("count is not strictly positive.")
Expand Down
2 changes: 1 addition & 1 deletion pyvistaqt/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Initialize the double slider."""
super().__init__(*args, **kwargs)
self.decimals = 5
self._max_int = 10 ** self.decimals
self._max_int = 10**self.decimals

super().setMinimum(0)
super().setMaximum(self._max_int)
Expand Down
2 changes: 1 addition & 1 deletion pyvistaqt/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def update(self) -> None:
for idx, renderer in enumerate(self.renderers):
actors = renderer._actors # pylint: disable=protected-access
widget_idx = self.stacked_widget.addWidget(_get_renderer_widget(renderer))
top_item = QTreeWidgetItem(self.tree_widget, ["Renderer {}".format(idx)])
top_item = QTreeWidgetItem(self.tree_widget, [f"Renderer {idx}"])
top_item.setData(0, Qt.ItemDataRole.UserRole, widget_idx)
self.tree_widget.addTopLevelItem(top_item)
for name, actor in actors.items():
Expand Down
12 changes: 5 additions & 7 deletions pyvistaqt/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@
class _GlobalTheme:
"""Wrap global_theme too rcParams."""

def __setattr__(self, k: str, v: Any) -> None: # noqa: D105
rcParams[k] = v
def __setattr__(self, k: str, val: Any) -> None: # noqa: D105
rcParams[k] = val

def __getattr__(self, k: str) -> None: # noqa: D105
return rcParams[k] if k != "__wrapped__" else None
Expand Down Expand Up @@ -285,7 +285,7 @@ def __init__(
# Modified() and upstream objects won't be updated. This
# ensures the render window stays updated without consuming too
# many resources.
twait = int((auto_update ** -1) * 1000.0)
twait = int((auto_update**-1) * 1000.0)
self.render_timer.timeout.connect(self.render)
self.render_timer.start(twait)

Expand Down Expand Up @@ -419,7 +419,7 @@ def dragEnterEvent(self, event: QtGui.QDragEnterEvent) -> None:
# only call accept on files
event.accept()
except IOError as exception: # pragma: no cover
warnings.warn("Exception when dropping files: %s" % str(exception))
warnings.warn(f"Exception when dropping files: {str(exception)}")

# pylint: disable=invalid-name,useless-return
def dropEvent(self, event: QtCore.QEvent) -> None:
Expand Down Expand Up @@ -816,9 +816,7 @@ def load_camera_position() -> None:
# pylint: disable=attribute-defined-outside-init
self.camera_position = camera_position

self.saved_cameras_tool_bar.addAction(
"Cam %2d" % ncam, load_camera_position
)
self.saved_cameras_tool_bar.addAction(f"Cam {ncam}", load_camera_position)
if ncam < 10:
self.add_key_event(str(ncam), load_camera_position)

Expand Down
4 changes: 2 additions & 2 deletions pyvistaqt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def _check_type(var: Any, var_name: str, var_types: List[Type[Any]]) -> None:
types = tuple(var_types)
if not isinstance(var, types):
raise TypeError(
"Expected type for ``{}`` is {}"
" but {} was given.".format(var_name, str(types), type(var))
f"Expected type for ``{var_name}`` is {str(types)}"
f" but {type(var)} was given."
)


Expand Down

0 comments on commit 4774de7

Please sign in to comment.