Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[submodule "spack"]
path = spack
url = https://github.com/jcsda/spack
branch = spack-stack-dev
url = https://github.com/spack/spack
branch = develop
[submodule "repos/builtin"]
path = repos/builtin
url = https://github.com/jcsda/spack-packages
Expand Down
5 changes: 3 additions & 2 deletions configs/common/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ config:
# Timeout in seconds for web requests (curl/urllib)
connect_timeout: 60

# Install deprecated packages (need for py-werkzeug@0.15.3, DH 20250417)
deprecated: true
# Where locally maintained Jinja templates are stored
template_dirs:
- ${SPACK_STACK_DIR}/spack-ext/lib/spack-stack/stack/templates
4 changes: 1 addition & 3 deletions configs/common/modules_lmod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ modules:
hash_length: 0
all:
autoload: direct
environment:
set:
'{name}_ROOT': '{prefix}'
template: case-preserving-root.lua
suffixes:
+debug: 'debug'
build_type=Debug: 'debug'
Expand Down
4 changes: 1 addition & 3 deletions configs/common/modules_tcl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ modules:
hash_length: 0
all:
autoload: direct
environment:
set:
'{name}_ROOT': '{prefix}'
template: case-preserving-root.tcl
suffixes:
+debug: 'debug'
build_type=Debug: 'debug'
Expand Down
7 changes: 7 additions & 0 deletions configs/common/packages.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
packages:
all:
# Install deprecated packages (need for py-werkzeug@0.15.3, DH 20250417)
deprecation:
allow:
- severity: critical
# Virtual provider settings
jpeg:
require:
Expand Down Expand Up @@ -521,6 +526,8 @@ packages:
# NOTE: py-setuptools was pinned @73.0.1 for the py3.11 stack; removed for the
# py3.12/numpy2 migration since modern packages (e.g. py-xarray@2025.7) require
# py-setuptools@77.0.3:. Re-evaluate issue #3695 if setuptools duplicates recur.
# NOTE (DH 20261202): unified/neptune environment use py-setuptools-scm@8.2.1.
# cylc environment chose 7.1.0 and 9.0.2 - pin to @:7 in cylc-dev template.
py-torch:
require:
- '@2.10:'
Expand Down
6 changes: 6 additions & 0 deletions configs/templates/cylc-dev/spack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ spack:
- py-cylc-flow@8.6.4
- py-cylc-uiserver@1.9.1
- bats

packages:
# Avoid conflicts by pinning py-setuptools-scm to versions @:7
py-setuptools-scm:
require:
- '@:7'
12 changes: 12 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ echo "Sourcing spack environment ${SPACK_STACK_DIR}/spack/share/spack/setup-env.
# Avoid using ~/.spack directory for bootstraping
echo "Changing bootstrap path to $(spack bootstrap root '$spack/bootstrap')"

echo "Enabling the spack-stack extension"
spack config --scope defaults add 'config:extensions:${SPACK_STACK_DIR}/spack-ext/lib/spack-stack'

echo "Configuring Spack repositories for spack-stack"
SPACK_REPOS_CONFIG="${SPACK_ROOT}/etc/spack/repos.yaml"
mkdir -p "$(dirname "${SPACK_REPOS_CONFIG}")"
cat > "${SPACK_REPOS_CONFIG}" <<EOF
repos:
builtin: ${SPACK_STACK_DIR}/repos/builtin/repos/spack_repo/builtin
spack_stack: ${SPACK_STACK_DIR}/repos/spack_stack/spack_repo/spack_stack
EOF

# Get the current hash of the spack-stack code
export SPACK_STACK_HASH=`cd $SPACK_STACK_DIR && git rev-parse --short HEAD`
echo "Current hash of spack-stack is ${SPACK_STACK_HASH}"
2 changes: 1 addition & 1 deletion spack
Submodule spack updated 710 files
2 changes: 1 addition & 1 deletion spack-ext/lib/spack-stack/stack/cmd/stack_cmds/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import shutil
from sys import platform

import spack.llnl.util.tty as tty
import spack.util.tty as tty

