From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 5 Jul 2022 15:54:03 +0000 (-0700) Subject: gh-90355: Add isolated flag if currently isolated (GH-92857) (GH-94568) X-Git-Tag: v3.11.0b4~28 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9bd97a2a7e542aca2635cc53d74b286944653316;p=thirdparty%2FPython%2Fcpython.git gh-90355: Add isolated flag if currently isolated (GH-92857) (GH-94568) Co-authored-by: Carter Dodd Co-authored-by: Éric Co-authored-by: Łukasz Langa (cherry picked from commit c8556bcf6c0b05ac46bd74880626a2853e7c99a1) --- diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py index a198a86e1f9a..1f25825f3feb 100644 --- a/Lib/ensurepip/__init__.py +++ b/Lib/ensurepip/__init__.py @@ -89,8 +89,18 @@ sys.path = {additional_paths or []} + sys.path sys.argv[1:] = {args} runpy.run_module("pip", run_name="__main__", alter_sys=True) """ - return subprocess.run([sys.executable, '-W', 'ignore::DeprecationWarning', - "-c", code], check=True).returncode + + cmd = [ + sys.executable, + '-W', + 'ignore::DeprecationWarning', + '-c', + code, + ] + if sys.flags.isolated: + # run code in isolated mode if currently running isolated + cmd.insert(1, '-I') + return subprocess.run(cmd, check=True).returncode def version(): diff --git a/Misc/NEWS.d/next/Library/2022-01-03-15-07-06.bpo-46197.Z0djv6.rst b/Misc/NEWS.d/next/Library/2022-01-03-15-07-06.bpo-46197.Z0djv6.rst new file mode 100644 index 000000000000..7a3b2d59dfaf --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-01-03-15-07-06.bpo-46197.Z0djv6.rst @@ -0,0 +1 @@ +Fix :mod:`ensurepip` environment isolation for subprocess running ``pip``.