diff --git a/CHANGELOG.md b/CHANGELOG.md index c4414fa53..9b24f3334 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are: The versions coincide with releases on pip. Only major versions will be released as tags on Github. ## [0.0.x](https://github.com/singularityhub/singularity-hpc/tree/main) (0.0.x) + - Labels with newlines need additional parsing (0.1.23) - Do not write directly to output with shpc show (0.1.22) - Podman template bug (0.1.21) - Improvement to shpc help command output (0.1.2) diff --git a/docs/getting_started/user-guide.rst b/docs/getting_started/user-guide.rst index abd5395c1..9b935a54f 100644 --- a/docs/getting_started/user-guide.rst +++ b/docs/getting_started/user-guide.rst @@ -157,7 +157,7 @@ as environment variables, as they will be subbed in by shpc before environment variable replacement. A summary table of variables is included below, and then further discussed in detail. -.. list-table:: Title +.. list-table:: Settings :widths: 25 65 10 :header-rows: 1 @@ -191,6 +191,9 @@ variable replacement. A summary table of variables is included below, and then f * - updated_at - a timestamp to keep track of when you last saved - never + * - label_separator + - When parsing labels, replace newlines with this string + - ', ' * - default_version - Should a default version be used? - module_sys diff --git a/shpc/main/container/base.py b/shpc/main/container/base.py index c3752c14c..afabadff0 100644 --- a/shpc/main/container/base.py +++ b/shpc/main/container/base.py @@ -102,6 +102,15 @@ def container_dir(self, name): return os.path.join(self.settings.module_base, name) return os.path.join(self.settings.container_base, name) + def clean_labels(self, labels): + """ + Clean labels, meaning removing newlines and replacing with label separator + """ + updated_labels = {} + for key, value in labels.items(): + updated_labels[key] = value.replace("\n", self.settings.label_separator) + return updated_labels + def guess_tag(self, module_name, allow_fail=False): """ If a user asks for a name without a tag, try to figure it out. diff --git a/shpc/main/container/config.py b/shpc/main/container/config.py index a9027f492..85bbe6654 100644 --- a/shpc/main/container/config.py +++ b/shpc/main/container/config.py @@ -254,6 +254,9 @@ def get_url(self): return self.get("docker") or self.get("gh") or self.get("path") def get(self, key, default=None): + """ + Get a value from the config. + """ return self.entry._config.get(key, default) def get_pull_type(self): diff --git a/shpc/main/container/docker.py b/shpc/main/container/docker.py index fa475977b..7130b5d33 100644 --- a/shpc/main/container/docker.py +++ b/shpc/main/container/docker.py @@ -207,7 +207,8 @@ def install(self, module_path, template, module, features=None): "Container %s was not found. Was it pulled?" % module.container_path ) - labels = manifest[0].get("Labels", {}) + labels = manifest[0].get("Labels") or {} + labels = self.clean_labels(labels) # Option to create wrapper scripts for commands aliases = module.config.get_aliases() diff --git a/shpc/main/container/singularity.py b/shpc/main/container/singularity.py index 1f35db91c..46fb60adb 100644 --- a/shpc/main/container/singularity.py +++ b/shpc/main/container/singularity.py @@ -191,7 +191,7 @@ def install(self, module_path, template, module, features=None): metadata = self.inspect(module.container_path) # Add labels, and deffile - labels = metadata.get("attributes", {}).get("labels") + labels = metadata.get("attributes", {}).get("labels") or {} deffile = ( metadata.get("attributes", {}).get("deffile", "").replace("\n", "\\n") ) @@ -203,6 +203,9 @@ def install(self, module_path, template, module, features=None): # Option to create wrapper scripts for commands aliases = module.config.get_aliases() + # Labels with newlines need to be handled, replace with comma + labels = self.clean_labels(labels) + # Wrapper scripts can be global (for aliases) or container specific wrapper_scripts = [] if self.settings.wrapper_scripts["enabled"] is True: diff --git a/shpc/main/schemas.py b/shpc/main/schemas.py index ea50896b8..1efdc2381 100644 --- a/shpc/main/schemas.py +++ b/shpc/main/schemas.py @@ -157,6 +157,7 @@ ] }, "enable_tty": {"type": "boolean"}, + "label_separator": {"type": "string"}, "views_base": {"type": ["string", "null"]}, "default_view": {"type": ["string", "null"]}, "wrapper_scripts": wrapper_scripts, diff --git a/shpc/settings.yml b/shpc/settings.yml index fa2dcf25a..e9d9f76eb 100644 --- a/shpc/settings.yml +++ b/shpc/settings.yml @@ -42,6 +42,9 @@ default_version: module_sys # It's recommended to do this for faster loading container_base: $root_dir/containers +# When parsing labels, replace newlines with this string +label_separator: ', ' + # Default root directory to create views views_base: $root_dir/views diff --git a/shpc/version.py b/shpc/version.py index df99c5993..4e292b62d 100644 --- a/shpc/version.py +++ b/shpc/version.py @@ -2,7 +2,7 @@ __copyright__ = "Copyright 2021-2023, Vanessa Sochat" __license__ = "MPL 2.0" -__version__ = "0.1.22" +__version__ = "0.1.23" AUTHOR = "Vanessa Sochat" EMAIL = "vsoch@users.noreply.github.com" NAME = "singularity-hpc"