diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index effaf62..6c91167 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,9 +1,12 @@ repos: - - repo: https://github.com/psf/black - rev: 24.3.0 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.8.2 hooks: - - id: black - args: [--check] + - id: ruff # linter + name: Run ruff (linter for Python) + args: ["--fix", "--select", "I,TID252,F401"] # "I => sort imports, TID252 => ban relative imports, F401 => unused imports" + - id: ruff-format # formatter + name: Run ruff (formatter for Python) - repo: https://github.com/pre-commit/pre-commit-hooks rev: v5.0.0 hooks: diff --git a/pyproject.toml b/pyproject.toml index 8c549e1..41aae69 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "biomesh" -version = "0.5.0" +version = "0.5.1" authors = [ { name="The biomesh Authors" }, ] @@ -40,3 +40,6 @@ dependencies = [ [tool.hatch.build.targets.wheel] packages = ["src/biomesh"] + +[tool.ruff.lint.per-file-ignores] +"src/biomesh/__init__.py" = ["F401"] diff --git a/src/biomesh/__init__.py b/src/biomesh/__init__.py index 22954ea..3635d0f 100644 --- a/src/biomesh/__init__.py +++ b/src/biomesh/__init__.py @@ -6,23 +6,22 @@ """Biomesh is a Python package for working with 3D meshes, providing tools for mesh generation, manipulation, and analysis tailored for finite element simulations of biomechanical applications.""" -from . import run_gmsh + import pathlib -from . import mesh -import lnmmeshio import tempfile + +import lnmmeshio import meshio -from .reorder import reorder + +from . import laplace, mesh, run_gmsh, utils from .adapt import lin_to_quad -from .merge import merge from .filter import ( - filter_by_cellblock, filter_by_block_ids, + filter_by_cellblock, filter_by_cellblock_point_mapping, ) - -from . import utils -from . import laplace +from .merge import merge +from .reorder import reorder def combine_colored_stl_files(*stl_files: pathlib.Path) -> meshio.Mesh: diff --git a/src/biomesh/fe.py b/src/biomesh/fe.py index 2fef50b..c791308 100644 --- a/src/biomesh/fe.py +++ b/src/biomesh/fe.py @@ -4,9 +4,11 @@ # # SPDX-License-Identifier: MIT """Small utilities for finite elements.""" -import numpy as np + import math + import meshio +import numpy as np import symfem import sympy as sp diff --git a/src/biomesh/filter.py b/src/biomesh/filter.py index 1ac8450..71048b9 100644 --- a/src/biomesh/filter.py +++ b/src/biomesh/filter.py @@ -5,9 +5,10 @@ # SPDX-License-Identifier: MIT """Filter for meshes to extract a subset.""" +from typing import Callable + import meshio import numpy as np -from typing import Callable def filter_by_cellblock_point_mapping( diff --git a/src/biomesh/laplace.py b/src/biomesh/laplace.py index 920371c..05d2571 100644 --- a/src/biomesh/laplace.py +++ b/src/biomesh/laplace.py @@ -4,10 +4,11 @@ # # SPDX-License-Identifier: MIT """A simple dummy Laplace-solver.""" -import numpy as np -import math + import meshio +import numpy as np import scipy.sparse + from . import fe _OPTIMAL_NUMBER_OF_INTEGRATION_POINTS = { diff --git a/src/biomesh/merge.py b/src/biomesh/merge.py index 7513d1c..41bec55 100644 --- a/src/biomesh/merge.py +++ b/src/biomesh/merge.py @@ -4,6 +4,7 @@ # # SPDX-License-Identifier: MIT """A module to merge multuple meshes into one larger mesh.""" + import meshio import numpy as np diff --git a/src/biomesh/mesh.py b/src/biomesh/mesh.py index e6b705c..d017031 100644 --- a/src/biomesh/mesh.py +++ b/src/biomesh/mesh.py @@ -5,10 +5,11 @@ # SPDX-License-Identifier: MIT """A module for utils for generating meshes.""" -import lnmmeshio import pathlib -import numpy as np + +import lnmmeshio import meshio +import numpy as np import scipy.spatial as sp @@ -90,7 +91,6 @@ def merge_colored_stl( # append cells for cell_id, cell in enumerate(mesh.cells[0].data): - key = _sort_cell_node_ids([node_mapping[i] for i in cell]) if key not in cell_surface_ids: diff --git a/src/biomesh/reorder.py b/src/biomesh/reorder.py index 2cd2f83..d245e7c 100644 --- a/src/biomesh/reorder.py +++ b/src/biomesh/reorder.py @@ -5,11 +5,12 @@ # SPDX-License-Identifier: MIT """A module for reordering nodes in a finite element mesh.""" +import copy +from collections import defaultdict + import meshio -import scipy.sparse as sp import numpy as np -from collections import defaultdict -import copy +import scipy.sparse as sp def reverse_permutation(perm: np.ndarray) -> np.ndarray: diff --git a/src/biomesh/run_gmsh.py b/src/biomesh/run_gmsh.py index 19b3cbe..737c62e 100644 --- a/src/biomesh/run_gmsh.py +++ b/src/biomesh/run_gmsh.py @@ -6,9 +6,10 @@ """A module controlling running the gmsh api if installed.""" import pathlib -import meshio import tempfile -from types import TracebackType, ModuleType +from types import TracebackType + +import meshio class GmshApi: diff --git a/src/biomesh/utils.py b/src/biomesh/utils.py index e1d34a6..50b0ef5 100644 --- a/src/biomesh/utils.py +++ b/src/biomesh/utils.py @@ -4,6 +4,7 @@ # # SPDX-License-Identifier: MIT """Some small utilities.""" + import numpy as np import scipy.spatial as sp diff --git a/tests/test_adapt.py b/tests/test_adapt.py index 5886e66..5b6a8ae 100644 --- a/tests/test_adapt.py +++ b/tests/test_adapt.py @@ -4,11 +4,14 @@ # # SPDX-License-Identifier: MIT """Testing mesh adaptation utilities.""" + import pathlib + import meshio -import biomesh import numpy as np +import biomesh + def test_lin_to_quad(): """Testing converting linear cells to quadratic cells.""" diff --git a/tests/test_fe.py b/tests/test_fe.py index 173a817..a15f764 100644 --- a/tests/test_fe.py +++ b/tests/test_fe.py @@ -4,11 +4,14 @@ # # SPDX-License-Identifier: MIT """Tests for small finite element ulitities.""" -import pytest + import pathlib + import meshio -import biomesh import numpy as np +import pytest + +import biomesh @pytest.mark.parametrize("shape", ["tetra", "tetra10"]) diff --git a/tests/test_filter.py b/tests/test_filter.py index bd2133f..f76eeae 100644 --- a/tests/test_filter.py +++ b/tests/test_filter.py @@ -4,11 +4,14 @@ # # SPDX-License-Identifier: MIT """Testing filtering meshes.""" -import biomesh + import pathlib + import meshio import numpy as np +import biomesh + def test_filter_by_cellblock(): """Test the filter by a specific cellblock filter.""" diff --git a/tests/test_laplace.py b/tests/test_laplace.py index bf9ec10..defda4c 100644 --- a/tests/test_laplace.py +++ b/tests/test_laplace.py @@ -4,11 +4,14 @@ # # SPDX-License-Identifier: MIT """A test suite for the dummy Laplace solver.""" -import pytest -import biomesh -import numpy as np + import pathlib + import meshio +import numpy as np +import pytest + +import biomesh def test_cell_stiffness_hex(): diff --git a/tests/test_merge.py b/tests/test_merge.py index 705ad19..75cb283 100644 --- a/tests/test_merge.py +++ b/tests/test_merge.py @@ -5,11 +5,13 @@ # SPDX-License-Identifier: MIT """Test merge meshes.""" -import meshio -import biomesh import pathlib + +import meshio import numpy as np +import biomesh + def test_merge(): """Test merging multiple meshes.""" diff --git a/tests/test_mesh_stl.py b/tests/test_mesh_stl.py index bec4e21..e81d8df 100644 --- a/tests/test_mesh_stl.py +++ b/tests/test_mesh_stl.py @@ -5,11 +5,11 @@ # SPDX-License-Identifier: MIT """Tests for meshing stl-files.""" -import biomesh import pathlib -import meshio + import pytest -import numpy as np + +import biomesh _my_script_dir = pathlib.Path(__file__).parent diff --git a/tests/test_reorder.py b/tests/test_reorder.py index 465a8ca..973603b 100644 --- a/tests/test_reorder.py +++ b/tests/test_reorder.py @@ -6,10 +6,12 @@ """Tests for reordering nodes/elements in a finite element mesh.""" import pathlib + import meshio -import biomesh import numpy as np +import biomesh + def test_reorder(): """Tests reordering the nodes in a finite element mesh.""" diff --git a/tests/test_utils.py b/tests/test_utils.py index ec59fa9..87d6f87 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -4,10 +4,12 @@ # # SPDX-License-Identifier: MIT """Test small utilities.""" + import numpy as np -import biomesh import scipy.spatial as sp +import biomesh + def test_bislerp(): """Test bislerp operation for rotations."""