Skip to content

Commit

Permalink
Accommodate separate lmod, tcl modules.yaml's
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderRichert-NOAA committed Sep 29, 2023
1 parent a90e852 commit 7caaca6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/jcsda-emc/spack-stack/stack/cmd/stack_cmds/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ def setup_common_parser_args(subparser):
help="Include upstream environment (/path/to/spack-stack-x.y.z/envs/unified-env/install)",
)

subparser.add_argument(
"--modulesys",
type=str,
choices=["lmod", "tcl"],
help="Override choice of tcl vs. lmod config (default is based on site config)",
)


def setup_ctr_parser(subparser):
"""create container-specific parsing options"""
Expand Down Expand Up @@ -168,6 +175,7 @@ def dict_from_args(args):
dict["base_packages"] = args.packages
dict["dir"] = args.dir
dict["upstreams"] = args.upstream
dict["modulesys"] = args.modulesys

return dict

Expand Down
21 changes: 20 additions & 1 deletion lib/jcsda-emc/spack-stack/stack/stack_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def __init__(self, **kwargs):
self.install_prefix = kwargs.get("install_prefix", None)
self.mirror = kwargs.get("mirror", None)
self.upstreams = kwargs.get("upstreams", None)
self.modulesys = kwargs.get("modulesys", None)

if not self.name:
# site = self.site if self.site else 'default'
Expand All @@ -108,11 +109,29 @@ def env_dir(self):
def add_includes(self, includes):
self.includes.extend(includes)

def get_lmod_or_tcl(self, site_configs_dir):
site_modules_yaml_path = os.path.join(site_configs_dir, "modules.yaml")
with open(site_modules_yaml_path, "r") as f:
site_modules_yaml = syaml.load_config(f)
lmod_or_tcl_list = site_modules_yaml["modules"]["default"]["enable"]
if len(set(lmod_or_tcl_list)) > 1:
logging.warning("WARNING: Multiple lmod/tcl settings found for %s; using the first" % site_modules_yaml_path)
lmod_or_tcl = lmod_or_tcl_list[0]
assert lmod_or_tcl in ("lmod", "tcl"), "lmod/tcl setting could not be determined for %s" % site_modules_yaml_path
return lmod_or_tcl

def _copy_common_includes(self):
"""Copy common directory into environment"""
self.includes.append("common")
env_common_dir = os.path.join(self.env_dir(), "common")
shutil.copytree(common_path, env_common_dir)
shutil.copytree(common_path, env_common_dir, ignore=shutil.ignore_patterns("modules_*.yaml"))
if not self.modulesys:
lmod_or_tcl = self.get_lmod_or_tcl(self.site_configs_dir())
else:
lmod_or_tcl = self.modulesys
modules_yaml_path = os.path.join(common_path, "modules_%s.yaml" % lmod_or_tcl)
destination = os.path.join(env_common_dir, "modules.yaml")
shutil.copy(modules_yaml_path, destination)

def site_configs_dir(self):
site_configs_dir = os.path.join(site_path, self.site)
Expand Down

0 comments on commit 7caaca6

Please sign in to comment.