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

View install commands #596

Merged
merged 11 commits into from
Oct 12, 2022
15 changes: 12 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ jobs:
printf "\n\nmodule help ============================================\n"
module help python/3.9.5-alpine

set -x
python-exec echo donuts >test_output
cat test_output
grep --quiet donuts test_output
Expand All @@ -109,13 +110,14 @@ jobs:
cat test_output
grep --quiet 'Python 3.9.5' test_output
rm test_output
shpc uninstall --force python:3.9.5-alpine

# Try creating views install
mkdir -p tmp-modules
shpc config set views_base:tmp-modules
shpc view create noodles
shpc install --view noodles python:3.9.5-alpine
shpc view install noodles python:3.9.5-alpine

shpc uninstall --force python:3.9.5-alpine
shpc view --force delete noodles

- name: Run python module tests (tcsh)
shell: tcsh -e {0}
Expand Down Expand Up @@ -164,4 +166,11 @@ jobs:
cat test_output
grep --quiet 'Python 3.9.5' test_output
rm test_output

mkdir -p tmp-modules
shpc config set views_base:tmp-modules
shpc view create noodles
shpc view install noodles python:3.9.5-alpine

shpc uninstall --force python:3.9.5-alpine
shpc view --force delete noodles
6 changes: 0 additions & 6 deletions shpc/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,6 @@ def get_parser():
"install_recipe",
help="recipe to install\nshpc install python\nshpc install python:3.9.5-alpine",
)
install.add_argument(
"--view",
dest="view",
help="install module to a named view (must be installed to shpc first).",
default=None,
)
install.add_argument(
"--no-view",
dest="no_view",
Expand Down
7 changes: 1 addition & 6 deletions shpc/client/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
__license__ = "MPL 2.0"

import shpc.utils
from shpc.logger import logger


def main(args, parser, extra, subparser):
Expand All @@ -25,11 +24,7 @@ def main(args, parser, extra, subparser):
# Update config settings on the fly
cli.settings.update_params(args.config_params)

# It doesn't make sense to define view and no view
if args.view and args.no_view:
logger.exit("Conflicting arguments --view and --no-view, choose one.")

# And do the install
cli.install(
args.install_recipe, view=args.view, disable_view=args.no_view, force=args.force
args.install_recipe, disable_default_view=args.no_view, force=args.force
)
14 changes: 12 additions & 2 deletions shpc/client/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ def create_from_file(

# Extra modules to install
for install_module in install_modules:
cli.install(install_module, view=view_name, disable_view=False, force=force)
cli.install(
install_module,
extra_view=view_name,
disable_default_view=False,
force=force,
)


def main(args, parser, extra, subparser):
Expand Down Expand Up @@ -168,7 +173,12 @@ def main(args, parser, extra, subparser):
# We don't make it hard to require them to install to the root first
module_name = args.params.pop(0)
if command == "install":
cli.install(module_name, view=view_name, disable_view=False, force=args.force)
cli.install(
module_name,
extra_view=view_name,
disable_default_view=False,
force=args.force,
)

if command == "uninstall":
cli.uninstall(module_name, view=view_name, force=args.force)
29 changes: 20 additions & 9 deletions shpc/main/modules/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,13 @@ def check(self, module_name):
return self.container.check(module_name, config)

def install(
self, name, tag=None, view=None, disable_view=False, force=False, **kwargs
self,
name,
tag=None,
extra_view=None,
muffato marked this conversation as resolved.
Show resolved Hide resolved
disable_default_view=False,
force=False,
**kwargs
):
"""
Given a unique resource identifier, install a recipe.
Expand Down Expand Up @@ -387,22 +393,27 @@ def install(
container_dir = self.container.container_dir(subfolder)

# Are we also installing to a named view?
if view is None and not disable_view:
view = self.settings.default_view
view_names = []
muffato marked this conversation as resolved.
Show resolved Hide resolved
if self.settings.default_view and not disable_default_view:
view_names.append(self.settings.default_view)
if extra_view:
view_names.append(extra_view)

# We only want to load over-rides for a tag at install time
config.load_override_file(tag.name)

# A view is a symlink under views_base/$view/$module
if view:
if view not in self.views:
for view_name in view_names:
muffato marked this conversation as resolved.
Show resolved Hide resolved
if view_name not in self.views:
logger.exit(
"View %s does not exist, shpc view create %s." % (view, view)
"View %s does not exist, shpc view create %s."
% (view_name, view_name)
)

# Update view from name to be View to interact with
view = self.views[view]
# Update view from name to be View to interact with
views = [self.views[view_name] for view_name in view_names]
muffato marked this conversation as resolved.
Show resolved Hide resolved

for view in views:
# Don't continue if it exists, unless force is True
view.confirm_install(module_dir, force=force)

Expand Down Expand Up @@ -476,7 +487,7 @@ def install(
logger.info("Module %s was created." % name)

# Install the module (symlink) to the view and create version file
if view:
for view in views:
muffato marked this conversation as resolved.
Show resolved Hide resolved
view.install(module_dir)

return container_path
2 changes: 1 addition & 1 deletion shpc/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_views(tmp_path, module_sys, module_file, container_tech, remote):
assert not view._config["view"]["system_modules"]

# Now install to it via the client
client.install("ghcr.io/autamus/emacs:27.2", view=view_name)
client.install("ghcr.io/autamus/emacs:27.2", extra_view=view_name)
muffato marked this conversation as resolved.
Show resolved Hide resolved

# Ensure it was created and as a symlink
assert view._config["view"]["modules"]
Expand Down