Skip to content

Commit 95f7bfa

Browse files
authored
Merge pull request #19 from scientificcomputing/remove-inpsect-hack
Remove inspect hack - it doesn't work with python< 3.12
2 parents 80c0cf7 + f59d084 commit 95f7bfa

File tree

2 files changed

+50
-20
lines changed

2 files changed

+50
-20
lines changed

src/io4dolfinx/checkpointing.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from __future__ import annotations
88

9-
import inspect
109
import typing
1110
from pathlib import Path
1211
from typing import Any
@@ -436,11 +435,21 @@ def partitioner(comm: MPI.Intracomm, n, m, topo):
436435
else:
437436
return partition_graph
438437
else:
439-
sig = inspect.signature(dolfinx.mesh.create_cell_partitioner)
440-
part_kwargs = {}
441-
if "max_facet_to_cell_links" in list(sig.parameters.keys()):
442-
part_kwargs["max_facet_to_cell_links"] = max_facet_to_cell_links
443-
partitioner = dolfinx.cpp.mesh.create_cell_partitioner(ghost_mode, **part_kwargs)
438+
try:
439+
partitioner = dolfinx.cpp.mesh.create_cell_partitioner(
440+
ghost_mode, max_facet_to_cell_links=max_facet_to_cell_links
441+
)
442+
except TypeError:
443+
partitioner = dolfinx.cpp.mesh.create_cell_partitioner(ghost_mode)
444+
445+
# Should change to the commented code below when we require python
446+
# minimum version to be >=3.12 see https://github.com/python/cpython/pull/116198
447+
# import inspect
448+
# sig = inspect.signature(dolfinx.mesh.create_cell_partitioner)
449+
# part_kwargs = {}
450+
# if "max_facet_to_cell_links" in list(sig.parameters.keys()):
451+
# part_kwargs["max_facet_to_cell_links"] = max_facet_to_cell_links
452+
# partitioner = dolfinx.cpp.mesh.create_cell_partitioner(ghost_mode, **part_kwargs)
444453

445454
return dolfinx.mesh.create_mesh(
446455
comm,

src/io4dolfinx/readers.py

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from __future__ import annotations
88

9-
import inspect
109
import pathlib
1110
import typing
1211
from pathlib import Path
@@ -181,19 +180,41 @@ def read_mesh_from_legacy_h5(
181180
shape=(mesh_geometry.shape[1],),
182181
)
183182
domain = ufl.Mesh(element)
184-
sig = inspect.signature(dolfinx.mesh.create_mesh)
185-
kwargs: dict[str, int] = {}
186-
if "max_facet_to_cell_links" in list(sig.parameters.keys()):
187-
kwargs["max_facet_to_cell_links"] = max_facet_to_cell_links
188-
189-
return dolfinx.mesh.create_mesh(
190-
comm=MPI.COMM_WORLD,
191-
cells=mesh_topology,
192-
x=mesh_geometry,
193-
e=domain,
194-
partitioner=None,
195-
**kwargs,
196-
)
183+
184+
try:
185+
return dolfinx.mesh.create_mesh(
186+
comm=MPI.COMM_WORLD,
187+
cells=mesh_topology,
188+
x=mesh_geometry,
189+
e=domain,
190+
partitioner=None,
191+
max_facet_to_cell_links=max_facet_to_cell_links,
192+
)
193+
except TypeError:
194+
return dolfinx.mesh.create_mesh(
195+
comm=MPI.COMM_WORLD,
196+
cells=mesh_topology,
197+
x=mesh_geometry,
198+
e=domain,
199+
partitioner=None,
200+
)
201+
202+
# Should change to the commented code below when we require python
203+
# minimum version to be >=3.12 see https://github.com/python/cpython/pull/116198
204+
# import inspect
205+
# sig = inspect.signature(dolfinx.mesh.create_mesh)
206+
# kwargs: dict[str, int] = {}
207+
# if "max_facet_to_cell_links" in list(sig.parameters.keys()):
208+
# kwargs["max_facet_to_cell_links"] = max_facet_to_cell_links
209+
210+
# return dolfinx.mesh.create_mesh(
211+
# comm=MPI.COMM_WORLD,
212+
# cells=mesh_topology,
213+
# x=mesh_geometry,
214+
# e=domain,
215+
# partitioner=None,
216+
# **kwargs,
217+
# )
197218

198219

199220
def read_function_from_legacy_h5(

0 commit comments

Comments
 (0)