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

Pull jcsda-emc libs and repos out of spack fork #961

Merged
merged 10 commits into from
Jan 24, 2024
28 changes: 27 additions & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,31 @@ SPACK_STACK_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && p
export SPACK_STACK_DIR
echo "Setting environment variable SPACK_STACK_DIR to ${SPACK_STACK_DIR}"

source ${SPACK_STACK_DIR}/spack/share/spack/setup-env.sh
source ${SPACK_STACK_DIR:?}/spack/share/spack/setup-env.sh
echo "Sourcing spack environment ${SPACK_STACK_DIR}/spack/share/spack/setup-env.sh"

libpath=${SPACK_STACK_DIR}/spack-ext/lib/jcsda-emc/spack-stack
if [ -d ${libpath}/stack/cmd ]; then
spack config --scope defaults add "config:extensions:$libpath"
else
echo "FATAL ERROR: Could not find spack-stack extensions in ${libpath}"
return 1
fi

# Register the jcsda-emc repos
msg1="Added repo with namespace"
msg2="Repository is already registered with Spack"
for repo in jcsda-emc jcsda-emc-bundles; do
repodir=${SPACK_STACK_DIR}/spack-ext/repos/$repo
othererrors=$( ( spack repo add $repodir --scope defaults |& grep -v -e "$msg1" -e "$msg2" ) || true )
if [ $(echo "$othererrors" | grep -c .) -ne 0 ]; then
echo "$othererrors"
return 2
fi
if [ ! -d $repodir ]; then
echo "FATAL ERROR: Repo directory $repodir does not exist!"
return 3
fi
done

echo "spack-stack extensions and repos are registered"
2 changes: 1 addition & 1 deletion spack
Submodule spack updated 49 files
+0 −3 etc/spack/defaults/config.yaml
+0 −2 etc/spack/defaults/repos.yaml
+0 −9 lib/jcsda-emc/spack-stack/pytest.ini
+0 −40 lib/jcsda-emc/spack-stack/stack/cmd/stack.py
+0 −246 lib/jcsda-emc/spack-stack/stack/cmd/stack_cmds/create.py
+0 −14 lib/jcsda-emc/spack-stack/stack/cmd/stack_cmds/setup_meta_modules.py
+0 −76 lib/jcsda-emc/spack-stack/stack/container_env.py
+0 −861 lib/jcsda-emc/spack-stack/stack/meta_modules.py
+0 −332 lib/jcsda-emc/spack-stack/stack/stack_env.py
+0 −26 lib/jcsda-emc/spack-stack/stack/stack_paths.py
+0 −38 lib/jcsda-emc/spack-stack/stack/templates/compiler
+0 −42 lib/jcsda-emc/spack-stack/stack/templates/compiler.lua
+0 −41 lib/jcsda-emc/spack-stack/stack/templates/mpi
+0 −45 lib/jcsda-emc/spack-stack/stack/templates/mpi.lua
+0 −24 lib/jcsda-emc/spack-stack/stack/templates/python
+0 −28 lib/jcsda-emc/spack-stack/stack/templates/python.lua
+0 −1 lib/jcsda-emc/spack-stack/tests/conftest.py
+0 −63 lib/jcsda-emc/spack-stack/tests/test_setup_meta_modules.py
+0 −206 lib/jcsda-emc/spack-stack/tests/test_stack_create.py
+0 −42 var/spack/repos/jcsda-emc-bundles/packages/base-env/package.py
+0 −29 var/spack/repos/jcsda-emc-bundles/packages/emc-gfs-wafs-env/package.py
+0 −33 var/spack/repos/jcsda-emc-bundles/packages/emc-verif-global-env/package.py
+0 −70 var/spack/repos/jcsda-emc-bundles/packages/ewok-env/package.py
+0 −33 var/spack/repos/jcsda-emc-bundles/packages/geos-gcm-env/package.py
+0 −28 var/spack/repos/jcsda-emc-bundles/packages/gldas-env/package.py
+0 −47 var/spack/repos/jcsda-emc-bundles/packages/global-workflow-env/package.py
+0 −70 var/spack/repos/jcsda-emc-bundles/packages/gmao-swell-env/package.py
+0 −36 var/spack/repos/jcsda-emc-bundles/packages/gsi-env/package.py
+0 −67 var/spack/repos/jcsda-emc-bundles/packages/jedi-base-env/package.py
+0 −22 var/spack/repos/jcsda-emc-bundles/packages/jedi-fv3-env/package.py
+0 −22 var/spack/repos/jcsda-emc-bundles/packages/jedi-mpas-env/package.py
+0 −34 var/spack/repos/jcsda-emc-bundles/packages/jedi-neptune-env/package.py
+0 −38 var/spack/repos/jcsda-emc-bundles/packages/jedi-tools-env/package.py
+0 −34 var/spack/repos/jcsda-emc-bundles/packages/jedi-ufs-env/package.py
+0 −26 var/spack/repos/jcsda-emc-bundles/packages/jedi-um-env/package.py
+0 −41 var/spack/repos/jcsda-emc-bundles/packages/nceplibs-env/package.py
+0 −22 var/spack/repos/jcsda-emc-bundles/packages/soca-env/package.py
+0 −32 var/spack/repos/jcsda-emc-bundles/packages/ufs-pyenv/package.py
+0 −52 var/spack/repos/jcsda-emc-bundles/packages/ufs-srw-app-env/package.py
+0 −50 var/spack/repos/jcsda-emc-bundles/packages/ufs-utils-env/package.py
+0 −45 var/spack/repos/jcsda-emc-bundles/packages/ufs-weather-model-env/package.py
+0 −32 var/spack/repos/jcsda-emc-bundles/packages/upp-env/package.py
+0 −37 var/spack/repos/jcsda-emc-bundles/packages/ww3-env/package.py
+0 −2 var/spack/repos/jcsda-emc-bundles/repo.yaml
+0 −28 var/spack/repos/jcsda-emc/packages/ewok/package.py
+0 −24 var/spack/repos/jcsda-emc/packages/r2d2/package.py
+0 −82 var/spack/repos/jcsda-emc/packages/shumlib/package.py
+0 −23 var/spack/repos/jcsda-emc/packages/solo/package.py
+0 −2 var/spack/repos/jcsda-emc/repo.yaml
9 changes: 9 additions & 0 deletions spack-ext/lib/jcsda-emc/spack-stack/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# content of pytest.ini
[pytest]
addopts = --durations=20 -ra
testpaths = tests
markers =
db: tests that require creating a DB
network: tests that require access to the network
maybeslow: tests that may be slow (e.g. access a lot the filesystem, etc.)
regression: tests that fix a reported bug
40 changes: 40 additions & 0 deletions spack-ext/lib/jcsda-emc/spack-stack/stack/cmd/stack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os

