| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -216,7 +216,7 @@ def test_upgrade_dependencies(self): | |||
| 216 | 216 | if sys.platform == 'win32': | |
| 217 | 217 | expect_exe = os.path.normcase(os.path.realpath(expect_exe)) | |
| 218 | 218 | ||
| 219 | - def pip_cmd_checker(cmd): | ||
| 219 | + def pip_cmd_checker(cmd, **kwargs): | ||
| 220 | 220 | cmd[0] = os.path.normcase(cmd[0]) | |
| 221 | 221 | self.assertEqual( | |
| 222 | 222 | cmd, | |
@@ -232,7 +232,7 @@ def pip_cmd_checker(cmd): | |||
| 232 | 232 | ) | |
| 233 | 233 | ||
| 234 | 234 | fake_context = builder.ensure_directories(fake_env_dir) | |
| 235 | - with patch('venv.subprocess.check_call', pip_cmd_checker): | ||
| 235 | + with patch('venv.subprocess.check_output', pip_cmd_checker): | ||
| 236 | 236 | builder.upgrade_dependencies(fake_context) | |
| 237 | 237 | ||
| 238 | 238 | @requireVenvCreate | |
@@ -659,8 +659,8 @@ def nicer_error(self): | |||
| 659 | 659 | try: | |
| 660 | 660 | yield | |
| 661 | 661 | except subprocess.CalledProcessError as exc: | |
| 662 | - out = exc.output.decode(errors="replace") | ||
| 663 | - err = exc.stderr.decode(errors="replace") | ||
| 662 | + out = (exc.output or b'').decode(errors="replace") | ||
| 663 | + err = (exc.stderr or b'').decode(errors="replace") | ||
| 664 | 664 | self.fail( | |
| 665 | 665 | f"{exc}\n\n" | |
| 666 | 666 | f"**Subprocess Output**\n{out}\n\n" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -339,14 +339,25 @@ def setup_python(self, context): | |||
| 339 | 339 | shutil.copyfile(src, dst) | |
| 340 | 340 | break | |
| 341 | 341 | ||
| 342 | + def _call_new_python(self, context, *py_args, **kwargs): | ||
| 343 | + """Executes the newly created Python using safe-ish options""" | ||
| 344 | + # gh-98251: We do not want to just use '-I' because that masks | ||
| 345 | + # legitimate user preferences (such as not writing bytecode). All we | ||
| 346 | + # really need is to ensure that the path variables do not overrule | ||
| 347 | + # normal venv handling. | ||
| 348 | + args = [context.env_exec_cmd, *py_args] | ||
| 349 | + kwargs['env'] = env = os.environ.copy() | ||
| 350 | + env['VIRTUAL_ENV'] = context.env_dir | ||
| 351 | + env.pop('PYTHONHOME', None) | ||
| 352 | + env.pop('PYTHONPATH', None) | ||
| 353 | + kwargs['cwd'] = context.env_dir | ||
| 354 | + kwargs['executable'] = context.env_exec_cmd | ||
| 355 | + subprocess.check_output(args, **kwargs) | ||
| 356 | + | ||
| 342 | 357 | def _setup_pip(self, context): | |
| 343 | 358 | """Installs or upgrades pip in a virtual environment""" | |
| 344 | - # We run ensurepip in isolated mode to avoid side effects from | ||
| 345 | - # environment vars, the current directory and anything else | ||
| 346 | - # intended for the global Python environment | ||
| 347 | - cmd = [context.env_exec_cmd, '-Im', 'ensurepip', '--upgrade', | ||
| 348 | - '--default-pip'] | ||
| 349 | - subprocess.check_output(cmd, stderr=subprocess.STDOUT) | ||
| 359 | + self._call_new_python(context, '-m', 'ensurepip', '--upgrade', | ||
| 360 | + '--default-pip', stderr=subprocess.STDOUT) | ||
| 350 | 361 | ||
| 351 | 362 | def setup_scripts(self, context): | |
| 352 | 363 | """ | |
@@ -445,9 +456,8 @@ def upgrade_dependencies(self, context): | |||
| 445 | 456 | logger.debug( | |
| 446 | 457 | f'Upgrading {CORE_VENV_DEPS} packages in {context.bin_path}' | |
| 447 | 458 | ) | |
| 448 | - cmd = [context.env_exec_cmd, '-m', 'pip', 'install', '--upgrade'] | ||
| 449 | - cmd.extend(CORE_VENV_DEPS) | ||
| 450 | - subprocess.check_call(cmd) | ||
| 459 | + self._call_new_python(context, '-m', 'pip', 'install', '--upgrade', | ||
| 460 | + *CORE_VENV_DEPS) | ||
| 451 | 461 | ||
| 452 | 462 | ||
| 453 | 463 | 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