does anybody have any experience using `sitecustom...
# pex
f
does anybody have any experience using
sitecustomize
hooks with pex? Specifically my prod team wants to use datadog's
ddtrace-run
hook, which seems to just inject their
sitecustomize
hook at the front of
PYTHONPATH
and then uses
os.execl
to swap for the new python process
e
That hook looks like this console script?: https://github.com/DataDog/dd-trace-py/blob/master/setup.py#L166
If so it looks like that script just manipulates PYTHONPATH. The key pex option then - since PEX files are hermetic by default is --inherit-path / PEX_INHERIT_PATH
You'd want to set that to prefer or fallback so the Pex runtime doesn't scrub it.
f
Yeah I saw that but I like pex scrubbing the import path... I want to know if I can build a pex with this sitecustomize hook in it
My concern is I never want what's in the environment to override what's in the pex, because I could see that leading to weird unexpected subtle bugs that I have no desire to track down
e
OK - in that case we're likely back to https://github.com/pantsbuild/pex/issues/987 The ddtrace-run script is a "delegator" app as described in that issue. Alternatively, there may be some way to use the ddtrace API to write a custom entrypoint to include in the PEX as source code and then activate via -e.
f
i think ddtrace-run looks like a main-delegator, but its main purpose is like you said just to manipulate PYTHONPATH and then replace itself with the process you want running. The real magic happens in
sitecustomize
which is loaded by the
site
module before the main.py shim. If there's a way i could inject a sitecustomize into the pex, and ensure it gets loaded before main, i think this could work without involving some kind of main-delegator