Skip to content

Commit 5e33ad5

Browse files
committed
squash: python_mumps recipe
1 parent 8df7254 commit 5e33ad5

File tree

3 files changed

+128
-1
lines changed

3 files changed

+128
-1
lines changed

repos/spack_repo/builtin/packages/mumps/package.py

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class Mumps(Package):
6565
description="Allow BLAS calls in OpenMP regions "
6666
+ "(warning: might not be supported by all multithread BLAS)",
6767
)
68+
variant("pkgconfig", default=False, description="Create unofficial pkgconfig files")
6869

6970
depends_on("c", type="build") # generated
7071
depends_on("fortran", type="build") # generated
@@ -174,7 +175,9 @@ def write_makefile_inc(self):
174175
)
175176

176177
orderings.append("-Dmetis")
177-
178+
if "+pkgconfig" in self.spec:
179+
# Keeping orderings in case we have to create pkg_config files
180+
self.orderings = orderings
178181
makefile_conf.append("ORDERINGSF = %s" % (" ".join(orderings)))
179182

180183
# Determine which compiler suite we are using
@@ -433,6 +436,52 @@ def install(self, spec, prefix):
433436
zsimpletest = Executable("./zsimpletest")
434437
zsimpletest(input="input_simpletest_cmplx")
435438

439+
@run_after("install", when="+pkgconfig")
440+
def create_pkgconfig(self):
441+
"""Create unofficial pkgconfig files for mumps libraries"""
442+
libdir = join_path(self.prefix, "lib")
443+
pkg_path = join_path(libdir, "pkgconfig")
444+
mkdirp(pkg_path)
445+
precision_desc = {
446+
"s": "single",
447+
"d": "double",
448+
"c": "complex single",
449+
"z": "complex double",
450+
}
451+
orderings = [ordering[2:] for ordering in self.orderings]
452+
if len(orderings) > 1:
453+
ord_desc = "with the following orderings available: "
454+
ord_desc += ", ".join(orderings[:-1])
455+
ord_desc += f" and {orderings[-1]}"
456+
else:
457+
ord_desc = f"with the {orderings[0]} ordering available"
458+
459+
if "+mpi" in self.spec:
460+
parallel_desc = "parallel"
461+
else:
462+
parallel_desc = "sequential"
463+
for char in "zscd":
464+
if (
465+
("+float" in self.spec and char == "s")
466+
or ("+double" in self.spec and char == "d")
467+
or ("+complex" in self.spec and "+float" in self.spec and char == "c")
468+
or ("+complex" in self.spec and "+double" in self.spec and char == "z")
469+
):
470+
with open(join_path(pkg_path, f"{char}mumps.pc"), "w") as f:
471+
f.write(
472+
f"""prefix={self.prefix}
473+
exec_prefix=${{prefix}}
474+
includedir=${{prefix}}/include
475+
libdir=${{exec_prefix}}/lib
476+
477+
Name: {char}mumps
478+
Description: The {parallel_desc} {precision_desc[char]} MUMPS library {ord_desc}
479+
Version: {self.version}
480+
Cflags: -I${{includedir}}
481+
Libs: -L${{libdir}} -l{char}mumps
482+
"""
483+
)
484+
436485
@property
437486
def libs(self):
438487
component_libs = ["*mumps", "mumps_common", "pord"]
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import os
2+
3+
from spack_repo.builtin.build_systems.meson import MesonBuilder
4+
from spack_repo.builtin.build_systems.python import PythonPackage
5+
6+
from spack.package import *
7+
8+
9+
class PyPythonMumps(PythonPackage):
10+
"""Python wrapper for the MUMPS solver (python_mumps)."""
11+
12+
homepage = "https://gitlab.kwant-project.org/kwant/python-mumps"
13+
url = "https://pypi.org/packages/source/p/python-mumps/python_mumps-0.0.6.tar.gz"
14+
15+
maintainers = ["williampiat3"]
16+
17+
version("0.0.6", sha256="58c33104f77c448e127e9e6da316f71dfb1a17719ecf022634669d513306b1fa")
18+
19+
variant("mpi", default=True, description="Whether to have MPI support on python-mumps or not")
20+
21+
# build dependencies
22+
with default_args(type="build"):
23+
depends_on("meson")
24+
depends_on("ninja")
25+
depends_on("py-meson-python")
26+
depends_on("py-setuptools")
27+
depends_on("py-setuptools-scm")
28+
depends_on("py-cython")
29+
30+
# Python dependencies
31+
with default_args(type=("build", "run")):
32+
depends_on("py-numpy")
33+
depends_on("py-mpi4py", when="+mpi")
34+
depends_on("py-scipy")
35+
36+
# Optional/test deps
37+
depends_on("py-pytest", type="test")
38+
39+
# External solver
40+
depends_on("mumps+float+complex+double+metis+scotch+pkgconfig", when="+mpi")
41+
depends_on("mumps~mpi+float+complex+double+metis+scotch+pkgconfig", when="~mpi")
42+
43+
patch("patch_meson_build.patch")
44+
45+
@run_before("install")
46+
def setup_meson(self) -> None:
47+
"""Running meson setup before building the package"""
48+
# Building with meson
49+
options = []
50+
if self.spec["meson"].satisfies("@0.64:"):
51+
options.append("setup")
52+
options.append(os.path.abspath(self.stage.source_path))
53+
options += MesonBuilder.std_args(self)
54+
builddir = "builddir"
55+
options.append(builddir + "/")
56+
with working_dir(join_path(self.build_directory, builddir), create=True):
57+
self.module.meson(*options)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
diff --git a/meson.build b/meson.build
2+
index 67c5ea0..1ee00fd 100644
3+
--- a/meson.build
4+
+++ b/meson.build
5+
@@ -19,13 +19,15 @@ fs = import('fs')
6+
# Declare NumPy via meson's dependency() (no explicit method), and add
7+
# the NPY_NO_DEPRECATED_API compile flag.
8+
numpy_nodepr_api = ['-DNPY_NO_DEPRECATED_API=NPY_1_9_API_VERSION']
9+
-np_dep_base = dependency('numpy')
10+
+np_dep_base = dependency('numpy', version : '>=2')
11+
np_dep = declare_dependency(dependencies: [np_dep_base], compile_args: numpy_nodepr_api)
12+
13+
# Declare MUMPS dependencies using meson's dependency() resolution.
14+
# Fail early if a named dependency is not available.
15+
mumps_names = get_option('mumps_names')
16+
mumps_deps = []
17+
+omp = dependency('openmp')
18+
+mumps_deps += omp
19+
foreach mumps_name : mumps_names
20+
# 1) Try the package as given
21+
pkg = dependency(mumps_name, required: false)

0 commit comments

Comments
 (0)