Last active
March 20, 2023 22:20
-
-
Save tsibley/ffb6469067b1cf8976be227d52548749 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # usage: pypreload <code> <cmd> [<arg> [<arg> […]]] | |
| # | |
| # See <https://docs.python.org/3/library/site.html> for how the "sitecustomize" | |
| # module works. | |
| # | |
| set -euo pipefail | |
| code="$1" | |
| shift | |
| tmplib="$(mktemp -dt "$(basename "$0")"-XXXXXX)" | |
| cat > "$tmplib/sitecustomize.py" <<~~ | |
| # written by $0 to run: $* | |
| $code | |
| # remove ourselves from consideration | |
| import sys, os.path | |
| del sys.modules["sitecustomize"] | |
| sys.path.remove(os.path.dirname(__file__)) | |
| # import any sitecustomize we masked | |
| import sitecustomize | |
| ~~ | |
| PYTHONPATH="$tmplib${PYTHONPATH:+:}${PYTHONPATH:-}" | |
| export PYTHONPATH | |
| exec "$@" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/tsibley/PY_PRELOAD