[jenkins-ci PATCH 4/5] guests: Make PYTHONPATH dynamic

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Instead of having to specify this separately for every
guest due to minor differences in the environment, figure
it out at login time by asking Python itself for the
information we need.

Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx>
---
 guests/group_vars/all/main.yml                    |  1 -
 guests/host_vars/libvirt-centos-6/main.yml        |  2 --
 guests/host_vars/libvirt-centos-7/main.yml        |  2 --
 guests/host_vars/libvirt-debian-8/main.yml        |  2 --
 guests/host_vars/libvirt-debian-9/main.yml        |  2 --
 guests/host_vars/libvirt-debian-sid/main.yml      |  2 --
 guests/host_vars/libvirt-fedora-27/main.yml       |  2 --
 guests/host_vars/libvirt-fedora-28/main.yml       |  2 --
 guests/host_vars/libvirt-fedora-rawhide/main.yml  |  2 --
 guests/host_vars/libvirt-freebsd-10/main.yml      |  2 --
 guests/host_vars/libvirt-freebsd-11/main.yml      |  2 --
 guests/host_vars/libvirt-freebsd-current/main.yml |  2 --
 guests/host_vars/libvirt-ubuntu-14/main.yml       |  2 --
 guests/host_vars/libvirt-ubuntu-16/main.yml       |  2 --
 guests/host_vars/libvirt-ubuntu-18/main.yml       |  2 --
 guests/templates/bashrc.j2                        | 10 +++++++++-
 16 files changed, 9 insertions(+), 30 deletions(-)

diff --git a/guests/group_vars/all/main.yml b/guests/group_vars/all/main.yml
index 840c80b..2641c33 100644
--- a/guests/group_vars/all/main.yml
+++ b/guests/group_vars/all/main.yml
@@ -16,4 +16,3 @@ PKG_CONFIG_PATH: $VIRT_PREFIX/lib/pkgconfig
 XDG_DATA_DIRS: $VIRT_PREFIX/share:/usr/share:/usr/local/share
 GI_TYPELIB_PATH: $VIRT_PREFIX/lib/girepository-1.0
 OSINFO_SYSTEM_DIR: $VIRT_PREFIX/share/osinfo
-PYTHONPATH:
diff --git a/guests/host_vars/libvirt-centos-6/main.yml b/guests/host_vars/libvirt-centos-6/main.yml
index c27c1ad..265c622 100644
--- a/guests/host_vars/libvirt-centos-6/main.yml
+++ b/guests/host_vars/libvirt-centos-6/main.yml
@@ -1,5 +1,3 @@
 ---
-PYTHONPATH: $VIRT_PREFIX/lib64/python2.6/site-packages
-
 projects:
   - libvirt+website
diff --git a/guests/host_vars/libvirt-centos-7/main.yml b/guests/host_vars/libvirt-centos-7/main.yml
index 6cb8995..c147830 100644
--- a/guests/host_vars/libvirt-centos-7/main.yml
+++ b/guests/host_vars/libvirt-centos-7/main.yml
@@ -1,6 +1,4 @@
 ---
-PYTHONPATH: $VIRT_PREFIX/lib64/python2.7/site-packages
-
 projects:
   - libosinfo
   - libvirt
diff --git a/guests/host_vars/libvirt-debian-8/main.yml b/guests/host_vars/libvirt-debian-8/main.yml
index 64f3255..954a037 100644
--- a/guests/host_vars/libvirt-debian-8/main.yml
+++ b/guests/host_vars/libvirt-debian-8/main.yml
@@ -1,6 +1,4 @@
 ---
-PYTHONPATH: $VIRT_PREFIX/lib/python3.4/site-packages
-
 projects:
   - libosinfo
   - libvirt
diff --git a/guests/host_vars/libvirt-debian-9/main.yml b/guests/host_vars/libvirt-debian-9/main.yml
index 04d5132..a588c09 100644
--- a/guests/host_vars/libvirt-debian-9/main.yml
+++ b/guests/host_vars/libvirt-debian-9/main.yml
@@ -1,6 +1,4 @@
 ---
-PYTHONPATH: $VIRT_PREFIX/lib/python3.5/site-packages
-
 projects:
   - libosinfo
   - libvirt
diff --git a/guests/host_vars/libvirt-debian-sid/main.yml b/guests/host_vars/libvirt-debian-sid/main.yml
index cbf57aa..a588c09 100644
--- a/guests/host_vars/libvirt-debian-sid/main.yml
+++ b/guests/host_vars/libvirt-debian-sid/main.yml
@@ -1,6 +1,4 @@
 ---
-PYTHONPATH: $VIRT_PREFIX/lib/python3.6/site-packages
-
 projects:
   - libosinfo
   - libvirt
diff --git a/guests/host_vars/libvirt-fedora-27/main.yml b/guests/host_vars/libvirt-fedora-27/main.yml
index 9ed392b..00b0848 100644
--- a/guests/host_vars/libvirt-fedora-27/main.yml
+++ b/guests/host_vars/libvirt-fedora-27/main.yml
@@ -1,6 +1,4 @@
 ---
-PYTHONPATH: $VIRT_PREFIX/lib64/python3.6/site-packages
-
 projects:
   - libosinfo
   - libvirt
diff --git a/guests/host_vars/libvirt-fedora-28/main.yml b/guests/host_vars/libvirt-fedora-28/main.yml
index 9ed392b..00b0848 100644
--- a/guests/host_vars/libvirt-fedora-28/main.yml
+++ b/guests/host_vars/libvirt-fedora-28/main.yml
@@ -1,6 +1,4 @@
 ---
-PYTHONPATH: $VIRT_PREFIX/lib64/python3.6/site-packages
-
 projects:
   - libosinfo
   - libvirt
