From 72c43ce73fdb601e5e58b9cfc6ef87a706539bad Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Sat, 27 Oct 2018 17:59:29 +0200 Subject: [PATCH] uninstalled: build and set PYTHONPATH --- gst-uninstalled.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/gst-uninstalled.py b/gst-uninstalled.py index dfcf8b5..4871a7d 100755 --- a/gst-uninstalled.py +++ b/gst-uninstalled.py @@ -11,6 +11,7 @@ import shutil import subprocess import sys import tempfile +import pathlib from distutils.sysconfig import get_python_lib @@ -112,9 +113,29 @@ def get_subprocess_env(options, gst_version): presets = set() encoding_targets = set() pkg_dirs = set() + python_dirs = set() if '--installed' in subprocess.check_output(meson + ['introspect', '-h']).decode(): installed_s = subprocess.check_output(meson + ['introspect', options.builddir, '--installed']) for path, installpath in json.loads(installed_s.decode()).items(): + installpath_parts = pathlib.Path(installpath).parts + path_parts = pathlib.Path(path).parts + + # We want to add all python modules to the PYTHONPATH + # in a manner consistent with the way they would be imported: + # For example if the source path /home/meh/foo/bar.py + # is to be installed in /usr/lib/python/site-packages/foo/bar.py, + # we want to add /home/meh to the PYTHONPATH. + # This will only work for projects where the paths to be installed + # mirror the installed directory layout, for example if the path + # is /home/meh/baz/bar.py and the install path is + # /usr/lib/site-packages/foo/bar.py , we will not add anything + # to PYTHONPATH, but the current approach works with pygobject + # and gst-python at least. + if 'site-packages' in installpath_parts: + install_subpath = os.path.join(*installpath_parts[installpath_parts.index('site-packages') + 1:]) + if path.endswith(install_subpath): + python_dirs.add(path[:len (install_subpath) * -1]) + if path.endswith('.prs'): presets.add(os.path.dirname(path)) elif path.endswith('.gep'): @@ -139,6 +160,9 @@ def get_subprocess_env(options, gst_version): 'gst-plugins-good', 'pkgconfig')) + for python_dir in python_dirs: + prepend_env_var(env, 'PYTHONPATH', python_dir) + mesonpath = os.path.join(SCRIPTDIR, "meson") if os.path.join(mesonpath): # Add meson/ into PYTHONPATH if we are using a local meson -- 2.7.4