From 96e99459e6271c49de9b6f07ec8bbf4307aa24e4 Mon Sep 17 00:00:00 2001 From: tituspijean Date: Sun, 15 Oct 2023 16:31:14 +0200 Subject: [PATCH 1/5] Support packages_from_raw_bash in extra packages --- src/utils/resources.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/utils/resources.py b/src/utils/resources.py index 69b260334..f206b9b96 100644 --- a/src/utils/resources.py +++ b/src/utils/resources.py @@ -1086,7 +1086,6 @@ class AptDependenciesAppResource(AppResource): packages: List = [] packages_from_raw_bash: str = "" extras: Dict[str, Dict[str, Union[str, List]]] = {} - def __init__(self, properties: Dict[str, Any], *args, **kwargs): super().__init__(properties, *args, **kwargs) @@ -1106,13 +1105,25 @@ class AptDependenciesAppResource(AppResource): if isinstance(values.get("packages"), str): values["packages"] = [value.strip() for value in values["packages"].split(",")] # type: ignore + if isinstance(values.get("packages_from_raw_bash"), str): + out, err = self.check_output_bash_snippet(values.get("packages_from_raw_bash")) + if err: + logger.error( + "Error while running apt resource packages_from_raw_bash snippet for '" + str(key) + "' extras:" + ) + logger.error(err) + values["packages"] = [value.strip() for value in out.split("\n")] + if ( not isinstance(values.get("repo"), str) or not isinstance(values.get("key"), str) - or not isinstance(values.get("packages"), list) + or ( + not isinstance(values.get("packages"), list) + and not isinstance(values.get("packages_from_raw_bash"), str) + ) ): raise YunohostError( - "In apt resource in the manifest: 'extras' repo should have the keys 'repo', 'key' defined as strings and 'packages' defined as list", + "In apt resource in the manifest: 'extras' repo should have the keys 'repo', 'key' defined as strings, 'packages' defined as list or 'packages_from_raw_bash' defined as string", raw_msg=True, ) From a69b80972eaec9673dc848b7ef09a043e0730272 Mon Sep 17 00:00:00 2001 From: tituspijean Date: Sun, 15 Oct 2023 16:46:24 +0200 Subject: [PATCH 2/5] Improve support for packages_from_raw_bash Co-authored-by: Alexandre Aubin <4533074+alexAubin@users.noreply.github.com> --- src/utils/resources.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/utils/resources.py b/src/utils/resources.py index f206b9b96..18b1bdb4c 100644 --- a/src/utils/resources.py +++ b/src/utils/resources.py @@ -1109,10 +1109,10 @@ class AptDependenciesAppResource(AppResource): out, err = self.check_output_bash_snippet(values.get("packages_from_raw_bash")) if err: logger.error( - "Error while running apt resource packages_from_raw_bash snippet for '" + str(key) + "' extras:" + f"Error while running apt resource packages_from_raw_bash snippet for '{key}' extras:" ) logger.error(err) - values["packages"] = [value.strip() for value in out.split("\n")] + values["packages"] = values.get("packages", []) + [value.strip() for value in out.split("\n")] if ( not isinstance(values.get("repo"), str) @@ -1126,6 +1126,9 @@ class AptDependenciesAppResource(AppResource): "In apt resource in the manifest: 'extras' repo should have the keys 'repo', 'key' defined as strings, 'packages' defined as list or 'packages_from_raw_bash' defined as string", raw_msg=True, ) + + # Drop 'extras' entries associated to no packages + self.extras = {key: value for key, values in self.extras.items() if values["packages"]} def provision_or_update(self, context: Dict = {}): script = " ".join(["ynh_install_app_dependencies", *self.packages]) From dc362dd636eaf912c788b2d468c015eb7bf035d1 Mon Sep 17 00:00:00 2001 From: tituspijean Date: Sun, 15 Oct 2023 16:48:59 +0200 Subject: [PATCH 3/5] Revert packages_from_raw_bash test Co-authored-by: Alexandre Aubin --- src/utils/resources.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/utils/resources.py b/src/utils/resources.py index 18b1bdb4c..ba1a915e4 100644 --- a/src/utils/resources.py +++ b/src/utils/resources.py @@ -1117,10 +1117,7 @@ class AptDependenciesAppResource(AppResource): if ( not isinstance(values.get("repo"), str) or not isinstance(values.get("key"), str) - or ( - not isinstance(values.get("packages"), list) - and not isinstance(values.get("packages_from_raw_bash"), str) - ) + or not isinstance(values.get("packages"), list) ): raise YunohostError( "In apt resource in the manifest: 'extras' repo should have the keys 'repo', 'key' defined as strings, 'packages' defined as list or 'packages_from_raw_bash' defined as string", From 23cdf91b0198ce8d4a034aea04f95406795b7c5f Mon Sep 17 00:00:00 2001 From: tituspijean Date: Sun, 15 Oct 2023 16:49:55 +0200 Subject: [PATCH 4/5] Restore deleted line --- src/utils/resources.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/resources.py b/src/utils/resources.py index ba1a915e4..87f6ae368 100644 --- a/src/utils/resources.py +++ b/src/utils/resources.py @@ -1086,6 +1086,7 @@ class AptDependenciesAppResource(AppResource): packages: List = [] packages_from_raw_bash: str = "" extras: Dict[str, Dict[str, Union[str, List]]] = {} + def __init__(self, properties: Dict[str, Any], *args, **kwargs): super().__init__(properties, *args, **kwargs) From 662998a1ab229f1c3cd2cdb736149fb3589aa23d Mon Sep 17 00:00:00 2001 From: Alexandre Aubin <4533074+alexAubin@users.noreply.github.com> Date: Mon, 16 Oct 2023 15:49:12 +0200 Subject: [PATCH 5/5] Update src/utils/resources.py --- src/utils/resources.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/utils/resources.py b/src/utils/resources.py index 87f6ae368..ba1a915e4 100644 --- a/src/utils/resources.py +++ b/src/utils/resources.py @@ -1086,7 +1086,6 @@ class AptDependenciesAppResource(AppResource): packages: List = [] packages_from_raw_bash: str = "" extras: Dict[str, Dict[str, Union[str, List]]] = {} - def __init__(self, properties: Dict[str, Any], *args, **kwargs): super().__init__(properties, *args, **kwargs)