Conversation
b2a32d9 to
45b4509
Compare
|
Also, see #358823. IMHO, "properly" fixing this issue is actually surprisingly hard, but I believe in you. You can do it! 😜 Otherwise, I might have to find some time to try fixing it myself))) |
|
I am not sure fix wrap-python-hook do work, i have not found any example python script that will behave different with optional sitePackages added. |
|
Well, i miss the deleted line “Python doesn't support |
|
Some packages (namely xonsh) really need the python-env's wrapper behavior (i.e. adding python-env's sitePackages to sys.path) independent of dontWrapPythonProgram and sys.argv[0]. |
|
Can you clarify, why xonsh "needs" this? It seems to me that both xonsh-related issues that I see mentioned here should work fine with as long as the prefixes, After all, |
|
xonsh set dontWrapPythonProgram=true; since wrap-python-hook will append path when wrapping xonsh, which xonsh does not want serving as a shell. By the meantime, xonsh need to be aware of it's python dependencies. This is done by bundle xonsh into the python-env, which set NIX_PYTHONPATH to python-env's sitePackages. In fact, we can't run nixpkgs#{python3Packages.xonsh}/bin/xonsh barely. If we add sitePackages "../${python.sitePackges}" relative to sys.argv[0] , xonsh will not work if we do not copy/ln sitePackages directory, see nixpkgs/pkgs/by-name/xo/xonsh/package.nix Lines 10 to 27 in ab0f360 If we replace python3Packages.xonsh}/bin/xonsh shebang with the actual python-env.interpreter, then xonsh will works fine. IMO, this is effectively the same as using NIX_PYTHONPATH. |
|
I guess there exisits binary (not a python script start with #!/nix/store/xxxxx-python/bin/python) that will benefit from NIX_PYTHONPATH when bundled into a python environment. So simply replace shengbang or adding sitePackges to sys.path in python scripts does not cover all the cases. |
|
I am switching to keep NIX_PYTHONPATH while replacing NIX_PYTHONPREFIX, NIX_PYTHONEXECUTABLE with --inherit-argv0 --resolve-argv0. I will open another pr later. |
My approch of using argv[0] does not work for xonsh, existing approch or replacing xonsh's shenbang with python-env's one will work fine. |
Hmmm. I wonder, are binary executables that 1) ship as part of a python package and 2) call into python themselves even a thing? I can't think of a single example right now. I think that for python packages, in 90% of cases, But if you think that binaries that call into python are common, then it's true that they might end up with a hard-coded path to the non-env version of the python binary. Although, it would be really helpful if you could come up with an example of such a binary (for testing). |
|
I guess netgen (Python3Packages.netgen-mesher) will be an example. |
|
@qbisi. Ah, I see. It seems that the |
|
migrating to #442540 |
Original pr: #297628
Related issue:
#326094 (comment)
In this pr, we wrap only the python executable with
--inherit-argv0 --resolve-argv0. We do dont modify other executable in python-env so there will be no hacky wrapping/unwrapping things of thouse python script. To make the wrapped python script aware of the symlink joined python-environment, we first pass argv[0] to wrapped python script via env variable NIX_PYTHONSCRIPT (for some reason Python doesn't support exec -a) then we derive python-env's sitePackages location from argv[0] and then add it to sys.path.Things done
--inherit-argv0 --resolve-argv0, do not modifiy other executable under bin.cc @MagicRB @ruro
Packages built
[x] pypy3
[ ] xonsh
Thing checked
passthru.tests.nixpkgs-reviewon this PR. See nixpkgs-review usage../result/bin/.Add a 👍 reaction to pull requests you find important.