[libvirt] [jenkins-ci PATCH 13/17] guests: Install meson via pip

Fabiano Fidêncio posted 17 patches 6 years, 4 months ago
There is a newer version of this series
[libvirt] [jenkins-ci PATCH 13/17] guests: Install meson via pip
Posted by Fabiano Fidêncio 6 years, 4 months ago
Let's install meson via pip whenever meson is not available at all or
does not match the minimum required version.

Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
---
 guests/lcitool                             | 13 +++++++++++++
 guests/playbooks/update/tasks/packages.yml |  8 ++++++++
 2 files changed, 21 insertions(+)

diff --git a/guests/lcitool b/guests/lcitool
index 5b5b622..6be396c 100755
--- a/guests/lcitool
+++ b/guests/lcitool
@@ -625,6 +625,11 @@ class Application:
         else:
             keys = base_keys + [self._native_arch + "-" + k for k in base_keys]
 
+        pip_install = []
+        pip_mappings = {
+            "meson" : "meson==0.49.0",
+        }
+
         # We need to add the base project manually here: the standard
         # machinery hides it because it's an implementation detail
         for project in projects + ["base"]:
@@ -644,6 +649,8 @@ class Application:
 
                 if package not in pkgs:
                     continue
+                if package in pip_mappings and pkgs[package] is None:
+                    pip_install += [pip_mappings[package]]
                 if cross_policy == "foreign" and pkgs[package] is not None:
                     cross_pkgs[package] = pkgs[package]
                 if pkgs[package] is None or cross_policy in ["skip", "foreign"]:
@@ -714,6 +721,12 @@ class Application:
                         {package_manager} clean all -y
                 """).format(**varmap))
 
+        if pip_install:
+            varmap["pip_install"] = " ".join(sorted(pip_install))
+            sys.stdout.write(textwrap.dedent("""
+                RUN pip3 install {pip_install}
+            """).format(**varmap))
+
     def run(self):
         args = self._parser.parse_args()
         if args.debug:
diff --git a/guests/playbooks/update/tasks/packages.yml b/guests/playbooks/update/tasks/packages.yml
index ec8a4c4..f2603f8 100644
--- a/guests/playbooks/update/tasks/packages.yml
+++ b/guests/playbooks/update/tasks/packages.yml
@@ -100,3 +100,11 @@
   package:
     name: '{{ flattened|sort }}'
     state: '{{ state }}'
+
+- name: '{{ project }}: Install meson from pip'
+  command: pip3 install meson==0.49.0
+  args:
+    creates: /usr/local/bin/meson
+  when:
+    - temp["meson"] is defined
+    - temp["meson"] == None
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [jenkins-ci PATCH 13/17] guests: Install meson via pip
Posted by Andrea Bolognani 6 years, 4 months ago
On Tue, 2019-10-01 at 16:28 +0200, Fabiano Fidêncio wrote:
> +++ b/guests/lcitool
> +        pip_install = []
> +        pip_mappings = {
> +            "meson" : "meson==0.49.0",
> +        }

This makes me think that perhaps we should have this information
encoded in the mapping, eg.

  meson:
    default: meson
    CentOS7: pip3(meson==0.49.0)

Of course then we'd be in the business of parsing that, which would
not be too bad in Python but probably a fair amount of pain in the
Ansible playbook...

Maybe a reasonable compromise would be to have something like

  pip_mappings:
    meson:
      default: meson==0.49.0

in addition to the existing mappings, and that use that information
as a fallback when a regular mapping is not available. Easier to
parse, even though it's less explicit about what's going on behind
the scenes, especially if you're only looking at the regular mapping.
On the other hand, it would avoid hardcoding the Meson installation
command in the Ansible playbook, which you're doing right now and is
a bit unsavory.

What do you think about the latter approach? It seems like it would
be fairly easy to implement and, while far from perfect, a slight
step up from what you currently have.

[...]
> +        if pip_install:
> +            varmap["pip_install"] = " ".join(sorted(pip_install))
> +            sys.stdout.write(textwrap.dedent("""
> +                RUN pip3 install {pip_install}
> +            """).format(**varmap))

It would be nice if we got the pip packages aligned nicely in the
output, same as the native packages, but that's not a blocker :)

> +++ b/guests/playbooks/update/tasks/packages.yml
> +- name: '{{ project }}: Install meson from pip'
> +  command: pip3 install meson==0.49.0
> +  args:
> +    creates: /usr/local/bin/meson
> +  when:
> +    - temp["meson"] is defined
> +    - temp["meson"] == None

Ansible has a pip module[1] which we should probably use for this;
on the other hand, from a quick look at the documentation I'm a bit
unclear on the implications when it comes to the version of pip that
would be invoked on each platform, so we can leave it be for now and
switch in a follow-up patch.


Incidentally, now that we are installing Python 3 on CentOS 7, we
should be able to set

  ansible_python_interpreter: /usr/bin/python3

in its host_vars. I haven't made sure that would actually work, but
it certainly would be nice to run everything on Python 3.


[1] https://docs.ansible.com/ansible/latest/modules/pip_module.html
-- 
Andrea Bolognani / Red Hat / Virtualization

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list