mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-83180: Made launcher treat shebang 'python' tags as low priority so that active virtual environments are preferred (GH-108101)
This commit is contained in:
parent
6139bf5e0c
commit
1b3bc610fd
4 changed files with 71 additions and 12 deletions
|
@ -717,3 +717,25 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
|
|||
f"{expect} arg1 {script}",
|
||||
data["stdout"].strip(),
|
||||
)
|
||||
|
||||
def test_shebang_command_in_venv(self):
|
||||
stem = "python-that-is-not-on-path"
|
||||
|
||||
# First ensure that our test name doesn't exist, and the launcher does
|
||||
# not match any installed env
|
||||
with self.script(f'#! /usr/bin/env {stem} arg1') as script:
|
||||
data = self.run_py([script], expect_returncode=103)
|
||||
|
||||
with self.fake_venv() as (venv_exe, env):
|
||||
# Put a real Python (ourselves) on PATH as a distraction.
|
||||
# The active VIRTUAL_ENV should be preferred when the name isn't an
|
||||
# exact match.
|
||||
env["PATH"] = f"{Path(sys.executable).parent};{os.environ['PATH']}"
|
||||
|
||||
with self.script(f'#! /usr/bin/env {stem} arg1') as script:
|
||||
data = self.run_py([script], env=env)
|
||||
self.assertEqual(data["stdout"].strip(), f"{venv_exe} arg1 {script}")
|
||||
|
||||
with self.script(f'#! /usr/bin/env {Path(sys.executable).stem} arg1') as script:
|
||||
data = self.run_py([script], env=env)
|
||||
self.assertEqual(data["stdout"].strip(), f"{sys.executable} arg1 {script}")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue