mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-29 04:37:00 +00:00
replace /usr/local as a source of packages in the python relocatable interpreter
I was playing with the python3 interpreter trying to get pip to work,
just to see how far we can go. We don't really need pip, but I figured
it would be a good stress test to make sure that the process is working
and robust.
And it didn't really work, because although pip will correctly install
things into $relocatable_root/local/lib, sys.path will still refer to a
hardcoded /usr/local. While this should not affect Scylla, since we
expect to have all our modules in out path anyway -- and that path is
searched before /usr/local, it is still dangerous to make an absolute
reference like this.
Unfortunately, /usr/local/ it is included unconditionally by site.py,
which is executed when the interpreter is started and there is no
environment variable I found to change that (the help string refers to
PYTHONNOUSERSITE, but I found no mention of that in site.py whatsoever)
There is a way to tell site.py not to bother to add user sites, by
passing the -s flag, which this patch does.
Aside from doing that, we also enhance PYTHONPATH to include a reference
to ./local/{lib,lib64}/python<version>/site-packages.
After applying this patch, I was able to build an interpreter containing
only python3-pip and python3-setuptools, and build the relocatable
environment from there.
Signed-off-by: Glauber Costa <glauber@scylladb.com>
Message-Id: <20190206052104.25927-1-glauber@scylladb.com>
This commit is contained in:
committed by
Avi Kivity
parent
64b1a2caf9
commit
fb742473e2
@@ -102,16 +102,21 @@ def fix_dynload(ar, binpath, targetpath):
|
||||
ar.add(patched_binary, arcname=targetpath, recursive=False)
|
||||
|
||||
def gen_python_thunk(ar, pybin):
|
||||
thunk=b'''\
|
||||
base_thunk='''\
|
||||
#!/bin/bash
|
||||
x="$(readlink -f "$0")"
|
||||
b="$(basename "$x")"
|
||||
d="$(dirname "$x")/.."
|
||||
ldso="$d/libexec/ld.so"
|
||||
realexe="$d/libexec/$b.bin"
|
||||
exec -a "$0" "$ldso" "$realexe" "$@"
|
||||
PYTHONPATH="$d/{sitepackages}:$d/{sitepackages64}:$PYTHONPATH" exec -a "$0" "$ldso" "$realexe" -s "$@"
|
||||
'''
|
||||
|
||||
sitepackages = os.path.join("local/lib/", pybin, "site-packages")
|
||||
sitepackages64 = os.path.join("local/lib64/", pybin, "site-packages")
|
||||
|
||||
thunk = base_thunk.format(sitepackages=sitepackages, sitepackages64=sitepackages64).encode()
|
||||
|
||||
ti = tarfile.TarInfo(name=os.path.join("bin", pybin))
|
||||
ti.size = len(thunk)
|
||||
ti.mode = 0o755
|
||||
|
||||
Reference in New Issue
Block a user