Skip to content

Commit d9aa216

Browse files
uranusjrvsajip
authored andcommitted
bpo-38927: Use python -m pip to upgrade venv deps (GH-17403)
I suggest you add `bpo-NNNNN: ` as a prefix for the first commit for future PRs. Thanks!
1 parent 045d4e2 commit d9aa216

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

Lib/test/test_venv.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,18 @@ def test_prompt(self):
141141
def test_upgrade_dependencies(self):
142142
builder = venv.EnvBuilder()
143143
bin_path = 'Scripts' if sys.platform == 'win32' else 'bin'
144-
pip_exe = 'pip.exe' if sys.platform == 'win32' else 'pip'
144+
python_exe = 'python.exe' if sys.platform == 'win32' else 'python'
145145
with tempfile.TemporaryDirectory() as fake_env_dir:
146146

147147
def pip_cmd_checker(cmd):
148148
self.assertEqual(
149149
cmd,
150150
[
151-
os.path.join(fake_env_dir, bin_path, pip_exe),
151+
os.path.join(fake_env_dir, bin_path, python_exe),
152+
'-m',
153+
'pip',
152154
'install',
153-
'-U',
155+
'--upgrade',
154156
'pip',
155157
'setuptools'
156158
]

Lib/venv/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,10 @@ def upgrade_dependencies(self, context):
393393
f'Upgrading {CORE_VENV_DEPS} packages in {context.bin_path}'
394394
)
395395
if sys.platform == 'win32':
396-
pip_exe = os.path.join(context.bin_path, 'pip.exe')
396+
python_exe = os.path.join(context.bin_path, 'python.exe')
397397
else:
398-
pip_exe = os.path.join(context.bin_path, 'pip')
399-
cmd = [pip_exe, 'install', '-U']
398+
python_exe = os.path.join(context.bin_path, 'python')
399+
cmd = [python_exe, '-m', 'pip', 'install', '--upgrade']
400400
cmd.extend(CORE_VENV_DEPS)
401401
subprocess.check_call(cmd)
402402

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use ``python -m pip`` instead of ``pip`` to upgrade dependencies in venv.

0 commit comments

Comments
 (0)