Skip to content

Commit 0408497

Browse files
committed
fix: only delete first sys.path entry in the stage-2 bootstrap iff PYTHONSAFEPATH is unset or unsupported
1 parent d5a595c commit 0408497

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

python/private/stage2_bootstrap_template.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44

55
import sys
66

7-
# The Python interpreter unconditionally prepends the directory containing this
7+
# By default the Python interpreter prepends the directory containing this
88
# script (following symlinks) to the import path. This is the cause of #9239,
9-
# and is a special case of #7091. We therefore explicitly delete that entry.
10-
# TODO(#7091): Remove this hack when no longer necessary.
11-
# TODO: Use sys.flags.safe_path to determine whether this removal should be
12-
# performed
13-
del sys.path[0]
9+
# and is a special case of #7091.
10+
#
11+
# Python 3.11 introduced an PYTHONSAFEPATH (-P) option that disables this
12+
# behaviour, which we set in the stage 1 bootstrap.
13+
# So the prepended entry needs to be removed only if the above option is either
14+
# unset or not supported by the interpreter.
15+
# TODO(#7091): Remove this hack when we drop support for Python 3.10 and below
16+
if not getattr(sys.flags, "safe_path", False):
17+
del sys.path[0]
1418

1519
import contextlib
1620
import os

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy