Date: Wednesday, May 10, 2023 @ 09:22:39
  Author: dvzrv
Revision: 1459743

upgpkg: molecule-plugins 23.4.1-3: Rebuild to fix issues with vagrant plugin.

Apply an upstream (not merged) fix to make the vagrant plugin work again:
https://github.com/ansible-community/molecule-plugins/pull/142
https://bugs.archlinux.org/task/78447

Added:
  molecule-plugins/trunk/molecule-plugins-23.4.1-molecule_internals.patch
Modified:
  molecule-plugins/trunk/PKGBUILD

--------------------------------------------------+
 PKGBUILD                                         |   20 ++-
 molecule-plugins-23.4.1-molecule_internals.patch |  118 +++++++++++++++++++++
 2 files changed, 134 insertions(+), 4 deletions(-)

Modified: PKGBUILD
===================================================================
--- PKGBUILD    2023-05-10 09:11:48 UTC (rev 1459742)
+++ PKGBUILD    2023-05-10 09:22:39 UTC (rev 1459743)
@@ -2,7 +2,7 @@
 
 pkgname=molecule-plugins
 pkgver=23.4.1
-pkgrel=2
+pkgrel=3
 pkgdesc="Collection of molecule plugins"
 arch=(any)
 url="https://github.com/ansible-community/molecule-plugins";
@@ -54,10 +54,22 @@
   molecule-podman
   molecule-vagrant
 )
