Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a2ae81e

Browse files
authored
Merge pull request #13345 from Carreau/no-sys-path-append
Don't add ipython unconditionally to sys.path
2 parents b2c3261 + 96c5d75 commit a2ae81e

1 file changed

Lines changed: 29 additions & 15 deletions

File tree

IPython/core/application.py

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,17 @@ def _profile_changed(self, change):
185185
get_ipython_package_dir(), u'config', u'profile', change['new']
186186
)
187187

188+
add_ipython_dir_to_sys_path = Bool(
189+
False,
190+
"""Should the IPython profile directory be added to sys path ?
191+
192+
This option was non-existing before IPython 8.0, and ipython_dir was added to
193+
sys path to allow import of extensions present there. This was historical
194+
baggage from when pip did not exist. This now default to false,
195+
but can be set to true for legacy reasons.
196+
""",
197+
).tag(config=True)
198+
188199
ipython_dir = Unicode(
189200
help="""
190201
The name of the IPython directory. This directory is used for logging
@@ -284,21 +295,24 @@ def _ipython_dir_changed(self, change):
284295
str_old = os.path.abspath(old)
285296
if str_old in sys.path:
286297
sys.path.remove(str_old)
287-
str_path = os.path.abspath(new)
288-
sys.path.append(str_path)
289-
ensure_dir_exists(new)
290-
readme = os.path.join(new, 'README')
291-
readme_src = os.path.join(get_ipython_package_dir(), u'config', u'profile', 'README')
292-
if not os.path.exists(readme) and os.path.exists(readme_src):
293-
shutil.copy(readme_src, readme)
294-
for d in ('extensions', 'nbextensions'):
295-
path = os.path.join(new, d)
296-
try:
297-
ensure_dir_exists(path)
298-
except OSError as e:
299-
# this will not be EEXIST
300-
self.log.error("couldn't create path %s: %s", path, e)
301-
self.log.debug("IPYTHONDIR set to: %s" % new)
298+
if self.add_ipython_dir_to_sys_path:
299+
str_path = os.path.abspath(new)
300+
sys.path.append(str_path)
301+
ensure_dir_exists(new)
302+
readme = os.path.join(new, "README")
303+
readme_src = os.path.join(
304+
get_ipython_package_dir(), "config", "profile", "README"
305+
)
306+
if not os.path.exists(readme) and os.path.exists(readme_src):
307+
shutil.copy(readme_src, readme)
308+
for d in ("extensions", "nbextensions"):
309+
path = os.path.join(new, d)
310+
try:
311+
ensure_dir_exists(path)
312+
except OSError as e:
313+
# this will not be EEXIST
314+
self.log.error("couldn't create path %s: %s", path, e)
315+
self.log.debug("IPYTHONDIR set to: %s" % new)
302316

303317
def load_config_file(self, suppress_errors=IPYTHON_SUPPRESS_CONFIG_ERRORS):
304318
"""Load the config file.

0 commit comments

Comments
 (0)