Skip to content

Commit ed2d000

Browse files
authored
Adding namespaces to make module install easier (#366)
* adding namespaces to make module install easier * add tests for show and namespace Signed-off-by: vsoch <[email protected]>
1 parent 85d60f0 commit ed2d000

File tree

15 files changed

+235
-25
lines changed

15 files changed

+235
-25
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
shpc.db
22
singularity_hpc.egg-info/
33
.env
4+
env
45
build
56
docs/_build
67
release

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are:
1414
The versions coincide with releases on pip. Only major versions will be released as tags on Github.
1515

1616
## [0.0.x](https://github.com/singularityhub/singularity-hpc/tree/master) (0.0.x)
17+
- adding namespaces to make module install, show, inspect easier (0.0.24)
1718
- container url does not render in docs (0.0.23)
1819
- addition of tcl modules, removal of un-needed database (0.0.22)
1920
- first update of all containers, and bugfix to pull (0.0.21)

docs/getting_started/installation.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ You'll next want to configure and create your registry, discussed next in
7676
.. code-black:: console
7777

7878

79-
$ shpc config registry:/<DIR>
80-
$ shpc config lmod_base:/<DIR>
81-
$ shpc config container_base:/<DIR>
79+
$ shpc config set registry:/<DIR>
80+
$ shpc config set lmod_base:/<DIR>
81+
$ shpc config set container_base:/<DIR>
8282

8383

8484
You can also easily (manually) update any settings in the ``shpc/settings.yaml`` file.

docs/getting_started/user-guide.rst

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ A summary table of variables is included below, and then further discussed in de
206206
* - singularity_shell
207207
- exported to SINGULARITY_SHELL, defaults to /bin/bash.
208208
- /bin/bash
209+
* - namespace
210+
- Set a default module namespace that you want to install from.
211+
- null
209212

210213

211214

@@ -339,16 +342,29 @@ Config
339342
------
340343

341344
If you want to edit a configuration value, you can either edit the ``shpc/settings.yml``
342-
file directly, or you can use ``shpc config``. The following example shows changing
343-
the default module_base path from the install directory modules folder.
345+
file directly, or you can use ``shpc config``, which will accept:
346+
347+
- set to set a parameter and value
348+
- get to get a parameter by name
349+
350+
351+
The following example shows changing the default module_base path from the install directory modules folder.
344352

345353
.. code-block:: console
346354
347355
# an absolute path
348-
$ shpc config module_base:/opt/lmod/modules
356+
$ shpc config set module_base:/opt/lmod/modules
349357
350358
# or a path relative to the install directory, remember to escape the "$"
351-
$ shpc config module_base:\$install_dir/modules
359+
$ shpc config set module_base:\$install_dir/modules
360+
361+
362+
And then to get values:
363+
364+
.. code-block:: console
365+
366+
$ shpc config get module_base
367+
352368
353369
354370
Show and Install
@@ -420,6 +436,70 @@ the container technology.
420436
If you don't have any module software on your system, you can now test interacting
421437
with the module via the :ref:`getting_started-development` instructions.
422438

439+
440+
Namespace
441+
---------
442+
443+
Let's say that you are exclusively using continers in the namespace ghcr.io/autamus.
444+
445+
.. code-block:: console
446+
447+
registry/ghcr.io/
448+
└── autamus
449+
├── abi-dumper
450+
├── abyss
451+
├── accumulo
452+
├── addrwatch
453+
...
454+
├── xrootd
455+
├── xz
456+
└── zlib
457+
458+
459+
It can become arduous to type the entire namespace every time! For this purpose,
460+
you can set a namespace:
461+
462+
.. code-block:: console
463+
464+
$ shpc namespace use ghcr.io/autamus
465+
466+
And then instead of asking to install clingo as follows:
467+
468+
.. code-block:: console
469+
470+
$ shpc install ghcr.io/autamus/clingo
471+
472+
473+
You can simply ask for:
474+
475+
476+
.. code-block:: console
477+
478+
$ shpc install clingo
479+
480+
481+
And when you are done, unset the namespace.
482+
483+
484+
.. code-block:: console
485+
486+
$ shpc namespace unset
487+
488+
489+
Note that you can also set the namespace as any other setting:
490+
491+
.. code-block:: console
492+
493+
$ shpc config set namespace:ghcr.io/autamus
494+
495+
Namespaces currently work with:
496+
497+
- install
498+
- uninstall
499+
- show
500+
- add
501+
- check
502+
423503
List
424504
----
425505

docs/index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ Resources
5757
`Singularity HPC Library <https://github.com/singularityhub/singularity-hpc/issues>`_
5858
Shows modules available to install as containers.
5959

60+
`Autamus Registry <https://autamus.io>`_
61+
Provides many of the shpc container modules, built directly from spack.
62+
6063

6164
.. toctree::
6265
:caption: Getting started
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
docker: vanessa/salad
2+
url: https://hub.docker.com/r/vanessa/salad
3+
maintainer: '@vsoch'
4+
description: A container all about fork and spoon puns.
5+
latest:
6+
latest: sha256:e8302da47e3200915c1d3a9406d9446f04da7244e4995b7135afd2b79d4f63db
7+
tags:
8+
latest: sha256:e8302da47e3200915c1d3a9406d9446f04da7244e4995b7135afd2b79d4f63db
9+
aliases:
10+
salad: /code/salad

shpc/client/__init__.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212

1313

1414
def get_parser():
15-
parser = argparse.ArgumentParser(description="Singularity Registry (HPC)")
15+
parser = argparse.ArgumentParser(
16+
description="Singularity Registry (HPC)",
17+
formatter_class=argparse.RawTextHelpFormatter,
18+
)
1619

1720
# Global Variables
1821
parser.add_argument(
@@ -104,7 +107,10 @@ def get_parser():
104107
check = subparsers.add_parser("check", help="check if you have latest installed.")
105108
check.add_argument("module_name", help="module to check (module/version)")
106109

107-
config = subparsers.add_parser("config", help="update configuration settings.")
110+
config = subparsers.add_parser(
111+
"config",
112+
help="update configuration settings. Use set or get to see or set information.",
113+
)
108114
config.add_argument(
109115
"params",
110116
nargs="*",
@@ -198,6 +204,16 @@ def get_parser():
198204
default="singularity",
199205
)
200206

207+
namespace = subparsers.add_parser(
208+
"namespace",
209+
help="set or unset the install namespace. E.g.,:\n shpc namespace set <namespace>\n shpc namespace unset",
210+
)
211+
namespace.add_argument(
212+
"namespace",
213+
help="command (use/unset) and if use, the namespace to set",
214+
nargs="*",
215+
)
216+
201217
show = subparsers.add_parser("show", help="show the config for a registry entry.")
202218
show.add_argument(
203219
"--versions", help="include versions", default=False, action="store_true"
@@ -277,6 +293,8 @@ def help(return_code=0):
277293
from .inspect import main
278294
elif args.command == "list":
279295
from .listing import main
296+
elif args.command == "namespace":
297+
from .namespace import main
280298
elif args.command == "shell":
281299
from .shell import main
282300
elif args.command == "show":

shpc/client/config.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,31 @@ def main(args, parser, extra, subparser):
1717
print(subparser.format_help())
1818
sys.exit(0)
1919

20-
# For each new setting, update and save!
21-
for param in args.params:
22-
key, value = param.split(":", 1)
23-
logger.info("Updating %s to be %s" % (key, value))
24-
cli.settings.set(key, value)
20+
# The first "param" is either set of get
21+
command = args.params.pop(0)
2522

26-
# Save settings
27-
cli.settings.save()
23+
# For each new setting, update and save!
24+
if command == "set":
25+
for param in args.params:
26+
if ":" not in param:
27+
logger.warning(
28+
"Param %s is missing a :, should be key:value pair. Skipping."
29+
% param
30+
)
31+
continue
32+
key, value = param.split(":", 1)
33+
logger.info("Updating %s to be %s" % (key, value))
34+
cli.settings.set(key, value)
35+
36+
# Save settings
37+
cli.settings.save()
38+
39+
# For each get request, print the param pair
40+
elif command == "get":
41+
for key in args.params:
42+
value = cli.settings.get(key)
43+
value = value or "is unset"
44+
logger.info("%s %s" % (key.ljust(30), value))
45+
46+
else:
47+
logger.error("%s is not a recognized command." % command)

shpc/client/namespace.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
__author__ = "Vanessa Sochat"
2+
__copyright__ = "Copyright 2021, Vanessa Sochat"
3+
__license__ = "MPL 2.0"
4+
5+
6+
from shpc.logger import logger
7+
import sys
8+
9+
10+
def main(args, parser, extra, subparser):
11+
12+
from shpc.main import get_client
13+
14+
cli = get_client(quiet=args.quiet, settings_file=args.settings_file)
15+
16+
# Case 1: we need to unset a namespace
17+
if not args.namespace:
18+
sys.exit("Please choose: shpc use <namespace> or shpc unset.")
19+
20+
command = args.namespace.pop(0)
21+
22+
# Unset a namespace, does not need or consider additional arguments
23+
if command == "unset":
24+
logger.info("Unsetting all namespaces.")
25+
cli.settings.set("namespace", None)
26+
27+
# use a namespace requires another argument (the namespace)
28+
elif command == "use":
29+
if not args.namespace:
30+
sys.exit("use must be followed by a namespace!")
31+
namespace = args.namespace[0]
32+
logger.info("Setting namespace %s" % namespace)
33+
cli.settings.set("namespace", namespace)
34+
35+
cli.settings.save()

shpc/main/client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ def get(self, module_name):
106106
"""
107107
raise NotImplementedError
108108

109+
def add_namespace(self, name):
110+
"""
111+
If a namespace is defined in settings, use it
112+
"""
113+
if self.settings.namespace:
114+
name = "%s/%s" % (self.settings.namespace.strip("/"), name)
115+
return name
116+
109117
def _load_container(self, name, tag=None):
110118
"""
111119
Given a name and an optional tag to default to, load a package
@@ -225,6 +233,7 @@ def show(self, name, names_only=False, out=None):
225233
Show available packages
226234
"""
227235
if name:
236+
name = self.add_namespace(name)
228237
config = self._load_container(name)
229238
config.dump(out)
230239
else:

0 commit comments

Comments
 (0)