diff --git a/guests/host_vars/libvirt-fedora-rawhide/main.yml b/guests/host_vars/libvirt-fedora-rawhide/main.yml
index 91b4158..5044594 100644
--- a/guests/host_vars/libvirt-fedora-rawhide/main.yml
+++ b/guests/host_vars/libvirt-fedora-rawhide/main.yml
@@ -1,6 +1,4 @@
 ---
-PYTHONPATH: $VIRT_PREFIX/lib64/python3.6/site-packages
-
 projects:
   - libosinfo
   - libosinfo+mingw
diff --git a/guests/host_vars/libvirt-freebsd-10/main.yml b/guests/host_vars/libvirt-freebsd-10/main.yml
index e37c845..2ad4584 100644
--- a/guests/host_vars/libvirt-freebsd-10/main.yml
+++ b/guests/host_vars/libvirt-freebsd-10/main.yml
@@ -1,8 +1,6 @@
 ---
 ansible_python_interpreter: /usr/local/bin/python2
 
-PYTHONPATH: $VIRT_PREFIX/lib/python3.6/site-packages
-
 projects:
   - libosinfo
   - libvirt
diff --git a/guests/host_vars/libvirt-freebsd-11/main.yml b/guests/host_vars/libvirt-freebsd-11/main.yml
index e37c845..2ad4584 100644
--- a/guests/host_vars/libvirt-freebsd-11/main.yml
+++ b/guests/host_vars/libvirt-freebsd-11/main.yml
@@ -1,8 +1,6 @@
 ---
 ansible_python_interpreter: /usr/local/bin/python2
 
-PYTHONPATH: $VIRT_PREFIX/lib/python3.6/site-packages
-
 projects:
   - libosinfo
   - libvirt
diff --git a/guests/host_vars/libvirt-freebsd-current/main.yml b/guests/host_vars/libvirt-freebsd-current/main.yml
index e37c845..2ad4584 100644
--- a/guests/host_vars/libvirt-freebsd-current/main.yml
+++ b/guests/host_vars/libvirt-freebsd-current/main.yml
@@ -1,8 +1,6 @@
 ---
 ansible_python_interpreter: /usr/local/bin/python2
 
-PYTHONPATH: $VIRT_PREFIX/lib/python3.6/site-packages
-
 projects:
   - libosinfo
   - libvirt
diff --git a/guests/host_vars/libvirt-ubuntu-14/main.yml b/guests/host_vars/libvirt-ubuntu-14/main.yml
index bfbdda6..839c668 100644
--- a/guests/host_vars/libvirt-ubuntu-14/main.yml
+++ b/guests/host_vars/libvirt-ubuntu-14/main.yml
@@ -1,6 +1,4 @@
 ---
-PYTHONPATH: $VIRT_PREFIX/lib/python3.4/site-packages
-
 projects:
   - libosinfo
   - libvirt
diff --git a/guests/host_vars/libvirt-ubuntu-16/main.yml b/guests/host_vars/libvirt-ubuntu-16/main.yml
index 04d5132..a588c09 100644
--- a/guests/host_vars/libvirt-ubuntu-16/main.yml
+++ b/guests/host_vars/libvirt-ubuntu-16/main.yml
@@ -1,6 +1,4 @@
 ---
-PYTHONPATH: $VIRT_PREFIX/lib/python3.5/site-packages
-
 projects:
   - libosinfo
   - libvirt
diff --git a/guests/host_vars/libvirt-ubuntu-18/main.yml b/guests/host_vars/libvirt-ubuntu-18/main.yml
index cbf57aa..a588c09 100644
--- a/guests/host_vars/libvirt-ubuntu-18/main.yml
+++ b/guests/host_vars/libvirt-ubuntu-18/main.yml
@@ -1,6 +1,4 @@
 ---
-PYTHONPATH: $VIRT_PREFIX/lib/python3.6/site-packages
-
 projects:
   - libosinfo
   - libvirt
diff --git a/guests/templates/bashrc.j2 b/guests/templates/bashrc.j2
index cf2679e..a4183ff 100644
--- a/guests/templates/bashrc.j2
+++ b/guests/templates/bashrc.j2
@@ -8,7 +8,6 @@ export PKG_CONFIG_PATH="{{ PKG_CONFIG_PATH }}"
 export XDG_DATA_DIRS="{{ XDG_DATA_DIRS }}"
 export GI_TYPELIB_PATH="{{ GI_TYPELIB_PATH }}"
 export OSINFO_SYSTEM_DIR="{{ OSINFO_SYSTEM_DIR }}"
-export PYTHONPATH="{{ PYTHONPATH }}"
 
 export MAKE="{{ make }}"
 export PYTHON="{{ python }}"
@@ -18,6 +17,15 @@ export PYTHON="{{ python }}"
 plarch=$(perl -e 'use Config; print $Config{archname}')
 export PERL5LIB="$VIRT_PREFIX/lib/perl5/$plarch"
 
+# For Python we need the version number (major and minor) and
+# to know whether "lib64" paths are searched
+pylib=lib
+if $PYTHON -c 'import sys; print("\n".join(sys.path))' | grep -q lib64; then
+    pylib=lib64
+fi
+pyver=$($PYTHON -c 'import sys; print(".".join(map(lambda x: str(sys.version_info[x]), [0,1])))')
+export PYTHONPATH="$VIRT_PREFIX/$pylib/python$pyver/site-packages"
+
 # Enable bash completion. Only needed on FreeBSD, the system-wide
 # shell profile will take care of it for us everywhere else
 bash_completion=/usr/local/share/bash-completion/bash_completion.sh
-- 
2.17.0

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



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux