Fix environments not being reused due to wrong Python lookup#428
Merged
cjolowicz merged 4 commits intowntrblm:mainfrom May 24, 2021
Merged
Fix environments not being reused due to wrong Python lookup#428cjolowicz merged 4 commits intowntrblm:mainfrom
cjolowicz merged 4 commits intowntrblm:mainfrom
Conversation
When determining the Python base installation of an existing environment, allow `nox.command.run` to find the Python executable in the virtualenv, by passing `VirtualEnv.bin_paths` as the `paths` argument. The original PR passed `os.path.join(self.location, "bin", "python")`. This does not work for two reasons: - The directory is named "Scripts" on Windows. - The executable is named "python.exe" on Windows. The follow-up PR passed bare "python". This does not work, because `nox.command.run` searches PATH by default. It needs to be told to search the virtualenv instead.
This test results in an error 'No pyvenv.cfg file' on the Windows 2019 runner:
[...]
File "D:\a\nox\nox\tests\test_virtualenv.py", line 438, in test_create_reuse_oldstyle_virtualenv_environment
reused = not venv.create()
File "d:\a\nox\nox\nox\virtualenv.py", line 420, in create
if not self._clean_location():
File "d:\a\nox\nox\nox\virtualenv.py", line 313, in _clean_location
and self._check_reused_environment_interpreter()
File "d:\a\nox\nox\nox\virtualenv.py", line 342, in _check_reused_environment_interpreter
["python", "-c", program], silent=True, log=False, paths=self.bin_paths
File "d:\a\nox\nox\nox\command.py", line 118, in run
full_cmd, return_code, ":" if silent else ""
Message: "Command python -c import sys; print(getattr(sys, 'real_prefix', sys.base_prefix)) failed with exit code 106:"
Arguments: ()
No pyvenv.cfg file
------------------------------ Captured log call ------------------------------
INFO nox:virtualenv.py:440 Creating virtual environment (virtualenv) using python.exe in D:\a\nox\nox\.nox\tests-3-7\tmp\pytest-of-runneradmin\pytest-0\test_create_reuse_oldstyle_vir0\venv
ERROR nox:command.py:118 Command python -c import sys; print(getattr(sys, 'real_prefix', sys.base_prefix)) failed with exit code 106:
The error message appears to come from the Windows Python launcher (see
cpython/PC/launcher.c).
The test places a spurious occurrence of "virtualenv" in the pyvenv.cfg file, to
check for robust parsing. This was done by modifying the `home` key to point to
a fictitious installation at /opt/virtualenv/bin.
Unfortunately, this leads to the following error on Windows when determining the
Python base installation:
No Python at '/opt/virtualenv/bin\python.exe'
Avoid this error by using an entirely bogus key, which should be ignored by
Python and other tools:
bogus = virtualenv
theacodes
approved these changes
May 24, 2021
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Follow-up to #418 and #425
This PR contains two changes to the staleness check when reusing environments:
1. Fix environments not being reused due to wrong Python lookup
When determining the Python base installation of an existing environment, allow
nox.command.runto find the Python executable in the virtualenv, by passingVirtualEnv.bin_pathsas thepathsargument.The original PR (#418) passed
os.path.join(self.location, "bin", "python"). This does not work for two reasons:The follow-up PR (#425) passed bare "python". This does not work, because
nox.command.runsearchesPATHby default. It needs to be told to search the virtualenv instead.This fix exposed portability flaws in the test suite on Windows. Some tests messed with the
pyvenv.cfgfiles, which confused the Windows Python launcher. We solve this by skipping one non-essential test on Windows, and by preserving the originalpyvenv.cfgkeys in another test.2. Don't log interpreter checks when reusing environments
This gets rid of some clutter in the Nox output. Here's an example for such clutter: