Skip to content
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

GH-87915: create a venv executable with the same name as sys.executable #129495

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Lib/test/test_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,17 @@ def test_venvwlauncher(self):
except subprocess.CalledProcessError:
self.fail("venvwlauncher.exe did not run %s" % exename)

def test_ensure_sys_executable_name(self):
"""
Test that we create a executable with the same name as sys.executable.
"""
rmtree(self.env_dir)
executable_dir = os.path.dirname(sys.executable)
with patch('sys.executable', os.path.join(executable_dir, 'some-custom-name')):
venv.create(self.env_dir)
scripts_dir = os.path.join(self.env_dir, self.bindir)
self.assertIn('some-custom-name', os.listdir(scripts_dir))


@requireVenvCreate
class EnsurePipTest(BaseTest):
Expand Down
13 changes: 11 additions & 2 deletions Lib/venv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,14 @@ def setup_python(self, context):
if not os.path.islink(path):
os.chmod(path, 0o755)

suffixes = ['python', 'python3', f'python3.{sys.version_info[1]}']
suffixes = {
'python',
'python3',
f'python3.{sys.version_info[1]}',
os.path.basename(sys.executable),
}
if sys.version_info[:2] == (3, 14):
suffixes.append('𝜋thon')
suffixes.add('𝜋thon')
for suffix in suffixes:
path = os.path.join(binpath, suffix)
if not os.path.exists(path):
Expand Down Expand Up @@ -388,6 +393,10 @@ def setup_python(self, context):
f'pythonw{exe_t}{exe_d}.exe': pythonw_exe,
}

for sources_dict in (link_sources, copy_sources):
if exename not in sources_dict:
sources_dict[exename] = python_exe

do_copies = True
if self.symlinks:
do_copies = False
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
We now make sure :mod:`venv` creates an executable with the same name as
:data:`sys.executable` in environments.
Loading