Skip to content
46 changes: 46 additions & 0 deletions packages/issm/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

from spack.package import *
import os
Comment thread
lawrenceabird marked this conversation as resolved.
Outdated


class Issm(AutotoolsPackage):
Expand Down Expand Up @@ -61,6 +62,12 @@ class Issm(AutotoolsPackage):
description="Propagate OpenMP flags so threaded deps link cleanly",
)

variant(
"py-tools",
default=False,
description="Install ISSM python files under <prefix>/python-tools",
)

# --------------------------------------------------------------------
# Dependencies
# --------------------------------------------------------------------
Expand Down Expand Up @@ -94,10 +101,17 @@ class Issm(AutotoolsPackage):
depends_on("access-triangle", when="+wrappers")
depends_on("python@3.9.2:", when="+wrappers", type=("build", "run"))
depends_on("py-numpy", when="+wrappers", type=("build", "run"))

# --------------------------------------------------------------------
# Conflicts
# --------------------------------------------------------------------

# GCC 14 breaks on several C++17 constructs used in ISSM
conflicts("%gcc@14:", msg="ISSM cannot be built with GCC versions above 13")

# +wrappers requires +py-tools to access the wrappers
conflicts("+wrappers", when="~py-tools", msg="The +wrappers variant requires +py-tools")
Comment thread
lawrenceabird marked this conversation as resolved.

# --------------------------------------------------------------------
# Helper functions
# --------------------------------------------------------------------
Expand Down Expand Up @@ -198,7 +212,39 @@ def configure_args(self):
def install(self, spec, prefix):
make("install", parallel=False)

# Optionally install examples directory
if "+examples" in self.spec:
examples_src = join_path(self.stage.source_path, "examples")
examples_dst = join_path(prefix, "examples")
install_tree(examples_src, examples_dst)

# Optionally install Python (.py) files
if "+py-tools" in spec:
py_src = join_path(self.stage.source_path, "src", "m")
py_dst = join_path(prefix, "python-tools")
mkdirp(py_dst)

# Recursively copy all .py files from src/m to the destination
for root, _, files in os.walk(py_src):
for file in files:
if file.endswith(".py"):
src_file = join_path(root, file)
install(src_file, py_dst)
Comment thread
lawrenceabird marked this conversation as resolved.
Outdated

# --------------------------------------------------------------------
# Run environment - set ISSM_DIR and PYTHONPATH
# --------------------------------------------------------------------
def setup_run_environment(self, env):
"""Set ISSM_DIR to the install root."""

# Get the prefix path (install root)
issm_dir = self.prefix

# Set environment variable
env.set('ISSM_DIR', issm_dir)

# Add ISSM python files (and shared libraries) to PYTHONPATH if +py
if "+py-tools" in self.spec:
env.prepend_path("PYTHONPATH", join_path(self.prefix, "python-tools"))
Comment thread
lawrenceabird marked this conversation as resolved.
Outdated
env.prepend_path("PYTHONPATH", join_path(self.prefix, "lib"))