| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -159,7 +159,7 @@ def test_upgrade_dependencies(self): | |||
| 159 | 159 | if sys.platform == 'win32': | |
| 160 | 160 | expect_exe = os.path.normcase(os.path.realpath(expect_exe)) | |
| 161 | 161 | ||
| 162 | - def pip_cmd_checker(cmd): | ||
| 162 | + def pip_cmd_checker(cmd, **kwargs): | ||
| 163 | 163 | cmd[0] = os.path.normcase(cmd[0]) | |
| 164 | 164 | self.assertEqual( | |
| 165 | 165 | cmd, | |
@@ -175,7 +175,7 @@ def pip_cmd_checker(cmd): | |||
| 175 | 175 | ) | |
| 176 | 176 | ||
| 177 | 177 | fake_context = builder.ensure_directories(fake_env_dir) | |
| 178 | - with patch('venv.subprocess.check_call', pip_cmd_checker): | ||
| 178 | + with patch('venv.subprocess.check_output', pip_cmd_checker): | ||
| 179 | 179 | builder.upgrade_dependencies(fake_context) | |
| 180 | 180 | ||
| 181 | 181 | @requireVenvCreate | |
@@ -547,8 +547,8 @@ def nicer_error(self): | |||
| 547 | 547 | try: | |
| 548 | 548 | yield | |
| 549 | 549 | except subprocess.CalledProcessError as exc: | |
| 550 | - out = exc.output.decode(errors="replace") | ||
| 551 | - err = exc.stderr.decode(errors="replace") | ||
| 550 | + out = (exc.output or b'').decode(errors="replace") | ||
| 551 | + err = (exc.stderr or b'').decode(errors="replace") | ||
| 552 | 552 | self.fail( | |
| 553 | 553 | f"{exc}\n\n" | |
| 554 | 554 | f"**Subprocess Output**\n{out}\n\n" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -308,14 +308,25 @@ def setup_python(self, context): | |||
| 308 | 308 | shutil.copyfile(src, dst) | |
| 309 | 309 | break | |
| 310 | 310 | ||
| 311 | + def _call_new_python(self, context, *py_args, **kwargs): | ||
| 312 | + """Executes the newly created Python using safe-ish options""" | ||
| 313 | + # gh-98251: We do not want to just use '-I' because that masks | ||
| 314 | + # legitimate user preferences (such as not writing bytecode). All we | ||
| 315 | + # really need is to ensure that the path variables do not overrule | ||
| 316 | + # normal venv handling. | ||
| 317 | + args = [context.env_exec_cmd, *py_args] | ||
| 318 | + kwargs['env'] = env = os.environ.copy() | ||
| 319 | + env['VIRTUAL_ENV'] = context.env_dir | ||
| 320 | + env.pop('PYTHONHOME', None) | ||
| 321 | + env.pop('PYTHONPATH', None) | ||
| 322 | + kwargs['cwd'] = context.env_dir | ||
| 323 | + kwargs['executable'] = context.env_exec_cmd | ||
| 324 | + subprocess.check_output(args, **kwargs) | ||
| 325 | + | ||
| 311 | 326 | def _setup_pip(self, context): | |
| 312 | 327 | """Installs or upgrades pip in a virtual environment""" | |
| 313 | - # We run ensurepip in isolated mode to avoid side effects from | ||
| 314 | - # environment vars, the current directory and anything else | ||
| 315 | - # intended for the global Python environment | ||
| 316 | - cmd = [context.env_exec_cmd, '-Im', 'ensurepip', '--upgrade', | ||
| 317 | - '--default-pip'] | ||
| 318 | - subprocess.check_output(cmd, stderr=subprocess.STDOUT) | ||
| 328 | + self._call_new_python(context, '-m', 'ensurepip', '--upgrade', | ||
| 329 | + '--default-pip', stderr=subprocess.STDOUT) | ||
| 319 | 330 | ||
| 320 | 331 | def setup_scripts(self, context): | |
| 321 | 332 | """ | |
@@ -414,9 +425,8 @@ def upgrade_dependencies(self, context): | |||
| 414 | 425 | logger.debug( | |
| 415 | 426 | f'Upgrading {CORE_VENV_DEPS} packages in {context.bin_path}' | |
| 416 | 427 | ) | |
| 417 | - cmd = [context.env_exec_cmd, '-m', 'pip', 'install', '--upgrade'] | ||
| 418 | - cmd.extend(CORE_VENV_DEPS) | ||
| 419 | - subprocess.check_call(cmd) | ||
| 428 | + self._call_new_python(context, '-m', 'pip', 'install', '--upgrade', | ||
| 429 | + *CORE_VENV_DEPS) | ||
| 420 | 430 | ||
| 421 | 431 | ||
| 422 | 432 | def create(env_dir, system_site_packages=False, clear=False, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Allow :mod:`venv` to pass along :envvar:`PYTHON*` variables to ``ensurepip`` and ``pip`` when | ||
| 2 | + they do not impact path resolution | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments