From: Mathieu Duponchelle Date: Fri, 19 Jan 2018 20:04:09 +0000 (+0100) Subject: gst-uninstalled: make override hacks work in virtualenv X-Git-Tag: 1.19.3~481^2~342 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a484ed4124123dd7f2d5d7877e4b527ac07e4992;p=platform%2Fupstream%2Fgstreamer.git gst-uninstalled: make override hacks work in virtualenv virtualenv ships its own version of site.py, which does not expose a getusersitepackages function. An alternative method is thus used when we detect that we are running in a virtualenv. --- diff --git a/gst-uninstalled.py b/gst-uninstalled.py index 2853def..07832d7 100755 --- a/gst-uninstalled.py +++ b/gst-uninstalled.py @@ -11,6 +11,8 @@ import subprocess import sys import tempfile +from distutils.sysconfig import get_python_lib + from common import get_meson SCRIPTDIR = os.path.dirname(os.path.realpath(__file__)) @@ -137,6 +139,10 @@ def get_subprocess_env(options): return env +# https://stackoverflow.com/questions/1871549/determine-if-python-is-running-inside-virtualenv +def in_venv(): + return (hasattr(sys, 'real_prefix') or + (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix)) def python_env(options, unset_env=False): """ @@ -150,7 +156,11 @@ def python_env(options, unset_env=False): not os.path.exists(gst_python_path): return False - sitepackages = site.getusersitepackages() + if in_venv (): + sitepackages = get_python_lib() + else: + sitepackages = site.getusersitepackages() + if not sitepackages: return False