from spack.extensions.stack.container_env import StackContainer
from spack.extensions.stack.stack_env import StackEnv, stack_path
Expand Down
2 changes: 1 addition & 1 deletion spack-ext/lib/spack-stack/stack/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def get_preferred_compiler(config):
- COMPILER_NAME (gcc, intel-oneapi-compilers, llvm, ..)
"""
try:
preferred_compilers = config.get("packages")["fortran"]["prefer"]
preferred_compilers = config.CONFIG.get("packages")["fortran"]["prefer"]
except:
raise Exception(
"""Unable to detect preferred compiler from environment.
Expand Down
10 changes: 4 additions & 6 deletions spack-ext/lib/spack-stack/stack/compiler_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,10 @@ def check_preferred_compiler():
request a different compiler. For the latter packages, check
that the explicitly requested compiler is being used."""

# Return the active environment object or terminate with an error
logging.info("Configuring active spack environment ...")
env_dir = ev.active_environment().path
if not env_dir:
raise Exception("No active spack environment")
env = spack.environment.Environment(env_dir)
spack.environment.environment.activate(env)
env = spack.cmd.require_active_env("stack check-preferred-compiler")
env_dir = env.path
logging.info(" ... environment directory: {}".format(env_dir))

# Get all specs and determine compilers
Expand All @@ -96,7 +94,7 @@ def check_preferred_compiler():
logging.info(" ... preferred compiler: {}".format(preferred_compiler))

# Get package config to compare actual specs against the intended config
package_config = spack.config.get("packages")
package_config = spack.config.CONFIG.get("packages")

logging.info("Checking all specs ...")
errors = 0
Expand Down
32 changes: 18 additions & 14 deletions spack-ext/lib/spack-stack/stack/meta_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ def modulepath_prepend_command(module_choice, modulepath):
return envmod_command(module_choice, "prepend_path", "MODULEPATH", modulepath)


def substitute_config_vars(config_str):
def substitute_config_vars(env, config_str):
"""
Substitute spack-specific and environment variables that may be present
in configuration files. See:
https://spack.readthedocs.io/en/latest/configuration.html#config-file-variables
"""
spack_vars = {
"ENV": ev.active_environment().path,
"ENV": env.path,
"SPACK": os.getenv("SPACK_ROOT"),
"TEMPDIR": None,
"USER": os.getenv("HOME"),
Expand Down Expand Up @@ -223,18 +223,16 @@ def setup_meta_modules():
spack-generated modules and implement a module hiearchy modeled after
the lua/lmod modules."""

# Return the active environment object or terminate with an error
logging.info("Configuring active spack environment ...")
env_dir = ev.active_environment().path
if not env_dir:
raise Exception("No active spack environment")
env = spack.environment.Environment(env_dir)
spack.environment.environment.activate(env)
env = spack.cmd.require_active_env("stack setup-meta-modules")
env_dir = env.path
logging.info(" ... environment directory: {}".format(env_dir))

# Parse spack main config from environment
logging.info("Parsing spack environment main config ...")
main_config = spack.config.get("config")
install_dir = substitute_config_vars(main_config["install_tree"]["root"])
main_config = spack.config.CONFIG.get("config")
install_dir = substitute_config_vars(env, main_config["install_tree"]["root"])

if not os.path.isabs(install_dir):
install_dir = os.path.realpath(os.path.join(env_dir, install_dir))
Expand All @@ -244,7 +242,7 @@ def setup_meta_modules():

# Parse spack module config from environment
logging.info("Parsing spack environment modules config ...")
module_config = spack.config.get("modules")
module_config = spack.config.CONFIG.get("modules")

# Check which modules are used - tcl or lmod (can only be one)
if len(module_config["default"]["enable"]) > 1:
Expand All @@ -253,7 +251,7 @@ def setup_meta_modules():
logging.info(" ... configured to use {} modules".format(module_choice))

# Top-level module directory
module_dir = substitute_config_vars(module_config["default"]["roots"][module_choice])
module_dir = substitute_config_vars(env, module_config["default"]["roots"][module_choice])
if not os.path.isabs(module_dir):
module_dir = os.path.realpath(os.path.join(env_dir, module_dir))
else:
Expand Down Expand Up @@ -522,9 +520,15 @@ def setup_meta_modules():
else:
compiler_alias = ALIASES[compiler.name]

# Spack mpi+compiler module hierarchy
# Spack mpi+compiler module hierarchy; note that the
# lmod directory tree contains the 7-digit hash of
# the MPI provider - the tcl tree does not.
if module_choice == "lmod":
mpi_version = str(mpi_provider.version) + "-" + mpi_provider.dag_hash(7)
else:
mpi_version = str(mpi_provider.version)
modulepath_save = os.path.join(
module_dir, mpi_alias, str(mpi_provider.version), compiler_alias, str(compiler.version)
module_dir, mpi_alias, mpi_version, compiler_alias, str(compiler.version)
)
if not os.path.isdir(modulepath_save):
os.makedirs(modulepath_save)
Expand Down Expand Up @@ -673,7 +677,7 @@ def setup_meta_modules():
number_of_meta_modules_written += 1

