Skip to content

Commit

Permalink
Use ruff instead of flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
francesco-ballarin committed Nov 26, 2023
1 parent 227c350 commit 4611a9f
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 56 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,10 @@ jobs:
echo "[[tool.mypy.overrides]]" >> pyproject.toml
echo 'module = "dolfinx.*"' >> pyproject.toml
echo "ignore_missing_imports = true" >> pyproject.toml
sed -i 's@exclude = \[".eggs", "build", "dist"\]@exclude = [".eggs", "build", "dist", "rbnicsx/backends", "tests/unit/backends"]@g' pyproject.toml
sed -i 's@exclude = "(^\\\\.eggs|^build|^dist|conftest\\\\.py\$)"@exclude = "(^\\\\.eggs|^build|^dist|conftest\\\\.py\$|^rbnicsx/backends|^tests/unit/backends)"@g' pyproject.toml
- name: Run flake8 on python files
- name: Run ruff on python files
run: |
python3 -m flake8 .
python3 -m ruff .
- name: Run isort on python files
run: |
python3 -m isort --check --diff .
Expand Down Expand Up @@ -151,10 +150,10 @@ jobs:
python3 -m pytest --ipynb-action=create-notebooks --np=2 tutorials || (($?==$NO_TESTS_COLLECTED))
python3 -m pytest --ipynb-action=create-notebooks --tag-collapse --np=2 tutorials || (($?==$NO_TESTS_COLLECTED))
shell: bash
- name: Run flake8 on tutorial files
- name: Run ruff on tutorial files
if: startsWith(matrix.backend, 'none') != true
run: |
python3 -m nbqa flake8 .
python3 -m nbqa ruff .
- name: Run isort on tutorial files
if: startsWith(matrix.backend, 'none') != true
run: |
Expand Down
48 changes: 22 additions & 26 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,9 @@ docs = [
"sphinx"
]
lint = [
"flake8",
"flake8-annotations",
"flake8-docstrings",
"flake8-import-restrictions",
"flake8-isort",
"Flake8-pyproject",
"flake8-quotes",
"isort",
"mypy",
"ruff",
"yamllint"
]
tests = [
Expand All @@ -85,25 +80,6 @@ tutorials = [
"viskex @ git+https://github.com/viskex/viskex.git"
]

[tool.flake8]
max-line-length = 120
show-source = true
docstring-convention = "numpy"
inline-quotes = "double"
imr241_exclude = ["__future__", "rbnicsx", "rbnicsx.*"]
imr245_include = "*"
imr245_exclude = ["__future__", "rbnicsx", "rbnicsx.*"]
ignore = ["ANN101", "W503"]
exclude = [".eggs", "build", "dist"]
per-file-ignores = [
"rbnicsx/__init__.py: I001, I004",
"rbnicsx/**/__init__.py: F401",
"tutorials/0*.py: D100, F401, I004",
"tutorials/1*.py: D100, F401, I004",
"tutorials/**/0*.py: D100, F401, I004",
"tutorials/**/1*.py: D100, F401, I004"
]

[tool.isort]
line_length = 120
multi_line_output = 4
Expand Down Expand Up @@ -164,6 +140,26 @@ ignore_missing_imports = true
module = "ufl"
ignore_missing_imports = true

[tool.ruff]
line-length = 120
select = ["ANN", "D", "E", "F", "ICN", "N", "Q", "RUF", "W"]
ignore = ["ANN101"]

[tool.ruff.per-file-ignores]
"rbnicsx/**/__init__.py" = ["F401"]
"rbnicsx/**/*.py" = ["N802", "N803", "N806"]
"tests/unit/**/*.py" = ["N802", "N803", "N806"]
"tutorials/0*.py" = ["D100", "F401", "N803", "N806"]
"tutorials/1*.py" = ["D100", "F401", "N803", "N806"]
"tutorials/**/0*.py" = ["D100", "F401", "N803", "N806"]
"tutorials/**/1*.py" = ["D100", "F401", "N803", "N806"]

[tool.ruff.pycodestyle]
max-doc-length = 120

[tool.ruff.pydocstyle]
convention = "numpy"

[tool.scikit-build]
cmake.source-dir = "rbnicsx/_cpp"
wheel.packages = ["rbnicsx"]
Expand Down
2 changes: 0 additions & 2 deletions rbnicsx/_backends/functions_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,10 @@ def __len__(self: Self) -> int:

@typing.overload
def __getitem__(self: Self, key: int) -> Function: # pragma: no cover
"""Stub of __getitem__ for type checking. See the concrete implementation below."""
...

@typing.overload
def __getitem__(self: Self, key: slice) -> Self: # pragma: no cover
"""Stub of __getitem__ for type checking. See the concrete implementation below."""
...

def __getitem__(self: Self, key: typing.Union[int, slice]) -> typing.Union[Function, Self]:
Expand Down
2 changes: 1 addition & 1 deletion rbnicsx/_backends/online_tensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def __iter__(self) -> typing.Iterator[ # type: ignore[no-any-unimported]
typing.Tuple[int, int, petsc4py.PETSc.Mat]]:
"""Iterate over blocks."""
with contextlib.ExitStack() as wrapper_stack:
for (I, row_indices_) in enumerate(self._row_indices):
for (I, row_indices_) in enumerate(self._row_indices): # noqa: E741
for (J, col_indices_) in enumerate(self._col_indices):
wrapper = MatSubMatrixContextManager(self._A, row_indices_, col_indices_)
yield (I, J, wrapper_stack.enter_context(wrapper))
Expand Down
2 changes: 0 additions & 2 deletions rbnicsx/_backends/tensors_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,10 @@ def contraction( # type: ignore[no-any-unimported]
def __getitem__( # type: ignore[no-any-unimported]
self: Self, key: typing.Union[int, typing.Tuple[int, ...]]
) -> typing.Union[petsc4py.PETSc.Mat, petsc4py.PETSc.Vec]: # pragma: no cover
"""Stub of __getitem__ for type checking. See the concrete implementation below."""
...

@typing.overload
def __getitem__(self: Self, key: typing.Union[slice, typing.Tuple[slice, slice]]) -> Self: # pragma: no cover
"""Stub of __getitem__ for type checking. See the concrete implementation below."""
...

def __getitem__( # type: ignore[no-any-unimported]
Expand Down
2 changes: 0 additions & 2 deletions rbnicsx/_backends/tensors_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,10 @@ def __len__(self: Self) -> int:
@typing.overload
def __getitem__(self: Self, key: int) -> typing.Union[ # type: ignore[no-any-unimported]
petsc4py.PETSc.Mat, petsc4py.PETSc.Vec]: # pragma: no cover
"""Stub of __getitem__ for type checking. See the concrete implementation below."""
...

@typing.overload
def __getitem__(self: Self, key: slice) -> Self: # pragma: no cover
"""Stub of __getitem__ for type checking. See the concrete implementation below."""
...

def __getitem__(self: Self, key: typing.Union[int, slice]) -> typing.Union[ # type: ignore[no-any-unimported]
Expand Down
8 changes: 4 additions & 4 deletions rbnicsx/backends/projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def project_vector( # type: ignore[no-any-unimported] # noqa: F811


@plum.dispatch
def project_vector(*args, **kwargs): # type: ignore[no-untyped-def] # noqa: F811
def project_vector(*args, **kwargs): # type: ignore[no-untyped-def] # noqa: ANN002, ANN003, ANN201, F811
"""Project a linear form onto the reduced basis."""
raise NotImplementedError("The abstract case has not been implemented") # pragma: no cover

Expand Down Expand Up @@ -127,7 +127,7 @@ def project_vector_block( # type: ignore[no-any-unimported] # noqa: F811


@plum.dispatch
def project_vector_block(*args, **kwargs): # type: ignore[no-untyped-def] # noqa: F811
def project_vector_block(*args, **kwargs): # type: ignore[no-untyped-def] # noqa: ANN002, ANN003, ANN201, F811
"""Project a list of linear forms onto the reduced basis."""
raise NotImplementedError("The abstract case has not been implemented") # pragma: no cover

Expand Down Expand Up @@ -191,7 +191,7 @@ def project_matrix( # type: ignore[no-any-unimported] # noqa: F811


@plum.dispatch
def project_matrix(*args, **kwargs): # type: ignore[no-untyped-def] # noqa: F811
def project_matrix(*args, **kwargs): # type: ignore[no-untyped-def] # noqa: ANN002, ANN003, ANN201, F811
"""Project a bilinear form onto the reduced basis."""
raise NotImplementedError("The abstract case has not been implemented") # pragma: no cover

Expand Down Expand Up @@ -260,7 +260,7 @@ def project_matrix_block( # type: ignore[no-any-unimported] # noqa: F811


@plum.dispatch
def project_matrix_block(*args, **kwargs): # type: ignore[no-untyped-def] # noqa: F811
def project_matrix_block(*args, **kwargs): # type: ignore[no-untyped-def] # noqa: ANN002, ANN003, ANN201, F811
"""Project a matrix of bilinear forms onto the reduced basis."""
raise NotImplementedError("The abstract case has not been implemented") # pragma: no cover

Expand Down
4 changes: 3 additions & 1 deletion rbnicsx/backends/proper_orthogonal_decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ def proper_orthogonal_decomposition( # type: ignore[no-any-unimported] # noqa:


@plum.dispatch
def proper_orthogonal_decomposition(*args, **kwargs): # type: ignore[no-untyped-def] # noqa: F811
def proper_orthogonal_decomposition( # type: ignore[no-untyped-def] # noqa: ANN201, F811
*args, **kwargs # noqa: ANN002, ANN003
):
"""Compute the proper orthogonal decomposition of a set of snapshots or tensors."""
raise NotImplementedError("The abstract case has not been implemented") # pragma: no cover

Expand Down
8 changes: 4 additions & 4 deletions rbnicsx/online/projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def project_vector( # type: ignore[no-any-unimported] # noqa: F811


@plum.dispatch
def project_vector(*args, **kwargs): # type: ignore[no-untyped-def] # noqa: F811
def project_vector(*args, **kwargs): # type: ignore[no-untyped-def] # noqa: ANN002, ANN003, ANN201, F811
"""Project a linear form onto the reduced basis."""
raise NotImplementedError("The abstract case has not been implemented") # pragma: no cover

Expand Down Expand Up @@ -123,7 +123,7 @@ def project_vector_block( # type: ignore[no-any-unimported] # noqa: F811


@plum.dispatch
def project_vector_block(*args, **kwargs): # type: ignore[no-untyped-def] # noqa: F811
def project_vector_block(*args, **kwargs): # type: ignore[no-untyped-def] # noqa: ANN002, ANN003, ANN201, F811
"""Project a list of linear forms onto the reduced basis."""
raise NotImplementedError("The abstract case has not been implemented") # pragma: no cover

Expand Down Expand Up @@ -183,7 +183,7 @@ def project_matrix( # type: ignore[no-any-unimported] # noqa: F811


@plum.dispatch
def project_matrix(*args, **kwargs): # type: ignore[no-untyped-def] # noqa: F811
def project_matrix(*args, **kwargs): # type: ignore[no-untyped-def] # noqa: ANN002, ANN003, ANN201, F811
"""Project a bilinear form onto the reduced basis."""
raise NotImplementedError("The abstract case has not been implemented") # pragma: no cover

Expand Down Expand Up @@ -255,7 +255,7 @@ def project_matrix_block( # type: ignore[no-any-unimported] # noqa: F811


@plum.dispatch
def project_matrix_block(*args, **kwargs): # type: ignore[no-untyped-def] # noqa: F811
def project_matrix_block(*args, **kwargs): # type: ignore[no-untyped-def] # noqa: ANN002, ANN003, ANN201, F811
"""Project a matrix of bilinear forms onto the reduced basis."""
raise NotImplementedError("The abstract case has not been implemented") # pragma: no cover

Expand Down
6 changes: 4 additions & 2 deletions rbnicsx/online/proper_orthogonal_decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


@plum.overload
def proper_orthogonal_decomposition( # type: ignore[no-any-unimported] # noqa: F811
def proper_orthogonal_decomposition( # type: ignore[no-any-unimported]
functions_list: FunctionsList, inner_product: petsc4py.PETSc.Mat, N: int = -1,
tol: petsc4py.PETSc.RealType = real_zero, normalize: bool = True
) -> typing.Tuple[
Expand Down Expand Up @@ -99,7 +99,9 @@ def proper_orthogonal_decomposition( # type: ignore[no-any-unimported] # noqa:


@plum.dispatch
def proper_orthogonal_decomposition(*args, **kwargs): # type: ignore[no-untyped-def] # noqa: F811
def proper_orthogonal_decomposition( # type: ignore[no-untyped-def] # noqa: ANN201, F811
*args, **kwargs # noqa: ANN002, ANN003
):
"""Compute the proper orthogonal decomposition of a set of online snapshots or tensors."""
raise NotImplementedError("The abstract case has not been implemented") # pragma: no cover

Expand Down
2 changes: 1 addition & 1 deletion rbnicsx/online/tensors_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def flattened_shape(self) -> typing.Tuple[typing.Union[int, typing.List[int]], .
if isinstance(self._content_shape, tuple):
return self.shape + self.content_shape # type: ignore[operator]
else:
return self.shape + (self.content_shape, ) # type: ignore[operator]
return self.shape + (self.content_shape, ) # type: ignore[operator] # noqa: RUF005

@property
def content_shape(self) -> typing.Union[
Expand Down
2 changes: 0 additions & 2 deletions rbnicsx/test/order_of_magnitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

@typing.overload
def order_of_magnitude(numbers: typing.Union[float, np.float32, np.float64]) -> np.int32: # pragma: no cover
"""Stub of order_of_magnitude for type checking. See the concrete implementation below."""
...


Expand All @@ -24,7 +23,6 @@ def order_of_magnitude( # type: ignore[no-any-unimported]
np.typing.NDArray[typing.Union[np.float32, np.float64, petsc4py.PETSc.RealType]],
typing.List[typing.Union[np.float32, np.float64, petsc4py.PETSc.RealType]]]
) -> np.typing.NDArray[np.int32]: # pragma: no cover
"""Stub of order_of_magnitude for type checking. See the concrete implementation below."""
...


Expand Down
8 changes: 4 additions & 4 deletions tests/unit/online/test_online_tensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def test_online_vector_block_sub_vector_wrapper_context_manager() -> None:
for i in range(5):
online_vec.setValue(i, i + 1)
with rbnicsx.online.BlockVecSubVectorWrapper(online_vec, N) as online_vec_wrapper:
for (I, online_subvec) in enumerate(online_vec_wrapper):
for (I, online_subvec) in enumerate(online_vec_wrapper): # noqa: E741
assert isinstance(online_subvec, petsc4py.PETSc.Vec)
assert online_subvec.size == N[I]
for i in range(N[I]):
Expand All @@ -306,7 +306,7 @@ def test_online_vector_block_sub_vector_copier_context_manager() -> None:
for i in range(5):
online_vec.setValue(i, i + 1)
with rbnicsx.online.BlockVecSubVectorCopier(online_vec, N) as online_vec_copier:
for (I, online_subvec) in enumerate(online_vec_copier):
for (I, online_subvec) in enumerate(online_vec_copier): # noqa: E741
assert isinstance(online_subvec, petsc4py.PETSc.Vec)
assert online_subvec.size == N[I]
for i in range(N[I]):
Expand Down Expand Up @@ -372,7 +372,7 @@ def test_online_matrix_block_sub_matrix_wrapper_context_manager() -> None:
online_mat.setValue(i, j, i * 9 + j + 1)
online_mat.assemble()
with rbnicsx.online.BlockMatSubMatrixWrapper(online_mat, M, N) as online_mat_wrapper:
for (I, J, online_submat) in online_mat_wrapper:
for (I, J, online_submat) in online_mat_wrapper: # noqa: E741
assert isinstance(I, int)
assert isinstance(J, int)
assert isinstance(online_submat, petsc4py.PETSc.Mat)
Expand Down Expand Up @@ -400,7 +400,7 @@ def test_online_matrix_block_sub_matrix_copier_context_manager() -> None:
online_mat.setValue(i, j, i * 9 + j + 1)
online_mat.assemble()
with rbnicsx.online.BlockMatSubMatrixCopier(online_mat, M, N) as online_mat_copier:
for (I, J, online_submat) in online_mat_copier:
for (I, J, online_submat) in online_mat_copier: # noqa: E741
assert isinstance(I, int)
assert isinstance(J, int)
assert isinstance(online_submat, petsc4py.PETSc.Mat)
Expand Down

0 comments on commit 4611a9f

Please sign in to comment.