mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-03 14:08:56 +00:00
uninstalled: Simplify our python environment setup
Not changing the main usersitepackage env but creating our own, similarly to what a venv would do.
This commit is contained in:
parent
4ef0584295
commit
63e743def6
1 changed files with 11 additions and 43 deletions
|
@ -73,6 +73,7 @@ def get_subprocess_env(options):
|
||||||
prepend_env_var(env, "GI_TYPELIB_PATH", os.path.join(PREFIX_DIR, 'lib',
|
prepend_env_var(env, "GI_TYPELIB_PATH", os.path.join(PREFIX_DIR, 'lib',
|
||||||
'lib', 'girepository-1.0'))
|
'lib', 'girepository-1.0'))
|
||||||
prepend_env_var(env, "PKG_CONFIG_PATH", os.path.join(PREFIX_DIR, 'lib', 'pkgconfig'))
|
prepend_env_var(env, "PKG_CONFIG_PATH", os.path.join(PREFIX_DIR, 'lib', 'pkgconfig'))
|
||||||
|
setup_python_env(options, env)
|
||||||
|
|
||||||
meson = get_meson()
|
meson = get_meson()
|
||||||
targets_s = subprocess.check_output([sys.executable, meson, 'introspect', options.builddir, '--targets'])
|
targets_s = subprocess.check_output([sys.executable, meson, 'introspect', options.builddir, '--targets'])
|
||||||
|
@ -150,12 +151,7 @@ def in_venv():
|
||||||
return (hasattr(sys, 'real_prefix') or
|
return (hasattr(sys, 'real_prefix') or
|
||||||
(hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix))
|
(hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix))
|
||||||
|
|
||||||
def python_env(options, unset_env=False):
|
def setup_python_env(options, env):
|
||||||
"""
|
|
||||||
Setup our overrides_hack.py as sitecustomize.py script in user
|
|
||||||
site-packages if unset_env=False, else unset, previously set
|
|
||||||
env.
|
|
||||||
"""
|
|
||||||
subprojects_path = os.path.join(options.builddir, "subprojects")
|
subprojects_path = os.path.join(options.builddir, "subprojects")
|
||||||
gst_python_path = os.path.join(SCRIPTDIR, "subprojects", "gst-python")
|
gst_python_path = os.path.join(SCRIPTDIR, "subprojects", "gst-python")
|
||||||
if not os.path.exists(os.path.join(subprojects_path, "gst-python")) or \
|
if not os.path.exists(os.path.join(subprojects_path, "gst-python")) or \
|
||||||
|
@ -167,46 +163,22 @@ def python_env(options, unset_env=False):
|
||||||
else:
|
else:
|
||||||
sitepackages = site.getusersitepackages()
|
sitepackages = site.getusersitepackages()
|
||||||
|
|
||||||
if not sitepackages:
|
sitecustomize = os.path.join(
|
||||||
return False
|
subprocess.check_output([sys.executable, '-c', 'import site; print(site.USER_SITE)'],
|
||||||
|
env={"PYTHONUSERBASE": PREFIX_DIR}).decode().strip("\n"), "sitecustomize.py")
|
||||||
sitecustomize = os.path.join(sitepackages, "sitecustomize.py")
|
|
||||||
overrides_hack = os.path.join(gst_python_path, "testsuite", "overrides_hack.py")
|
overrides_hack = os.path.join(gst_python_path, "testsuite", "overrides_hack.py")
|
||||||
mesonconfig = os.path.join(gst_python_path, "testsuite", "mesonconfig.py")
|
mesonconfig = os.path.join(gst_python_path, "testsuite", "mesonconfig.py")
|
||||||
mesonconfig_link = os.path.join(sitepackages, "mesonconfig.py")
|
mesonconfig_link = os.path.join(sitepackages, "mesonconfig.py")
|
||||||
|
|
||||||
if not unset_env:
|
os.makedirs(os.path.dirname(sitecustomize), exist_ok=True)
|
||||||
if os.path.exists(sitecustomize):
|
with contextlib.suppress(FileExistsError):
|
||||||
if os.path.realpath(sitecustomize) == overrides_hack:
|
|
||||||
print("Customize user site script already linked to the GStreamer one")
|
|
||||||
return False
|
|
||||||
|
|
||||||
old_sitecustomize = os.path.join(sitepackages,
|
|
||||||
"old.sitecustomize.gstuninstalled.py")
|
|
||||||
shutil.move(sitecustomize, old_sitecustomize)
|
|
||||||
elif not os.path.exists(sitepackages):
|
|
||||||
os.makedirs(sitepackages)
|
|
||||||
|
|
||||||
with contextlib.suppress(FileNotFoundError):
|
|
||||||
os.remove(sitecustomize)
|
|
||||||
os.remove(mesonconfig_link)
|
|
||||||
os.symlink(overrides_hack, sitecustomize)
|
os.symlink(overrides_hack, sitecustomize)
|
||||||
|
with contextlib.suppress(FileExistsError):
|
||||||
os.symlink(mesonconfig, mesonconfig_link)
|
os.symlink(mesonconfig, mesonconfig_link)
|
||||||
return os.path.realpath(sitecustomize) == overrides_hack
|
|
||||||
else:
|
|
||||||
if not os.path.realpath(sitecustomize) == overrides_hack:
|
|
||||||
return False
|
|
||||||
|
|
||||||
os.remove(sitecustomize)
|
|
||||||
os.remove (mesonconfig_link)
|
|
||||||
old_sitecustomize = os.path.join(sitepackages,
|
|
||||||
"old.sitecustomize.gstuninstalled.py")
|
|
||||||
|
|
||||||
if os.path.exists(old_sitecustomize):
|
|
||||||
shutil.move(old_sitecustomize, sitecustomize)
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
env["PYTHONUSERBASE"] = PREFIX_DIR
|
||||||
|
if sitepackages:
|
||||||
|
prepend_env_var(env, "PYTHONPATH", sitepackages)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(prog="gstreamer-uninstalled")
|
parser = argparse.ArgumentParser(prog="gstreamer-uninstalled")
|
||||||
|
@ -248,12 +220,8 @@ if __name__ == "__main__":
|
||||||
# Let the GC remove the tmp file
|
# Let the GC remove the tmp file
|
||||||
args.append("--rcfile")
|
args.append("--rcfile")
|
||||||
args.append(tmprc.name)
|
args.append(tmprc.name)
|
||||||
python_set = python_env(options)
|
|
||||||
try:
|
try:
|
||||||
exit(subprocess.call(args, cwd=options.srcdir, close_fds=False,
|
exit(subprocess.call(args, cwd=options.srcdir, close_fds=False,
|
||||||
env=get_subprocess_env(options)))
|
env=get_subprocess_env(options)))
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
exit(e.returncode)
|
exit(e.returncode)
|
||||||
finally:
|
|
||||||
if python_set:
|
|
||||||
python_env(options, unset_env=True)
|
|
||||||
|
|
Loading…
Reference in a new issue