from spack.extensions.stack.cmd.stack_cmds.create import (
setup_create_parser,
stack_create,
)
from spack.extensions.stack.cmd.stack_cmds.setup_meta_modules import (
setup_meta_modules_parser,
stack_setup_meta_modules,
)
from spack.extensions.stack.stack_paths import stack_path

description = "Create spack-stack environment"
section = "spack-stack"
level = "long"


default_env_name = 'default'
default_env_path = os.path.join(stack_path(), 'envs')
default_packages = os.path.join(stack_path(),
'configs', 'common', 'packages.yaml')
container_path = os.path.join(stack_path(), 'configs' 'containers')


def setup_parser(subparser):
sp = subparser.add_subparsers(metavar='SUBCOMMAND', dest='stack_command')
create_parser = sp.add_parser('create',
help='Create spack-stack environment or container.')
meta_modules_parser = sp.add_parser('setup-meta-modules',
help='Create lmod/lua or tcl/tk meta-modules')
setup_create_parser(create_parser)
setup_meta_modules_parser(meta_modules_parser)


# Main command that calls subcommands
def stack(parser, args):
if args.stack_command == 'create':
stack_create(parser, args)
if args.stack_command == 'setup-meta-modules':
stack_setup_meta_modules(parser, args)
246 changes: 246 additions & 0 deletions spack-ext/lib/jcsda-emc/spack-stack/stack/cmd/stack_cmds/create.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
import logging
import os
import shutil
from sys import platform

import llnl.util.tty as tty

from spack.extensions.stack.container_env import StackContainer
from spack.extensions.stack.stack_env import StackEnv, stack_path

description = "Create spack-stack environment (environment or container)"
section = "spack-stack"
level = "long"

default_env_name = "default"
default_env_path = stack_path("envs")


def default_site():
if platform == "linux" or platform == "linux2":
return "linux.default"
elif platform == "darwin":
return "macos.default"


def site_help():
_, site_dirs, _ = next(os.walk(stack_path("configs", "sites")))
help_string = 'Pre-configured platform, or "default" for an empty site.yaml.'
help_string += os.linesep
help_string += 'Defaults to "default" if no arg is given'
help_string += os.linesep
help_string += "Available options are: "
help_string += os.linesep
for site in site_dirs:
help_string += "\t" + site + os.linesep
return help_string


def template_help():
_, template_dirs, _ = next(os.walk(stack_path("configs", "templates")))
help_string = "Environment template" + os.linesep
help_string += "Default to an empty spack.yaml" + os.linesep
help_string += "Available options are: " + os.linesep
for template in template_dirs:
help_string += "\t" + template + os.linesep
return help_string