# Write stack virtual environment meta modules
view_config = spack.config.get("view")
view_config = spack.config.CONFIG.get("view")
# view: [true|false]
if isinstance(view_config, bool):
# view: true
Expand Down
30 changes: 15 additions & 15 deletions spack-ext/lib/spack-stack/stack/stack_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,37 +265,37 @@ def write(self):
env_scope = env.scope_name

# Save original data in spack.yaml because it has higest precedence.
# spack.config.add will overwrite as it goes.
# spack.config.CONFIG.add will overwrite as it goes.
# Precedence order (high to low) is original spack.yaml,
# then common configs, then site configs.
original_sections = {}
for key in spack.config.SECTION_SCHEMAS.keys():
section = spack.config.get(key, scope=env_scope)
section = spack.config.CONFIG.get(key, scope=env_scope)
if section:
original_sections[key] = copy.deepcopy(section)

# Commonly used config settings
#compiler = f"packages:all:prefer:['%{self.compiler}']"
#spack.config.add(compiler, scope=env_scope)
#spack.config.CONFIG.add(compiler, scope=env_scope)
# Also update compiler definitions if matrices are used
# DH I am too stupid to do this the "spack way" ...
definitions = spack.config.get("definitions", scope=env_scope)
definitions = spack.config.CONFIG.get("definitions", scope=env_scope)
if definitions:
target_compiler = f"%{self.compiler}"
for i in range(len(definitions)):
if "compilers" in definitions[i]:
definitions[i] = {"compilers": [target_compiler]}
spack.config.set("definitions", definitions, scope=env_scope)
spack.config.CONFIG.set("definitions", definitions, scope=env_scope)

