Skip to content

Commit 4e7f409

Browse files
committed
several updates to config and environment settings
Signed-off-by: vsoch <[email protected]>
1 parent 095ab18 commit 4e7f409

File tree

15 files changed

+230
-38
lines changed

15 files changed

+230
-38
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ 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.scom/singularityhub/singularity-hpc/tree/master) (0.0.x)
17+
- Allow environment variables in settings (0.0.29)
18+
- User settings file creation and use with shpc config inituser
19+
- registry is now a list to support multiple registry locations
20+
- config supports add/remove to append/delete from list
1721
- Add test for docker and podman (0.0.28)
1822
- namespace as format string for command named renamed to repository
1923
- shpc test/uninstall should be run for all tests

docs/getting_started/user-guide.rst

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,27 @@ Setup
9999
=====
100100

101101
Setup includes, after installation, editing any configuration values to
102-
customize your install. The defaults are likely suitable for most.
103-
For any configuration value that you might set, the following variables
104-
are available to you:
102+
customize your install. The configuration file will default to ``shpc/settings.yml``
103+
in the installed module, however you can create your own user settings file to
104+
take preference over this one as follows:
105+
106+
.. code-block:: console
107+
108+
$ shpc config userinit
109+
110+
111+
The defaults in either file are likely suitable for most. For any configuration value
112+
that you might set, the following variables are available to you:
105113

106114
- ``$install_dir``: the shpc folder
107115
- ``$root_dir``: the parent directory of shpc (where this README.md is located)
108116

109117

110-
A summary table of variables is included below, and then further discussed in detail.
118+
Additionally, the variables ``module_base``, ``container_base``, and ``registry``
119+
can be set with environment variables that will be expanded at runtime. You cannot
120+
use the protected set of substitution variables (``$install_dir`` and ``$install_root``)
121+
as environment variables, as they will be subbed in by shpc before environment
122+
variable replacement. A summary table of variables is included below, and then further discussed in detail.
111123

112124

113125
.. list-table:: Title
@@ -121,8 +133,8 @@ A summary table of variables is included below, and then further discussed in de
121133
- Set a default module system. Currently lmod and tcl are supported
122134
- [lmod, tcl]
123135
* - registry
124-
- The full path to the registry folder (with subfolders with container.yaml recipes)
125-
- $root_dir/registry
136+
- A list of full paths to one or more registry folders (with subfolders with container.yaml recipes)
137+
- [$root_dir/registry]
126138
* - module_base
127139
- The install directory for modules. Defaults to the install directory/modules
128140
- $root_dir/modules
@@ -271,8 +283,10 @@ directory.
271283
Registry
272284
--------
273285

274-
The registry folder in the root of the repository, but you can change it to
275-
be a custom one with the config variable ``registry``
286+
The registry parameter is a list of one or more registry locations (filesystem
287+
directories) where shpc will search for ``container.yaml`` files. The default
288+
registry shipped with shpc is the folder in the root of the repository, but
289+
you can add or remove entries via the config variable ``registry``
276290

277291

278292
.. code-block:: console
@@ -409,6 +423,8 @@ file directly, or you can use ``shpc config``, which will accept:
409423

410424
- set to set a parameter and value
411425
- get to get a parameter by name
426+
- add to add a value to a parameter that is a list (e.g., registry)
427+
- remove to remove a value from a parameter that is a list
412428

413429
The following example shows changing the default module_base path from the install directory modules folder.
414430

@@ -428,6 +444,14 @@ And then to get values:
428444
$ shpc config get module_base
429445
430446
447+
And to add and remove a value to a list:
448+
449+
.. code-block::console
450+
451+
$ shpc config add registry:/tmp/registry
452+
$ shpc config remove registry:/tmp/registry
453+
454+
431455
You can also open the config in the editor defined in settings at ``config_editor``
432456

433457
.. code-block:: console

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ And container technologies:
2020

2121
- `Singularity <https://github.com/sylabs/singularity>`_
2222
- `Podman <https://podman.io>`_
23+
- `Docker <https://www.docker.com/>`_
2324

2425
And coming soon:
2526

2627
- `Shifter <https://github.com/NERSC/shifter>`_
27-
- `Docker <https://www.docker.com/>`_
2828
- `Sarus <https://github.com/eth-cscs/sarus>`_
2929

3030

shpc/client/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,13 @@ def get_parser():
145145
config.add_argument(
146146
"params",
147147
nargs="*",
148-
help="Set or get a config value, or edit the config.\nshpc config set key:value\nshpc config get key\nshpc edit",
148+
help="""Set or get a config value, edit the config, add or remove a list variable, or create a user-specific config.
149+
shpc config set key:value
150+
shpc config get key
151+
shpc edit
152+
shpc config inituser
153+
shpc config add registry:/tmp/registry
154+
shpc config remove registry:/tmp/registry""",
149155
type=str,
150156
)
151157
# Generate markdown docs for a container registry entry

shpc/client/config.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ def main(args, parser, extra, subparser):
2424
)
2525

