Skip to content

Commit 46b0d72

Browse files
committed
squash: python_mumps recipe
1 parent f3199ce commit 46b0d72

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
@@ -66,6 +66,7 @@ class Mumps(Package):
6666
description="Allow BLAS calls in OpenMP regions "
6767
+ "(warning: might not be supported by all multithread BLAS)",
6868
)
69+
variant("pkgconfig", default=False, description="Create unofficial pkgconfig files")
6970

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

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

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

440+
@run_after("install", when="+pkgconfig")
441+
def create_pkgconfig(self):
442+
"""Create unofficial pkgconfig files for mumps libraries"""
443+
libdir = join_path(self.prefix, "lib")
444+
pkg_path = join_path(libdir, "pkgconfig")
445+
mkdirp(pkg_path)
446+
precision_desc = {
447+
"s": "single",
448+
"d": "double",
449+
"c": "complex single",
450+
"z": "complex double",
451+
}
452+
orderings = [ordering[2:] for ordering in self.orderings]
453+
if len(orderings) > 1:
454+
ord_desc = "with the following orderings available: "
455+
ord_desc += ", ".join(orderings[:-1])
456+
ord_desc += f" and {orderings[-1]}"
457+
else:
458+
ord_desc = f"with the {orderings[0]} ordering available"
459+
460+
if "+mpi" in self.spec:
461+
parallel_desc = "parallel"
462+
else:
463+
parallel_desc = "sequential"
464+
for char in "zscd":
465+
if (
466+
("+float" in self.spec and char == "s")
467+
or ("+double" in self.spec and char == "d")
468+
or ("+complex" in self.spec and "+float" in self.spec and char == "c")
469+
or ("+complex" in self.spec and "+double" in self.spec and char == "z")
470+
):
471+
with open(join_path(pkg_path, f"{char}mumps.pc"), "w") as f:
472+
f.write(
473+
f"""prefix={self.prefix}
474+
exec_prefix=${{prefix}}
475+
includedir=${{prefix}}/include
476+
libdir=${{exec_prefix}}/lib
477+
478+
Name: {char}mumps
479+
Description: The {parallel_desc} {precision_desc[char]} MUMPS library {ord_desc}
480+
Version: {self.version}
481+
Cflags: -I${{includedir}}
482+
Libs: -L${{libdir}} -l{char}mumps
483+
"""
484+
)
485+
437486
@property
438487
def libs(self):
439488
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)