Closed RonnyPfannschmidt closed 8 years ago
Quite busy these days, maybe @FRidh has an idea. Otherwise I'll peek at it in following days.
I don't use Tox myself but I guess TOX_TESTENV_PASSENV
should help you.
http://tox.readthedocs.io/en/latest/config.html?highlight=tox_testenv_passenv
Right now PYTHONPATH
contains the paths to all installed dependencies, which includes tox
and thus py
. I suppose passing to TOX_TESTENV_PASSENV
a PYTHONPATH
should do the trick?
In this case I pass the current PYTHONPATH
TOX_TESTENV_PASSENV="PYTHONPATH" tox
and that seems to work. I guess though it would be better if PYTHONPATH
was unset so it would install py
it self, but it doesn't seem to do that.
and I was using nix-shell
with nix-shell -p python27Packages.tox python35Packages.python
.
shouldnt tox in nix be updated to do that then?
i can verify that the TOX_TESTENV_PASSENV="PYTHONPATH"
works
but in normal tox usage thats not how it should go
If we think this approach is general enough and should work for basically all cases, then yes. Like I said, I never use tox myself so I am not sure whether this is a good approach or not. We can at least document it (see also #7368).
after taking a look at the wrapper, im reasonably certain tox should not passenv the pythonpath since it makes new virtualenvs that should just work
my understanding is, that tox in nix breaks because pip invocations will see tox pythonpath instead of the real virtualenv pythonpath
as far as i can tell this is impossible to fix without changing completely how nix composes the pythonpath
however a tox bugfix can be done, namely applying passenv to pip invocations
@RonnyPfannschmidt you asked whether it is possible to create Python envs without setting PYTHONPATH
, but e.g. using pth
files. We used to have that until https://github.com/NixOS/nixpkgs/pull/11086/, if I remember correctly, with the recursivePthLoader
.
The recursivePthLoader [1] iterates over sys.path and adds directories specified in the pth files to the end of PYTHONPATH
. It's actually still there, only being used in virtualenv
, although I don't see just yet how it is used there.
virtualenv
does seem to work correctly with regards to pip
. When I create a virtualenv it installs pip 7.1.2 and is being used. I think this is the behaviour we also want for tox
, to use the pip
that is installed in the virtualenv.
but the pythonpath exposed by the tox executable in nix pushed a pylib install into the pip invocation but then the test call (where tox does more isolation) suddenly those packages are not there, thus the builds break
the basci issue is, that pythonpath is a rather bad mechanism to transfer python packages as per system pacakges, and pth files generated work better
wheels are bascially just pythons variant of .nar
tht doe get unpacked into a python site package folder
when usign them in nix, nix should ensure that the executable scripts and the python path gets constructed in a non-obstrusive manner (i.e. without smearing into the environment variables)
ok, a writedown of what happens and why the interaction tox<>virtualenv breaks on nix
in order to properly fix, the tox script, should instead of being a shell wrapper, use python, add directly to site and not touch the environment
also all "python executable" packages that do not invoke sub-processes should probably do the same
I think this is an issue for upstream. Why doesn't tox isolate PYTHONPATH
?
because on a normal system that is not necessary per se but it certainly shows an issue with nix as well, a virtuelanv created by nix should be immune forwards invocation by a nix based command
virtualenv and tox don't isolate PYTHONPATH
. How is this Nix fault? :)
nix creates a wrapper that changes it ^^
Nix exposes libraries to python via PYTHONPATH
so tox can actually import packages. This is 101 how Python works. Nothing magic or unexpected. This is really an issue for upstream.
the basic implication is, that any nix installed python tool that invokes things in my path can break them in case of virtualenv unless all python tools use environment isolation in all cases
also this implies that if a python3 tool invokes a python2 tool we can get funny effects unless all tools learn very specific isolation thats based on how nix splits and constructs python installations
Issue description
when running the nix-os shipped tox on one of my packages, it breaks
Steps to reproduce
clone https://github.com/RonnyPfannschmidt/sentaku get tox run tox on the project
Technical details
the missing py package is a python dependency of the pytest package