-source=(https://files.pythonhosted.org/packages/source/${pkgname::1}/$pkgname/$pkgname-$pkgver.tar.gz)
-sha512sums=('5c158e278318402006f9f86f4143dac27d0cf6e95912963414e9c06720f9b5572240a6b6ddaccbd2872bb594144215a4a5ec434f4414e692fb72a3d97de175d3')
-b2sums=('e0261d189e55b0705ff2e967620146dd6ef0bc4182a6e87d5ffdaf8e1298dc0bc9e9bb188669300b63cf692f822ad6b0d4c8038fc1cff6afbf7f79b61dfbc184')
+source=(
+  
https://files.pythonhosted.org/packages/source/${pkgname::1}/$pkgname/$pkgname-$pkgver.tar.gz
+  $pkgname-23.4.1-molecule_internals.patch
+)
+sha512sums=('5c158e278318402006f9f86f4143dac27d0cf6e95912963414e9c06720f9b5572240a6b6ddaccbd2872bb594144215a4a5ec434f4414e692fb72a3d97de175d3'
+            
'11822fbd65ba7ccc796e454c015fe765a811e82bd89dc0727201cd45495907df3f808be967d73f45473c073816f9db5c072f32dbcab807229d7c7cf82de9101c')
+b2sums=('e0261d189e55b0705ff2e967620146dd6ef0bc4182a6e87d5ffdaf8e1298dc0bc9e9bb188669300b63cf692f822ad6b0d4c8038fc1cff6afbf7f79b61dfbc184'
+        
'62bb11057e5c429229a033ca8911b836817c456270077469decf608c9c9927c425e1c647a54f5370b4cabb644cfb0a1e44e0166b6a4f21912ce4e430f6b56a8f')
 
+prepare() {
+  # fix issues with vagrant plugin using molecule internals that are now gone:
+  # https://github.com/ansible-community/molecule-plugins/pull/142
+  # https://bugs.archlinux.org/task/78447
+  patch -Np1 -d $pkgname-$pkgver -i ../$pkgname-23.4.1-molecule_internals.patch
+}
+
 build() {
   cd $pkgname-$pkgver
   python -m build --wheel --no-isolation

Added: molecule-plugins-23.4.1-molecule_internals.patch
===================================================================
--- molecule-plugins-23.4.1-molecule_internals.patch                            
(rev 0)
+++ molecule-plugins-23.4.1-molecule_internals.patch    2023-05-10 09:22:39 UTC 
(rev 1459743)
@@ -0,0 +1,118 @@
+From 6ee55c7b7a9e556fc18bbc14144b8ca1ee7be845 Mon Sep 17 00:00:00 2001
+From: Arnaud Patard <[email protected]>
+Date: Thu, 27 Apr 2023 18:13:56 +0200
+Subject: [PATCH] src/molecule_plugins/vagrant/modules/vagrant.py: Get rid of
+ molecule dependency
+
+To avoid changes in molecule.util breaking the vagrant module, let's
+get rid of the dependency by:
+- embedded the recursive dict merge function
+- replace template handling by our own code.
+  (and keep the autoescaping enabled)
+
+Moreover, it will make it easier to use community.vagrant since molecule
+is not needed anymore.
+
+Signed-off-by: Arnaud Patard <[email protected]>
+---
+ .../vagrant/modules/vagrant.py                | 41 +++++++++++++++----
+ 1 file changed, 33 insertions(+), 8 deletions(-)
+
+diff --git a/src/molecule_plugins/vagrant/modules/vagrant.py 
b/src/molecule_plugins/vagrant/modules/vagrant.py
+index 8232695..b8cb11f 100644
+--- a/src/molecule_plugins/vagrant/modules/vagrant.py
++++ b/src/molecule_plugins/vagrant/modules/vagrant.py
+@@ -22,16 +22,16 @@
+ 
+ 
+ import contextlib
++import copy
+ import datetime
+ import os
+ import subprocess
+ import sys
++from collections.abc import MutableMapping
+ 
++import jinja2
+ from ansible.module_utils.basic import AnsibleModule
+ 
+-import molecule
+-import molecule.util
+-
+ try:
+     import vagrant
+ except ImportError:
+@@ -199,6 +199,8 @@
+   {%- endfor -%}
+ {%- endmacro -%}
+ 
++# Ansible managed
++
+ Vagrant.configure('2') do |config|
+   if Vagrant.has_plugin?('vagrant-cachier')
+     {% if cachier is not none and cachier in [ "machine", "box" ] %}
+@@ -335,6 +337,27 @@
+ """
+ 
+ 
++# Taken from molecule.util.
++def merge_dicts(a: MutableMapping, b: MutableMapping) -> MutableMapping:
++    """Merge the values of b into a and returns a new dict.
++
++    This function uses the same algorithm as Ansible's 
`combine(recursive=True)` filter.
++
++    :param a: the target dictionary
++    :param b: the dictionary to import
++    :return: dict
++    """
++    result = copy.deepcopy(a)
++
++    for k, v in b.items():
++        if k in a and isinstance(a[k], dict) and isinstance(v, dict):
++            result[k] = merge_dicts(a[k], v)
++        else:
++            result[k] = v
++
++    return result
++
++
+ class VagrantClient:
+     def __init__(self, module) -> None:
+         self._module = module
+@@ -548,13 +571,15 @@ def _get_config(self):
+ 
+     def _write_vagrantfile(self):
+         instances = self._get_vagrant_config_dict()
+-        template = molecule.util.render_template(
+-            VAGRANTFILE_TEMPLATE,
++        j_env = jinja2.Environment(autoescape=True)
++        t = j_env.from_string(VAGRANTFILE_TEMPLATE)
++        template = t.render(
+             instances=instances,
+             cachier=self.cachier,
+             no_kvm=not os.path.exists("/dev/kvm"),
+         )
+-        molecule.util.write_file(self._vagrantfile, template)
++        with open(self._vagrantfile, "w") as f:
++            f.write(template)
+ 
+     def _write_configs(self):
+         self._write_vagrantfile()
+@@ -628,7 +653,7 @@ def _get_instance_vagrant_config_dict(self, instance):
+         }
+ 
+         d["config_options"].update(
+-            molecule.util.merge_dicts(
++            merge_dicts(
+                 d["config_options"],
+                 instance.get("config_options", {}),
+             ),
+@@ -640,7 +665,7 @@ def _get_instance_vagrant_config_dict(self, instance):
+             )
+ 
+         d["provider_options"].update(
+-            molecule.util.merge_dicts(
++            merge_dicts(
+                 d["provider_options"],
+                 instance.get("provider_options", {}),
+             ),

Reply via email to