def container_config_help():
_, _, container_configs = next(os.walk(stack_path("configs", "containers")))
# Exclude files like "README.md"
container_configs = [x for x in container_configs if x.endswith(".yaml")]
help_string = "Pre-configured container." + os.linesep
help_string += "Available options are: " + os.linesep
for config in container_configs:
help_string += "\t" + config.rstrip(".yaml") + os.linesep
return help_string


def container_specs_help():
_, _, specs_lists = next(os.walk(stack_path("configs", "containers", "specs")))
help_string = "List of specs to build in container." + os.linesep
help_string += "Available options are: " + os.linesep
for specs_list in specs_lists:
help_string += "\t" + specs_list.rstrip(".yaml") + os.linesep
return help_string


def setup_common_parser_args(subparser):
"""Shared CLI args for container and environment subcommands"""

subparser.add_argument(
"--overwrite",
action="store_true",
required=False,
default=False,
help="Overwrite existing environment if it exists." " Warning this is dangerous.",
)


def setup_ctr_parser(subparser):
"""create container-specific parsing options"""

subparser.add_argument("--container", required=True, help=container_config_help())

subparser.add_argument("--specs", required=True, help=container_specs_help())

subparser.add_argument(
"--dir",
type=str,
required=False,
default=default_env_path,
help="Environment will be placed in <dir>/container/."
" Default is {}/container/.".format(default_env_path),
)

setup_common_parser_args(subparser)


def setup_env_parser(subparser):
"""create environment-specific parsing options"""
setup_common_parser_args(subparser)

subparser.add_argument(
"--dir",
type=str,
required=False,
default=default_env_path,
help="Environment will be placed in <dir>/<env-name>/."
" Default is {}/<env-name>/.".format(default_env_path),
)

subparser.add_argument(
"--name",
type=str,
required=False,
default=None,
help="Environment name, defaults to <template>.<site>",
)

subparser.add_argument(
"--template",
type=str,
required=False,
dest="template",
default="empty",
help=template_help(),
)

subparser.add_argument(
"--packages",
type=str,
required=False,
default=None,
help="Base packages.yaml, use to override common packages.yaml.",
)

subparser.add_argument(
"--upstream",
nargs="*",
action="append",
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)",
)

subparser.add_argument(
"--site", type=str, required=False, default=default_site(), help=site_help()
)

subparser.add_argument(
"--prefix",
type=str,
required=False,
default=None,
help="""Install prefix for spack packages and
modules (not the spack environment).""",
)

subparser.add_argument(
"--modify-pkg",
action="append",
help="Modify selected package and place in an environment-specific repository",
)


def setup_create_parser(subparser):
sp = subparser.add_subparsers(metavar="SUBCOMMAND", dest="env_type")

env_parser = sp.add_parser("env", help="Create local Spack environment")
ctr_parser = sp.add_parser("ctr", help="Create container.")

setup_env_parser(env_parser)

setup_ctr_parser(ctr_parser)


def container_create(args):
"""Create pre-configured container"""

container = StackContainer(args.container, args.dir, args.specs)

env_dir = container.env_dir
if os.path.exists(env_dir):
if args.overwrite:
tty.msg("Env {} exists. Overwriting...".format(env_dir))
shutil.rmtree(env_dir)
else:
raise Exception("Env: {} already exists".format(env_dir))

container.write()
tty.msg("Created container {}".format(env_dir))


def dict_from_args(args):
dict = {}
dict["site"] = args.site
dict["template"] = args.template
dict["name"] = args.name
dict["install_prefix"] = args.prefix
dict["base_packages"] = args.packages
dict["dir"] = args.dir
dict["upstreams"] = args.upstream
dict["modulesys"] = args.modulesys
dict["modifypkg"] = args.modify_pkg

return dict


def env_create(args):
"""Create pre-configured Spack environment.

Args: args

Returns:

"""

stack_settings = dict_from_args(args)
stack_env = StackEnv(**stack_settings)

env_dir = stack_env.env_dir()
if os.path.exists(env_dir):
if args.overwrite:
tty.msg("Environment {} exists. Overwriting...".format(env_dir))
shutil.rmtree(env_dir)
else:
raise Exception("Environment: {} already exists".format(env_dir))

logging.debug("Creating environment from command-line args")
stack_env = StackEnv(**stack_settings)
stack_env.write()
stack_env.check_umask()
tty.msg("Created environment {}".format(env_dir))


def stack_create(parser, args):
if args.env_type == "env":
env_create(args)
elif args.env_type == "ctr":
container_create(args)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from spack.extensions.stack.meta_modules import setup_meta_modules

description = "Create meta-modules"
section = "spack-stack"
level = "long"


# Add potential arguments to setup-meta-modules
def setup_meta_modules_parser(subparser):
pass


def stack_setup_meta_modules(parser, args):
setup_meta_modules()
Loading
Loading