pip-tools: Fix test failures for Python 3.8-3.10 #189810
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of changes
Fixes test failures for
python38Packages.pip-tools
,python39Packages.pip-tools
, andpython310Packages.pip-tools
.For Python 3.8/3.9: changed the current fix of patching up
scripts/compile.py
to ignoreStopIteration
to ignoring thetest_bad_setup_file
test case.Diagnosis
The
StopIteration
exception was coming from this line in thebuild
package, which looks for packages namedpip
inpurelib
:https://github.com/pypa/build/blob/0.8.0/src/build/env.py#L272
By inserting a line that raises an exception with the result of running
find {purelib}
, I saw thatpurelib
was empty when I tried to buildpython39Packages.pip-tools
...while it had a bunch of stuff with
python310Packages.pip-tools
pip
is supposed to be installed by thevenv
module if you invokevenv.EnvBuilder
withwith_pip=True
, whichbuild
does on this line:https://github.com/pypa/build/blob/0.8.0/src/build/env.py#L265
So why isn't
pip
installed in the virtualenv?Printing the output of the call to
ensurepip
from withinvenv
showed that, in the context ofpytest
runs duringnix-build
, it thought requirements were already satisfied:This behavior differs in Python 3.10 (or more precisely, 3.10.6) because it includes a fix for ensurepip's bug where the 'isolated' flag of the Python process wasn't propagated.
Outside of nix-build, even for Python 3.8/3.9, running
pip-compile
in a directory that emulates the test casetest_bad_setup_file
(echo "BAD SYNTAX" > setup.py
) doesn't result in aStopIteration
... I guess because, whilePYTHONPATH
gets set up to point tosite-packages
directories ofpropagatedBuildInputs
, once the package is built,PYTHONPATH
is left clean..? The output of the call toensurepip
when running./result/bin/pip-compile
shows thatsetuptools
andpip
do get installed, as expected:In any case, given that this
StopIteration
exception only happens during testing and it's something that will be fixed upstream once theensurepip
bug fix lands in Python 3.8/3.9, I thought it better to avoid patching pip-compile's source code and ignore the test case instead.For Python 3.10: Patched the
test_bad_setup_file
test case to provide a--find-links
directory that contains a .whl file of thewheel
package.Diagnosis
Even with the 'empty virtualenv' issue above fixed, the test was still failing for Python 3.10.
Looking at the details of the exception revealed that the
build
package was trying to installwheel
but wasn't able to do so because we don't allow network access during builds.I couldn't pin-point exactly when it started happening to be the case, but the
wheel
package is no longer installed by default in virtualenvs created byvenv
.Confirmed that, with the fix in place, what seems to be the expected exception is raised
Patched
build.ProjectBuilder._handle_backend
to raise the caught exception and saw that it'sSyntaxError
, which sounds like what you'd expect if you try to evaluate asetup.py
that only contains the string "BAD SYNTAX".I didn't attempt to fix the build for Python 3.7, as the build error seemed to stem from a circular dependency that I wasn't sure how to fix:
^Seems to require adding importlib-metadata to setuptools-scm's build inputs, but importlib-metadata already depends on setuptools-scm.
Things done
sandbox = true
set innix.conf
? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)nixos/doc/manual/md-to-db.sh
to update generated release notes