Repository navigation
wrapPythonProgram: use site.addsitedir instead of PYTHONPATH - #17749
Conversation
|
@abbradar I think the problem you describe is basically #11423. @garbas, you proposed this solution as well, right? |
|
@FRidh I think the problem is somewhat different. The problem that is described there IIUC is that when you put a derivation into |
|
Therefore I think we shouldn't set/prefix Anyway, until then I think I am fine with this change as I don't add anything to |
|
Oh, I got it now -- yes, it would help. BTW this patch can be a small preparation step -- if anything relies on prefixing EDIT: after more thoughts -- nah, it wouldn't, only a sub-case of people setting |
|
On second thought, while I don't set or append/prepend to |
|
i consider usage of we should never allow to extend |
Agreed. And therefore we should solve the root of the problem: stop using
We can add an option to Edit: Maybe we should, in general, use wrappers only in environments and not inside derivations that build packages. cc @bennofs |
|
This LGTM and would fix some issues I've had. Agreed that a better solution would be nice. |
|
for me this is a quick improvement over currently (for me) broken way how we handle python binaries. i got bitten by this bug many times and in all my projects i've been using this PR wont fix everything in python but it for sure will make python stuff more reproducible across machines. i would like to merge this, but i would also like some comments on this subject from @domenkozar and @bennofs |
|
100% agree with this patch. I didn't know it used People can still use PYTHONPATH, they just can't mix it with nix-built packages. I think this is similar to how we handle LD_LIBRARY_PATH, that also is not really supported for nix built packages (we don't override it, but I think there were some weird interactions). |
|
also another thing. is this triggering a mass-rebuild? i think we could easily apply this directly to master. yes quite few packages will need to be rebuilt but nothing than hydra can not handle. @domenkozar you thoughts on this? |
|
I don't see a reason from top of my head where |
|
I think this breaks because (Note that I anyway think we should replace this kind of usage with |
|
invoking edit: that's because in the I think we need to separate building and installing into two derivations, with the wheel a |
|
Hm, I'll try to test this more extensively and see what happens (I haven't built anything big with this because of lack of CPU time. I don't even remember what exactly, I think maybe |
|
EDIT: there's also nosetests... seems like really the question is, is whatever executable that's being run meant to interact with a python environment, or is it just meant to be a self-contained executable? |
|
Hm, indeed, IPython is a special case. I'm now trying an alternative patch which removes all meddling with |
|
We could also skip using local -a wrap_args=("$f"
--set PYTHONHOME ':' "$program_PYTHONPATH"
--prefix PATH ':' "$program_PATH:$dir/bin")I haven't tested this out yet but it seems perhaps promising? |
|
@adnelson and now you've broken Unless we're willing to use PYTHONPATH with |
|
I thought that |
|
@FRidh I haven't broken anything yet 😉 I didn't realize that's what |
|
BTW to clarify my thoughts towards @FRidh proposition: I like it much more than the current situation, and I think we probably should go there in the long run. However, I experience a broken browser when called from my IM client right now and I suspect that there are more breakages like this in the wild. |
|
I actually think that using PYTHONHOME is not such a bad idea: you could establish the convention that PYTHONHOME is to be used for the "application-dependencies", i.e. things that for example ipython itself depends on. The PYTHONPATH would be used to add any additional dependencies then, like plugins etc. |
|
So couldn't we point Something (conceptually, cuz I have no idea) along the lines of mkDerivation {
postInstall = ''
for bin_file in $out/bin; do
makeWrapper $bin_file \
--set PYTHONHOME ${buildEnv {paths = propagatedBuildInputs;}}
'';
} |
|
@adnelson and what is that derivation? It cannot be the actual package, it has to be outside of that or it wouldn't be a DAG. Here we're back to my suggestion of #16672. It's really easy actually, as you see in the implementation. And we could choose for now to keep @bennofs Do you mean adding to PYTHONPATH with Nix, or outside of Nix? |
|
Sadly I don't think so (this doesn't affect |
|
atm tox is broken because it puts packages from its environment into the virtualenvs at setup time and then isolates them away at the other level tox would work fine if it was not wrapped by the pythonpath thing |
|
This shouldn't be a problem already I think because there's no |
|
will this change hit 16-09 ?? - i just did a nix-env -i for tox and it has a wrapper |
|
It should have, a long time ago. |
|
i am on a 16.09 channel, just updated my channels and installed tox |
|
same for unstable channel |
So it's in master at least, and given that the change was merged long before |
|
@domenkozar any chance to see this in 16.09? |
|
@RonnyPfannschmidt As I've said it should be in 16.09 already but just to be sure I checked: |
|
@RonnyPfannschmidt does this fix the tox issue for you on master? @FRidh any reason not to backport this to 16.09? It's quote late for such big python change.. |
|
@domenkozar Again, this is already in 16.09 -- see also for example db31282 (notice |
is this perhaps an issue with the channel lagging behind the branch? |
|
Hm, I think you have an old |
|
|
This already does contain this change (notice absence of |
|
nm, i missed that detail on the 16.09 branch i get the same output - i was confused by the different output path the behaviour is indeed correct but thats something that can change in future as far as i can tell your change correctly and nicely fixes the 2 issues i posted |
|
oh, wait ,not completely tox is fixed, PYTHONPATH is still leaking into nix-shell |
|
Can you perhaps submit a PR for this? The workaround should be quite simple -- you need to add |
|
imho there should be a default decision on what nix python programs do wrt inheriting pythonpath users tend to use it, so its certainly valid - a tool in nix that does filter nix store paths out of env vars in wrappers might be whats helpfull |
|
|
|
@FRidh sounds perfect, i'd like to be free of nix-shell, from my POV its a tool for developing nix packages, not using them in develpment environments |
|
Currently we add the following to scripts and we also create a wrapper. I don't think we should do both. In case of Python code, we should add this code, and in the case of a non-Python program, we should create a wrapper. The wrappers can be problematic, e.g. when the program that is wrapped calls itself using I would like to make the following change:
Important is that |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
Motivation for this change
Consider two applications, "a" and "b". "a" uses Python 2.7 and enum34, which exports
enummodule. It calls "b" via exec, which uses Python 3.5. In this Python there's its ownenummodule, but it's overridden by enum34 because it's inPYTHONPATH. As a resultenummodule doesn't work and there are weird errors.Real life example:
gajimcallsqutebrowserto open an URL, which crashes instead.I don't know any better solution to this problem than the proposed patch. It looks good to me but it can potentially break some workflows which somehow rely on
PYTHONPATHpostfixes.Things done
(nix.useChroot on NixOS,
or option
build-use-chrootinnix.confon non-NixOS)
nix-shell -p nox --run "nox-review wip"./result/bin/)cc @domenkozar