Repository navigation
Python: add sitecustomize.py, listen to NIX_PYTHONPATH - #64634
Conversation
|
This is a really neat idea - I've been doing something similar in a much hackier way to get virtualenvs to work with less hassle - simply using Moving towards preferring |
|
I don't follow you. This does not use |
abbradar
left a comment
There was a problem hiding this comment.
Additionally, this commit introduces
NIX_PYTHON_SCRIPT_NAMEwhich
can be used for settingsys.argv[0].
Not in the commit, a rebasing mistake?
I needed to read on the previous discussions since I have completely forgotten what's the problem we are trying to solve :D
It's better than using PYTHONHOME. I like the idea of unsetting the variable; if we apply it to NIX_PYTHON_SCRIPT_NAME won't this solve its leakiness? I don't see any other problems with it, maybe I missed anything in #25985?
We still don't solve crazy cases like (5) from #25985 (comment) but that's a clear improvement.
|
And if we move to using them both in |
This commit adds a Nix-specific module that recursively adds paths that are on `NIX_PYTHONPATH` to `sys.path`. In order to process possible `.pth` files `site.addsitedir` is used. The paths listed in `PYTHONPATH` are added to `sys.path` afterwards, but they will be added before the entries we add here and thus take precedence. The reason for adding support for this environment variable is that we can set it in a wrapper without breaking support for `PYTHONPATH`.
I've updated the commit message. Yes, we could use |
|
@FRidh my point is just that users may have custom entries in their runtime environment's It's possible I've misunderstood how this is being handled with |
|
Ah, now I understand. No, this won't change. |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
Motivation for this change
Split from #25985.
Add a
sitecustomize.pyfile that listens toNIX_PYTHONPATHand unsets it afterwards. This gives the same feature as bothPYTHONHOMEandPYTHONPATH, however, without preventing the user from using those environment variables, and without leaking the variable.This variable is now used in
python.buildEnv, thereby solving issues with a leakingPYTHONHOMEwhich could break nested Python programs/environments.In the future we may choose to use this as well in
buildPythonPackage.Things done
sandboxinnix.confon non-NixOS)nix-shell -p nix-review --run "nix-review wip"./result/bin/)nix path-info -Sbefore and after)