PhysicalWM / PSIVG /run /sitecustomize.py
Ravenveil's picture
backup 05_psivg 2026-11-08 10:26:02 (part 7)
0f934c2 verified
Raw History Blame Contribute Delete
1.26 kB
"""sitecustomize: neutralize the broken /tmp/six.py (left by another user in
the shared /tmp). It shadows the real six package. Python auto-imports
`sitecustomize` at startup; we simply preload the REAL six from site-packages
and pin it in sys.modules so /tmp/six.py is never consulted.
"""
import importlib.util
import site
def _load_real_six():
candidates = list(site.getsitepackages()) + [site.getusersitepackages()]
for sp in candidates:
if not sp:
continue
p = sp.rstrip("/") + "/six.py"
try:
with open(p, "r", encoding="utf-8") as f:
if "with_metaclass" not in f.read():
continue
except OSError:
continue
spec = importlib.util.spec_from_file_location("six", p)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
import sys
sys.modules["six"] = mod
return True
return False
try:
import sys
already_ok = False
try:
import six # noqa
already_ok = "with_metaclass" in dir(six) or hasattr(six, "with_metaclass")
except ImportError:
already_ok = False
if not already_ok:
_load_real_six()
except Exception:
pass