Skip to content

Commit bb8b2ba

Browse files
committed
Modify init_path to include safe_path check
Update init_path so that if sys.flags.safe_path is set, it will not include the current working directory. sys.flags.safe_path is python's equivalent to of the ipython flag ignore_cwd. It is most often set by PYTHONSAFEPATH or by running python with -P.
1 parent 0a64e76 commit bb8b2ba

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

IPython/core/shellapp.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ def _user_ns_changed(self, change):
247247
def init_path(self):
248248
"""Add current working directory, '', to sys.path
249249
250+
Unless disabled by ignore_cwd config or sys.flags.safe_path.
251+
250252
Unlike Python's default, we insert before the first `site-packages`
251253
or `dist-packages` directory,
252254
so that it is after the standard library.
@@ -255,8 +257,10 @@ def init_path(self):
255257
Try to insert after the standard library, instead of first.
256258
.. versionchanged:: 8.0
257259
Allow optionally not including the current directory in sys.path
260+
.. versionchanged:: X.X
261+
Respect sys.flags.safe_path (PYTHONSAFEPATH and -P flag)
258262
"""
259-
if '' in sys.path or self.ignore_cwd:
263+
if '' in sys.path or self.ignore_cwd or sys.flags.safe_path:
260264
return
261265
for idx, path in enumerate(sys.path):
262266
parent, last_part = os.path.split(path)

0 commit comments

Comments
 (0)