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 25, 2023
1 parent 474a81a commit f2bc322
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 37 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ jobs:
- name: Install multiphenicsx
run: |
python3 -m pip install --check-build-dependencies --no-build-isolation --config-settings=build-dir="build" --config-settings=cmake.build-type="Debug" --verbose .[docs,lint,tests,tutorials]
- 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 @@ -81,9 +81,9 @@ jobs:
python3 -m pytest --ipynb-action=create-notebooks tutorials || (($?==$NO_TESTS_COLLECTED))
python3 -m pytest --ipynb-action=create-notebooks --np=2 tutorials || (($?==$NO_TESTS_COLLECTED))
shell: bash
- name: Run flake8 on tutorial files
- name: Run ruff on tutorial files
run: |
python3 -m nbqa flake8 .
python3 -m nbqa ruff .
- name: Run isort on tutorial files
run: |
python3 -m nbqa isort --check --diff .
Expand Down
44 changes: 19 additions & 25 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,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 @@ -82,23 +77,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 = ["multiphenicsx", "multiphenicsx.*"]
imr245_include = "*"
imr245_exclude = ["multiphenicsx", "multiphenicsx.*"]
ignore = ["ANN101", "W503"]
exclude = [".eggs", "build", "dist"]
per-file-ignores = [
"multiphenicsx/**/__init__.py: F401",
"tests/notebooks/data/*.py: D100, I004",
"tutorials/**/tutorial_*.py: D100, I004",
"tutorials/**/generate_mesh*.py: D100, I004"
]

[tool.isort]
line_length = 120
multi_line_output = 4
Expand All @@ -108,7 +86,6 @@ order_by_type = false
check_untyped_defs = true
disallow_any_unimported = true
disallow_untyped_defs = true
exclude = "(^\\.eggs|^build|^dist|conftest\\.py$)"
implicit_reexport = true
no_implicit_optional = true
pretty = true
Expand Down Expand Up @@ -177,6 +154,23 @@ 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]
"multiphenicsx/**/__init__.py" = ["F401"]
"multiphenicsx/fem/petsc.py" = ["N801", "N802", "N803", "N806"]
"tests/unit/fem/*.py" = ["N802", "N803", "N806"]
"tutorials/**/tutorial_*.py" = ["D100", "E741", "N802", "N803", "N806", "N816"]

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

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

[tool.scikit-build]
cmake.source-dir = "multiphenicsx/cpp"
wheel.packages = ["multiphenicsx"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
" p2 = [self.add_point(x_max, y_max)]\n",
" p3 = self.add_point(x_min, y_max)\n",
" l0 = self.add_line(p0, p1)\n",
" p1_p2 = [p1] + p2\n",
" p1_p2 = [p1, *p2]\n",
" l1 = [self.add_line(p1_p2[i], p1_p2[i + 1]) for i in range(len(p2))]\n",
" l2 = self.add_line(p2[-1], p3)\n",
" l3 = self.add_line(p3, p0)\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
" p2 = [self.add_point(x_max, y_max)]\n",
" p3 = self.add_point(x_min, y_max)\n",
" l0 = self.add_line(p0, p1)\n",
" p1_p2 = [p1] + p2\n",
" p1_p2 = [p1, *p2]\n",
" l1 = [self.add_line(p1_p2[i], p1_p2[i + 1]) for i in range(len(p2))]\n",
" l2 = self.add_line(p2[-1], p3)\n",
" l3 = self.add_line(p3, p0)\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
"import dolfinx.io\n",
"import dolfinx.mesh\n",
"import gmsh\n",
"import matplotlib\n",
"import matplotlib as mpl\n",
"import matplotlib.collections\n",
"import matplotlib.pyplot as plt\n",
"import matplotlib.tri as tri # noqa: IMR223\n",
"import matplotlib.tri as tri\n",
"import mpi4py.MPI\n",
"import mpl_toolkits.axes_grid1\n",
"import numpy as np\n",
Expand Down Expand Up @@ -88,16 +88,16 @@
" ax.set_aspect(\"equal\")\n",
" points = mesh.geometry.x\n",
" colors = [\"b\", \"r\"]\n",
" cmap = matplotlib.colors.ListedColormap(colors)\n",
" cmap = mpl.colors.ListedColormap(colors)\n",
" cmap_bounds = [0, 0.5, 1]\n",
" norm = matplotlib.colors.BoundaryNorm(cmap_bounds, cmap.N)\n",
" norm = mpl.colors.BoundaryNorm(cmap_bounds, cmap.N)\n",
" assert mesh_tags.dim in (mesh.topology.dim, mesh.topology.dim - 1)\n",
" if mesh_tags.dim == mesh.topology.dim:\n",
" cells = mesh.geometry.dofmap\n",
" tria = tri.Triangulation(points[:, 0], points[:, 1], cells)\n",
" cell_colors = np.zeros((cells.shape[0], ))\n",
" cell_colors[mesh_tags.indices[mesh_tags.values == 1]] = 1\n",
" mappable: matplotlib.collections.Collection = ax.tripcolor(\n",
" mappable: mpl.collections.Collection = ax.tripcolor(\n",
" tria, cell_colors, edgecolor=\"k\", cmap=cmap, norm=norm)\n",
" elif mesh_tags.dim == mesh.topology.dim - 1:\n",
" tdim = mesh.topology.dim\n",
Expand Down Expand Up @@ -128,7 +128,7 @@
" lines_colors_as_int.append(value_f)\n",
" lines_colors_as_str.append(colors[value_f])\n",
" lines_linestyles.append(linestyles[value_f])\n",
" mappable: matplotlib.collections.Collection = matplotlib.collections.LineCollection( # type: ignore[no-redef]\n",
" mappable: mpl.collections.Collection = mpl.collections.LineCollection( # type: ignore[no-redef]\n",
" lines, cmap=cmap, norm=norm, colors=lines_colors_as_str, linestyles=lines_linestyles)\n",
" mappable.set_array(np.array(lines_colors_as_int))\n",
" ax.add_collection(mappable)\n",
Expand Down

0 comments on commit f2bc322

Please sign in to comment.