Skip to content

Commit aec824b

Browse files
committed
Use ruff as formatter and linter
1 parent 51bc2f8 commit aec824b

19 files changed

+71
-40
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
repos:
2-
- repo: https://github.com/psf/black
3-
rev: 24.3.0
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.8.2
44
hooks:
5-
- id: black
6-
args: [--check]
5+
- id: ruff # linter
6+
name: Run ruff (linter for Python)
7+
args: ["--fix", "--select", "I,TID252,F401"] # "I => sort imports, TID252 => ban relative imports, F401 => unused imports"
8+
- id: ruff-format # formatter
9+
name: Run ruff (formatter for Python)
710
- repo: https://github.com/pre-commit/pre-commit-hooks
811
rev: v5.0.0
912
hooks:

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "biomesh"
7-
version = "0.5.0"
7+
version = "0.5.1"
88
authors = [
99
{ name="The biomesh Authors" },
1010
]
@@ -40,3 +40,6 @@ dependencies = [
4040

4141
[tool.hatch.build.targets.wheel]
4242
packages = ["src/biomesh"]
43+
44+
[tool.ruff.lint.per-file-ignores]
45+
"src/biomesh/__init__.py" = ["F401"]

src/biomesh/__init__.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,22 @@
66
"""Biomesh is a Python package for working with 3D meshes, providing tools for
77
mesh generation, manipulation, and analysis tailored for finite element
88
simulations of biomechanical applications."""
9-
from . import run_gmsh
9+
1010
import pathlib
11-
from . import mesh
12-
import lnmmeshio
1311
import tempfile
12+
13+
import lnmmeshio
1414
import meshio
15-
from .reorder import reorder
15+
16+
from . import laplace, mesh, run_gmsh, utils
1617
from .adapt import lin_to_quad
17-
from .merge import merge
1818
from .filter import (
19-
filter_by_cellblock,
2019
filter_by_block_ids,
20+
filter_by_cellblock,
2121
filter_by_cellblock_point_mapping,
2222
)
23-
24-
from . import utils
25-
from . import laplace
23+
from .merge import merge
24+
from .reorder import reorder
2625

2726

2827
def combine_colored_stl_files(*stl_files: pathlib.Path) -> meshio.Mesh:

src/biomesh/fe.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
#
55
# SPDX-License-Identifier: MIT
66
"""Small utilities for finite elements."""
7-
import numpy as np
7+
88
import math
9+
910
import meshio
11+
import numpy as np
1012
import symfem
1113
import sympy as sp
1214

src/biomesh/filter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
# SPDX-License-Identifier: MIT
66
"""Filter for meshes to extract a subset."""
77

8+
from typing import Callable
9+
810
import meshio
911
import numpy as np
10-
from typing import Callable
1112

1213

1314
def filter_by_cellblock_point_mapping(

src/biomesh/laplace.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
#
55
# SPDX-License-Identifier: MIT
66
"""A simple dummy Laplace-solver."""
7-
import numpy as np
8-
import math
7+
98
import meshio
9+
import numpy as np
1010
import scipy.sparse
11+
1112
from . import fe
1213

1314
_OPTIMAL_NUMBER_OF_INTEGRATION_POINTS = {

src/biomesh/merge.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#
55
# SPDX-License-Identifier: MIT
66
"""A module to merge multuple meshes into one larger mesh."""
7+
78
import meshio
89
import numpy as np
910

src/biomesh/mesh.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
# SPDX-License-Identifier: MIT
66
"""A module for utils for generating meshes."""
77

8-
import lnmmeshio
98
import pathlib
10-
import numpy as np
9+
10+
import lnmmeshio
1111
import meshio
12+
import numpy as np
1213
import scipy.spatial as sp
1314

1415

@@ -90,7 +91,6 @@ def merge_colored_stl(
9091

9192
# append cells
9293
for cell_id, cell in enumerate(mesh.cells[0].data):
93-
9494
key = _sort_cell_node_ids([node_mapping[i] for i in cell])
9595

9696
if key not in cell_surface_ids:

src/biomesh/reorder.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
# SPDX-License-Identifier: MIT
66
"""A module for reordering nodes in a finite element mesh."""
77

8+
import copy
9+
from collections import defaultdict
10+
811
import meshio
9-
import scipy.sparse as sp
1012
import numpy as np
11-
from collections import defaultdict
12-
import copy
13+
import scipy.sparse as sp
1314

1415

1516
def reverse_permutation(perm: np.ndarray) -> np.ndarray:

src/biomesh/run_gmsh.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
"""A module controlling running the gmsh api if installed."""
77

88
import pathlib
9-
import meshio
109
import tempfile
11-
from types import TracebackType, ModuleType
10+
from types import TracebackType
11+
12+
import meshio
1213

1314

1415
class GmshApi:

0 commit comments

Comments
 (0)