2626
# For each new setting, update and save!
27+
if command == "inituser":
28+
return cli.settings.inituser()
2729
if command == "edit":
2830
return cli.settings.edit()
29-
elif command == "set":
31+
elif command in ["set", "add", "remove"]:
3032
for param in args.params:
3133
if ":" not in param:
3234
logger.warning(
@@ -35,8 +37,15 @@ def main(args, parser, extra, subparser):
3537
)
3638
continue
3739
key, value = param.split(":", 1)
38-
cli.settings.set(key, value)
39-
logger.info("Updated %s to be %s" % (key, value))
40+
if command == "set":
41+
cli.settings.set(key, value)
42+
logger.info("Updated %s to be %s" % (key, value))
43+
elif command == "add":
44+
cli.settings.add(key, value)
45+
logger.info("Added %s to %s" % (key, value))
46+
elif command == "remove":
47+
cli.settings.remove(key, value)
48+
logger.info("Removed %s from %s" % (key, value))
4049

4150
# Save settings
4251
cli.settings.save()

shpc/defaults.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
# The default settings file in the install root
1313
default_settings_file = os.path.join(reps["$install_dir"], "settings.yml")
1414

15+
# The user settings file can be created to over-ride default
16+
user_settings_file = os.path.join(
17+
os.path.expanduser("~/.singularity-hpc"), "settings.yml"
18+
)
19+
20+
# variables in settings that allow environment variable expansion
21+
allowed_envars = ["container_base", "module_base", "registry"]
22+
1523
# The GitHub repository with recipes
1624
github_url = "https://github.com/singularityhub/singularity-hpc"
1725

shpc/main/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import shpc.utils
99
from shpc.logger import logger
10+
import shpc.defaults
1011

1112

1213
def get_client(quiet=False, **kwargs):

shpc/main/client.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ def add_namespace(self, name):
8686
name = "%s/%s" % (self.settings.namespace.strip("/"), name)
8787
return name
8888

89+
def load_registry_config(self, name):
90+
"""
91+
Given an identifier, find the first match in the registry.
92+
"""
93+
for registry, fullpath in self.container.iter_registry():
94+
package_dir = os.path.join(registry, name)
95+
package_file = os.path.join(package_dir, "container.yaml")
96+
if package_file == fullpath:
97+
return container.ContainerConfig(package_file)
98+
99+
logger.exit("%s is not a known recipe in any registry." % name)
100+
89101
def _load_container(self, name, tag=None):
90102
"""
91103
Given a name and an optional tag to default to, load a package
@@ -94,12 +106,8 @@ def _load_container(self, name, tag=None):
94106
if ":" in name:
95107
name, tag = name.split(":", 1)
96108

97-
# The recipe folder must exist in the registry
98-
package_dir = os.path.join(self.settings.registry, name)
99-
package_file = os.path.join(package_dir, "container.yaml")
100-
config = container.ContainerConfig(package_file)
101-
102109
# If the user provides a tag, set it
110+
config = self.load_registry_config(name)
103111
config.set_tag(tag)
104112
return config
105113

@@ -205,12 +213,10 @@ def show(self, name, names_only=False, out=None, filter_string=None):
205213
out = out or sys.stdout
206214

207215
# List the known registry modules
208-
for fullpath in utils.recursive_find(self.settings.registry):
216+
for registry, fullpath in self.container.iter_registry():
209217
if fullpath.endswith("container.yaml"):
210218
module_name = (
211-
os.path.dirname(fullpath)
212-
.replace(self.settings.registry, "")
213-
.strip(os.sep)
219+
os.path.dirname(fullpath).replace(registry, "").strip(os.sep)
214220
)
215221

216222
# If the user has provided a filter, honor it

shpc/main/container/base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ def container_dir(self, name):
9090
return os.path.join(self.settings.module_base, name)
9191
return os.path.join(self.settings.container_base, name)
9292

93+
def iter_registry(self):
94+
"""
95+
Iterate over known registries defined in settings.
96+
"""
97+
for registry in self.settings.registry:
98+
for filename in shpc.utils.recursive_find(registry):
99+
yield registry, filename
100+
93101
def guess_tag(self, module_name, allow_fail=False):
94102
"""
95103
If a user asks for a name without a tag, try to figure it out.

shpc/main/container/singularity.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,20 @@ def add(self, sif, module_name, modulefile, template, **kwargs):
7171
"""
7272
Manually add a registry container.
7373
"""
74-
registry_dir = self.settings.registry
75-
7674
# Ensure the container exists
7775
sif = os.path.abspath(sif)
7876
if not os.path.exists(sif):
7977
logger.exit("%s does not exist." % sif)
8078

8179
# First ensure that we aren't using a known namespace
82-
for subfolder in module_name.split("/"):
83-
registry_dir = os.path.join(registry_dir, subfolder)
84-
if os.path.exists(registry_dir):
85-
logger.exit(
86-
"%s is a known registry namespace, choose another for a custom addition."
87-
% subfolder
88-
)
80+
for registry_dir, _ in self.iter_registry():
81+
for subfolder in module_name.split("/"):
82+
registry_dir = os.path.join(registry_dir, subfolder)
83+
if os.path.exists(registry_dir):
84+
logger.exit(
85+
"%s is a known registry namespace, choose another for a custom addition."
86+
% subfolder
87+
)
8988

9089
# The user can have a different container directory defined
9190
container_dir = self.container_dir(module_name)

0 commit comments

Comments
 (0)