-
-
Notifications
You must be signed in to change notification settings - Fork 309
Fix identification of venv interpreters. #3114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5281032
Add a failing test.
jsirois ca57834
Fix identification of venv interpreters.
jsirois 6bdf99c
Prepare a release.
jsirois 00888cb
Cleanup commented out code and fix impl.
jsirois 3371074
Don't pretend INTERP-INFO atomic dir handling is general.
jsirois File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| # Copyright 2015 Pex project contributors. | ||
| # Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
|
||
| __version__ = "2.91.0" | ||
| __version__ = "2.91.1" |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| # Copyright 2026 Pex project contributors. | ||
| # Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
|
||
| from __future__ import absolute_import | ||
|
|
||
| import glob | ||
| import os.path | ||
| import shutil | ||
| import subprocess | ||
| from typing import Tuple | ||
|
|
||
| import pytest | ||
|
|
||
| from pex.common import safe_delete | ||
| from pex.util import CacheHelper | ||
| from testing import ( | ||
| IS_LINUX_X86_64, | ||
| PyenvPythonDistribution, | ||
| ensure_python_distribution, | ||
| make_env, | ||
| run_pex_command, | ||
| ) | ||
| from testing.pytest_utils.tmp import Tempdir | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def cowsay(tmpdir): | ||
| # type: (Tempdir) -> str | ||
|
|
||
| pex_root = tmpdir.join("pex-root") | ||
| cowsay = tmpdir.join("cowsay.pex") | ||
| run_pex_command( | ||
| args=[ | ||
| "--pex-root", | ||
| pex_root, | ||
| "--runtime-pex-root", | ||
| pex_root, | ||
| "cowsay<6", | ||
| "-c", | ||
| "cowsay", | ||
| "-o", | ||
| cowsay, | ||
| ] | ||
| ).assert_success() | ||
| return cowsay | ||
|
|
||
|
|
||
| def pypy_dist( | ||
| pyenv_version, # type: str | ||
| python_version, # type: Tuple[int, int, int] | ||
| ): | ||
| # type: (...) -> PyenvPythonDistribution | ||
| pypy_distribution = ensure_python_distribution( | ||
| pyenv_version, | ||
| python_version="{major}.{minor}".format(major=python_version[0], minor=python_version[1]), | ||
| allow_adhoc_version=True, | ||
| ) | ||
| assert ( | ||
| "{major}.{minor}.{patch}".format( | ||
| major=python_version[0], minor=python_version[1], patch=python_version[2] | ||
| ) | ||
| == subprocess.check_output( | ||
| args=[ | ||
| pypy_distribution.binary, | ||
| "-c", | ||
| "import sys; print('.'.join(map(str, sys.version_info[:3])))", | ||
| ] | ||
| ) | ||
| .decode("utf-8") | ||
| .strip() | ||
| ) | ||
| return pypy_distribution | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def pypy3_11_11_dist(): | ||
| # type: () -> PyenvPythonDistribution | ||
| return pypy_dist("pypy3.11-7.3.19", python_version=(3, 11, 11)) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def pypy3_11_13_dist(): | ||
| # type: () -> PyenvPythonDistribution | ||
| return pypy_dist("pypy3.11-7.3.20", python_version=(3, 11, 13)) | ||
|
|
||
|
|
||
| @pytest.mark.skipif( | ||
| not IS_LINUX_X86_64, | ||
| reason=( | ||
| "We only need to test this for one known-good pair of interpreters with matching binary " | ||
| "hash and differing patch versions. The pypy3.11-7.3.19 / pypy3.11-7.3.20 pair is known to " | ||
| "meet this criteria for x86_64 Linux." | ||
| ), | ||
| ) | ||
| def test_interpreter_upgrade_same_binary_hash( | ||
| tmpdir, # type: Tempdir | ||
| cowsay, # type: str | ||
| pypy3_11_11_dist, # type: PyenvPythonDistribution | ||
| pypy3_11_13_dist, # type: PyenvPythonDistribution | ||
| ): | ||
| # type: (...) -> None | ||
|
|
||
| assert pypy3_11_11_dist.binary != pypy3_11_13_dist.binary | ||
| assert CacheHelper.hash(pypy3_11_11_dist.binary) == CacheHelper.hash(pypy3_11_13_dist.binary) | ||
|
|
||
| pypy_311_prefix = tmpdir.join("opt", "pypy") | ||
|
|
||
| def install_pypy_311_and_create_venv( | ||
| pypy_distribution, # type: PyenvPythonDistribution | ||
| venv_dir, # type: str | ||
| ): | ||
| # type: (...) -> str | ||
|
|
||
| if os.path.exists(pypy_311_prefix): | ||
| shutil.move(pypy_311_prefix, pypy_311_prefix + ".sav") | ||
| shutil.copytree(pypy_distribution.interpreter.prefix, pypy_311_prefix) | ||
| for binary in glob.glob(os.path.join(pypy_311_prefix, "bin", "*")): | ||
| if os.path.basename(binary) not in ("libpypy3.11-c.so", "pypy3.11"): | ||
| safe_delete(binary) | ||
| pypy_binary = os.path.join(pypy_311_prefix, "bin", "pypy3.11") | ||
| venv_path = tmpdir.join(venv_dir) | ||
| subprocess.check_call(args=[pypy_binary, "-m", "venv", venv_path]) | ||
| return os.path.join(venv_path, "bin", "python") | ||
|
|
||
| pypy3_11_11_venv_binary = install_pypy_311_and_create_venv(pypy3_11_11_dist, "pypy3_11_11.venv") | ||
| assert b"| I am 3.11.11 |" in subprocess.check_output( | ||
| args=[pypy3_11_11_venv_binary, cowsay, "I am 3.11.11"], | ||
| env=make_env(PEX_PYTHON_PATH=pypy3_11_11_venv_binary), | ||
| ) | ||
|
|
||
| pypy3_11_13_venv_binary = install_pypy_311_and_create_venv(pypy3_11_13_dist, "pypy3_11_13.venv") | ||
| assert b"| I am 3.11.13 |" in subprocess.check_output( | ||
| args=[pypy3_11_13_venv_binary, cowsay, "I am 3.11.13"], | ||
| env=make_env(PEX_PYTHON_PATH=pypy3_11_13_venv_binary), | ||
| ) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prior to the fix this fails with:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cburroughs this test was pretty titchy to get right (both a single re-used install path is required as well as a limited interpreter search path), but it faithfully reproduces your original test case (besides using pre-compiled PyPy interpreters) AFAICT.