if self.install_prefix:
# Modules can go in <prefix>/modulefiles by default
prefix = "config:install_tree:root:{}".format(self.install_prefix)
spack.config.add(prefix, scope=env_scope)
spack.config.CONFIG.add(prefix, scope=env_scope)
module_prefix = os.path.join(self.install_prefix, "modulefiles")
lmod_prefix = "modules:default:roots:lmod:{}".format(module_prefix)
tcl_prefix = "modules:default:roots:tcl:{}".format(module_prefix)
spack.config.add(lmod_prefix, scope=env_scope)
spack.config.add(tcl_prefix, scope=env_scope)
spack.config.CONFIG.add(lmod_prefix, scope=env_scope)
spack.config.CONFIG.add(tcl_prefix, scope=env_scope)
if self.upstreams:
env_config_dirs = {
"common": os.path.join(self.env_dir(), "common"),
Expand All @@ -322,7 +322,7 @@ def write(self):
name = os.path.realpath(os.path.join(upstream_path, ".."))
upstream = "upstreams:%s:install_tree:'%s'" % (name, upstream_path)
logging.info("Adding upstream path '%s'" % upstream_path)
spack.config.add(upstream, scope=env_scope)
spack.config.CONFIG.add(upstream, scope=env_scope)
# Verify that config files match
upstream_config_dirs = {
"common": os.path.normpath(os.path.join(upstream_path, "../common/")),
Expand All @@ -348,7 +348,7 @@ def write(self):
shutil.copytree(envrepo_path, new_envrepo, dirs_exist_ok=True)
config_envrepo = True
if config_envrepo:
spack.config.add("repos:[$env/envrepo]", scope=env_scope)
spack.config.CONFIG.add("repos:[$env/envrepo]", scope=env_scope)

if self.modifypkg:
logging.info("Creating custom repo with packages %s" % ", ".join(self.modifypkg))
Expand All @@ -357,7 +357,7 @@ def write(self):
os.makedirs(env_pkgs_path, exist_ok=True)
with open(os.path.join(env_repo_path, "repo.yaml"), "w") as f:
f.write("repo:\n namespace: envrepo")
repo_paths = spack.config.get("repos")
repo_paths = spack.config.CONFIG.get("repos")
repo_paths = [p.replace("${SPACK_STACK_DIR}", os.getenv("SPACK_STACK_DIR")) for p in repo_paths.values()]
for pkg_name in self.modifypkg:
pkg_found = False
Expand All @@ -381,7 +381,7 @@ def write(self):
if not pkg_found:
logging.warning(f"WARNING: package '{pkg_name}' could not be found")
logging.info("Adding custom repo 'envrepo' to env config")
spack.config.add("repos:[$env/envrepo]", scope=env_scope)
spack.config.CONFIG.add("repos:[$env/envrepo]", scope=env_scope)

# Copy any envrepo directory associated with the template (i.e., add-on env)
if self.template:
Expand All @@ -390,16 +390,16 @@ def write(self):
logging.info(f"Copying envrepo/ from {self.template_path}")
target_envrepo_path = os.path.join(env_dir, "envrepo")
shutil.copytree(template_envrepo_path, target_envrepo_path, dirs_exist_ok=True)
spack.config.add("repos:[$env/envrepo]", scope=env_scope)
spack.config.CONFIG.add("repos:[$env/envrepo]", scope=env_scope)

# Merge the original spack.yaml template back in
# so it has the highest precedence
for section in spack.config.SECTION_SCHEMAS.keys():
original = original_sections.get(section, {})
existing = spack.config.get(section, scope=env_scope)
existing = spack.config.CONFIG.get(section, scope=env_scope)
new = spack.schema.merge_yaml(existing, original)
if existing and section in existing:
spack.config.set(section, new[section], env_scope)
spack.config.CONFIG.set(section, new[section], env_scope)

with env.write_transaction():
env.write()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{# Inherit the complete standard Spack Lmod/Lua module template. #}
{% extends "modules/modulefile.lua" %}

{# Add the case-preserving ROOT variable at the end of the module. #}
{% block footer %}
{{ super() }}
setenv("{{ spec.name | replace("-", "_") }}_ROOT", [==[{{ spec.prefix }}]==])
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{# Inherit the complete standard Spack Tcl module template. #}
{% extends "modules/modulefile.tcl" %}

{# Add the case-preserving ROOT variable at the end of the module. #}
{% block footer %}
{{ super() }}
setenv {{ spec.name | replace("-", "_") }}_ROOT { {{- spec.prefix -}} }
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import spack
import spack.environment as ev
from spack.llnl.util.filesystem import filter_file
from spack.util.filesystem import filter_file
import spack.main

spack_stack_cmd = spack.main.SpackCommand("stack")
Expand Down Expand Up @@ -151,6 +151,9 @@ def test_check_preferred_compiler():
with open(site_packages_yaml, 'w') as f:
f.write(packages_definition)

# Clear the spack config cache
spack.config.CONFIG.clear_caches()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required because spack.config.CONFIG is a singleton with its own memory.


with pytest.raises(Exception) as error:
spack_stack_cmd("check-preferred-compiler")
# There is only one compiler mismatch for libszip.
Expand Down
2 changes: 1 addition & 1 deletion spack-ext/lib/spack-stack/tests/test_stack_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def test_modifypkg():
"--env-dir", env_dir, "location", "--package-dir", "netcdf_c", output=str
).strip()
assert (
os.path.join(spack.config.get("repos")['builtin'].replace("${SPACK_STACK_DIR}", os.getenv("SPACK_STACK_DIR")), "packages/netcdf_c") == netcdfc_spack_path
os.path.join(spack.config.CONFIG.get("repos")['builtin'].replace("${SPACK_STACK_DIR}", os.getenv("SPACK_STACK_DIR")), "packages/netcdf_c") == netcdfc_spack_path
), "Incorrect netcdf-c location in modifypkg_test"

@pytest.mark.extension("stack")
Expand Down
8 changes: 3 additions & 5 deletions util/fetch_cargo_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,18 @@

this_dir = os.path.dirname(os.path.abspath(sys.argv[0]))

from spack.environment import active_environment
from spack_repo.builtin.build_systems.cargo import CargoPackage
from spack_repo.builtin.build_systems.python import PythonPackage
from spack.package_base import PackageBase
from spack.util.executable import Executable, which
from spack.llnl.util.filesystem import working_dir
from spack.util.filesystem import working_dir
from spack.store import find
from spack.util.environment import EnvironmentModifications
from spack.error import SpackError
import spack.cmd

# Load the current environment
env = active_environment()
if not env:
raise SpackError("No active Spack environment")
env = spack.cmd.require_active_env("env activate")

default_path = os.getenv("PATH")

Expand Down
Loading
Loading