]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-90355: Add isolated flag if currently isolated (GH-92857) (GH-94569)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 5 Jul 2022 15:58:28 +0000 (08:58 -0700)
committerGitHub <noreply@github.com>
Tue, 5 Jul 2022 15:58:28 +0000 (17:58 +0200)
Co-authored-by: Carter Dodd <carter.dodd@gmail.com>
Co-authored-by: Éric <merwok@netwok.org>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit c8556bcf6c0b05ac46bd74880626a2853e7c99a1)

Lib/ensurepip/__init__.py
Misc/NEWS.d/next/Library/2022-01-03-15-07-06.bpo-46197.Z0djv6.rst [new file with mode: 0644]

index 3fbe8b2a5b13677cd3d28a69dbc531488a60b463..a82dbadce1635e9c20267fb8c932b65dbe295592 100644 (file)
@@ -90,8 +90,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 (file)
index 0000000..7a3b2d5
--- /dev/null
@@ -0,0 +1 @@
+Fix :mod:`ensurepip` environment isolation for subprocess running ``pip``.