Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

source_sh of spack's set-env.sh seems to not fully work #750

Open
jscook2345 opened this issue Feb 12, 2025 · 0 comments
Open

source_sh of spack's set-env.sh seems to not fully work #750

jscook2345 opened this issue Feb 12, 2025 · 0 comments

Comments

@jscook2345
Copy link

jscook2345 commented Feb 12, 2025

Hello!

I'm trying to create a modulefile using lmod for a site-based spack deployment. I seem to have hit a snag and I'm trying to figure out the issue. I'm hoping you could help.

Before you get into it I'd just like to thank you for lmod and all the work done on it. It's a great piece of software and we really appreciate it's usage here @ NERSC.

Also I'm happy to help debug in any way (I'm doing this on Perlmutter, our production system) you think would be useful, including patches, experiments, etc. Don't hesitate to ask!

Thanks for any help and time you can offer on this!

Describe the bug

I created the a basic modulefile for spack that essentially only does one thing:

source_sh("bash", pathJoin(root, "share", "spack", "setup-env.sh"))

This works great for most of the spack things with a little spack configuration tweaking!

However, when I try to use spack environments, things don't seem to be working.

To Reproduce

  1. Clone spack to your system.
git clone -c feature.manyFiles=true --depth=2 https://github.com/spack/spack.git
  1. Create a modulefile spack.lua that contains the following:
source_sh("bash", pathJoin("/path/to/spack", "share", "spack", "set-env.sh"))
  1. Create a spack environment:
spack env create tmp
  1. Try to activate the spack environment:
spack env activate --prompt tmp
  1. Note the following error:
==> Error: `spack env activate` requires Spack's shell support.
  
  To set up shell support, run the command below for your shell.
  
  For bash/zsh/sh:
    . /global/common/software/nersc9/spack/0.23.0/share/spack/setup-env.sh
  
  For csh/tcsh:
    source /global/common/software/nersc9/spack/0.23.0/share/spack/setup-env.csh
  
  For fish:
    source /global/common/software/nersc9/spack/0.23.0/share/spack/setup-env.fish
  
  For Windows batch:
    /global/common/software/nersc9/spack/0.23.0/bin\spack_cmd.bat
  
  For PowerShell:
    /global/common/software/nersc9/spack/0.23.0/share/spack\setup-env.ps1
  
  Or, if you do not want to use shell support, run one of these instead:
  
      eval `spack env activate --sh   [...]`  # bash/zsh/sh
      eval `spack env activate --csh  [...]`  # csh/tcsh
      eval `spack env activate --fish [...]`  # fish
      eval `spack env activate --bat  [...]`  # batch
      eval `spack env activate --pwsh [...]`  # powershell
  
  If you have already set up Spack's shell support but still receive
  this message, please make sure to call Spack via the `spack` command
  without any path components (such as `bin/spack`).

Expected behavior

If you were to source the file instead of using the modulefile, you would get the following output when you try to activate the spack environment:

spack env activate --prompt tmp
[tmp] jscook@perlmutter:login11:~/src/spack>

So no output, but with the new prompt from the environment name. To deactivate you can do the following:

spack env deactivate

Something of note?

When I look at the environment when I source the shell script manually instead of via a modulefile, I see the two following entries:

printenv | grep -i spack
BASH_FUNC_spack%%=() {  : this is a shell function from: /global/homes/j/jscook/src/spack/share/spack/setup-env.sh;
 : the real spack script is here: /global/homes/j/jscook/src/spack/bin/spack;
 _spack_shell_wrapper "$@";
BASH_FUNC__spack_shell_wrapper%%=() {  for var in DYLD_LIBRARY_PATH DYLD_FALLBACK_LIBRARY_PATH;
 eval "if [ -n \"\${${var}-}\" ]; then export SPACK_$var=\${${var}}; fi";
 command spack $_sp_flags "$@";
 command spack cd -h;
 LOC="$(SPACK_COLOR="${SPACK_COLOR:-always}" spack location $_sp_arg "$@")";
 command spack env -h;
 command spack env activate "$@";
 stdout="$(SPACK_COLOR="${SPACK_COLOR:-always}" command spack $_sp_flags env activate --sh "$@")" || return;
 command spack env deactivate "$@";
 command spack env deactivate -h;
 stdout="$(SPACK_COLOR="${SPACK_COLOR:-always}" command spack $_sp_flags env deactivate --sh)" || return;
 command spack env $_sp_arg "$@"
 command spack $_sp_flags $_sp_subcommand "$@";
 stdout="$(SPACK_COLOR="${SPACK_COLOR:-always}" command spack $_sp_flags $_sp_subcommand --sh "$@")" || return;
 command spack $_sp_flags $_sp_subcommand "$@"

These are not present when I source the script via source_sh in a modulefile. I'm not sure that is the culprit, but maybe a helpful tip?

Desktop (please complete the following information):

  • OS: Linux
  • Linux distribution: SUSE Linux Enterprise Server 15 SP4
  • Lmod Version: 8.7.31
Modules based on Lua: Version 8.7.31  2023-08-09 12:41 -05:00
    by Robert McLay mclay@tacc.utexas.edu

Changes from Default Configuration
----------------------------------

Name                           Where Set  Default                                           Value
----                           ---------  -------                                           -----
LFS_VERSION                    D          1.6.3                                             1.8.0
LMOD_ADMIN_FILE                E          /opt/cray/pe/lmod/etc/admin.list                  /opt/nersc/pe/etc/lmod/admin.list
LMOD_AVAIL_STYLE               E          <system>                                          grouped:system
LMOD_CASE_INDEPENDENT_SORTING  E          no                                                yes
LMOD_IGNORE_CACHE              E          false                                             yes
LMOD_MODULERCFILE              E          /opt/cray/pe/lmod/etc/rc                          /opt/nersc/pe/etc/lmod/modulerc.lua
LMOD_PACKAGE_PATH              D          nil                                               /opt/nersc/pe/etc/lmod/sitepackages
LMOD_PAGER                     C          less                                              /usr/bin/less
LMOD_RC                        E                                                            /opt/nersc/pe/etc/lmod/lmodrc.lua
LMOD_SITEPACKAGE_LOCATION      Other      /opt/cray/pe/lmod/8.7.31/libexec/SitePackage.lua  /opt/nersc/pe/etc/lmod/sitepackages/SitePackage.lua
LMOD_SITE_NAME                 E          false                                             NERSC
LMOD_SYSHOST                   E          false                                             perlmutter
LMOD_SYSTEM_DEFAULT_MODULES    E          __unknown__                                       craype-x86-milan:craype-network-ofi:perftools-base:xpmem:PrgEnv-gnu:cpe:gpu:sqs:darshan
LMOD_SYSTEM_NAME               E          false                                             perlmutter
LMOD_TCLSH                     C          tclsh                                             /usr/bin/tclsh
MODULEPATH_ROOT                E                                                            /opt/cray/pe/modulefiles
PATH_TO_LUA                    C          lua                                               /usr/bin/lua5.3


Where Set -> D: default, E: environment, C: configuration
             lmod_cfg: lmod_config.lua SitePkg: SitePackage StdPkg: StandardPackage
             Other: Set somewhere outside of normal locations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant