Skip to content

Commit

Permalink
Add ruff linter config to pyproject.toml (#5304)
Browse files Browse the repository at this point in the history
* Add ruff linter config to pyproject.toml

* Revert which is not raise error

---------

Co-authored-by: Bane Sullivan <banesullivan@gmail.com>
  • Loading branch information
tkoyama010 and banesullivan committed Dec 12, 2023
1 parent 0eb941d commit b70494c
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,9 @@ repos:
rev: 0.27.2
hooks:
- id: check-github-workflows

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.7
hooks:
- id: ruff
args: [ --fix ]
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ PyVista
.. |pre-commit.ci status| image:: https://results.pre-commit.ci/badge/github/pyvista/pyvista/main.svg
:target: https://results.pre-commit.ci/latest/github/pyvista/pyvista/main

.. |Ruff| image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
:target: https://github.com/astral-sh/ruff
:alt: Ruff

+----------------------+------------------------+-------------+
| Deployment | |pypi| | |conda| |
Expand All @@ -80,6 +83,8 @@ PyVista
+----------------------+------------------------+-------------+
| Formatter | |black| | |isort| |
+----------------------+------------------------+-------------+
| Linter | |Ruff| |
+----------------------+------------------------+-------------+
| Affiliated | |NumFOCUS Affiliated| |
+----------------------+------------------------+-------------+

Expand Down
42 changes: 42 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,45 @@ exclude = [ # don't report on objects that match any of these regex
'\.PyVistaRemoteLocalView(\.|$)',
'\.Texture(\.|$)', # awaiting Texture refactor
]

[tool.ruff]
exclude = [
'.git',
'pycache__',
'build',
'dist',
'doc/examples',
'doc/_build',
]
line-length = 100
indent-width = 4
target-version = 'py39'

[tool.ruff.lint]
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",
# too many leading '#' for block comment
"E266",
# ambiguous variable name
"E741",
# module level import not at top of file
"E402",
# Quotes (temporary)
"Q0",
# bare excepts (temporary)
# "B001", "E722",
"E722",
# we already check black
# "BLK100",
# 'from module import *' used; unable to detect undefined names
"F403",
]
fixable = ["ALL"]
unfixable = []
2 changes: 1 addition & 1 deletion pyvista/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __getattr__(name):

try:
feature = inspect.getattr_static(sys.modules['pyvista.plotting'], name)
except AttributeError as e:
except AttributeError:
raise AttributeError(f"module 'pyvista' has no attribute '{name}'") from None

return feature
4 changes: 2 additions & 2 deletions pyvista/core/input_validation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Input validation functions."""
from .check import ( # noqa: 401
from .check import ( # noqa: F401
check_has_length,
check_has_shape,
check_is_arraylike,
Expand All @@ -24,7 +24,7 @@
check_is_subdtype,
check_is_type,
)
from .validate import ( # noqa: 401
from .validate import ( # noqa: F401
validate_array,
validate_array3,
validate_arrayN,
Expand Down
2 changes: 1 addition & 1 deletion pyvista/plotting/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def to_paraview_pvcc(self, filename: Union[str, Path]):
tmp.attrib["index"] = "0"

val = getattr(self, attr)
if type(val) is not bool:
if not isinstance(val, bool):
tmp.attrib["value"] = str(val)
e.append(tmp)
else:
Expand Down
1 change: 0 additions & 1 deletion pyvista/trame/ui/base_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import io

from trame.app import get_server
from trame.widgets import html
from trame_client.ui.core import AbstractLayout

import pyvista
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_datasetattributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def test_length_should_be_0_on_clear(insert_arange_narray):
def test_keys_should_be_strings(insert_arange_narray):
dsa, sample_array = insert_arange_narray
for name in dsa.keys():
assert type(name) is str
assert isinstance(name, str)


def test_key_should_exist(insert_arange_narray):
Expand Down
6 changes: 3 additions & 3 deletions tests/core/test_input_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def test_validate_number():
validate_number([2.0])
num = validate_number(1)
assert num == 1
assert type(num) is int
assert isinstance(num, int)

num = validate_number(2.0, to_list=False, must_have_shape=(), reshape=False)
assert num == 2.0
Expand Down Expand Up @@ -504,11 +504,11 @@ def test_validate_array(
# Check output
if np.array(array_in).ndim == 0 and (to_tuple or to_list):
# test scalar input results in scalar output
assert type(array_out) is float or type(array_out) is int
assert isinstance(array_out, float) or isinstance(array_out, int)
elif to_tuple:
assert type(array_out) is tuple
elif to_list:
assert type(array_out) is list
assert isinstance(array_out, list)
else:
assert isinstance(array_out, np.ndarray)
assert array_out.dtype.type is dtype_out
Expand Down

0 comments on commit b70494c

Please sign in to comment.