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

Skip to content

Commit cf7e3a3

Browse files
authored
Merge pull request #10266 from Carreau/ipython-ext-dir
Warn about IPython extension dir
2 parents ad8a59a + 477d997 commit cf7e3a3

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

IPython/core/extensions.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
# Distributed under the terms of the Modified BSD License.
66

77
import os
8+
import os.path
9+
import warnings
810
from shutil import copyfile
911
import sys
1012
from importlib import import_module
1113

1214
from traitlets.config.configurable import Configurable
13-
from IPython.utils.path import ensure_dir_exists
15+
from IPython.utils.path import ensure_dir_exists, compress_user
1416
from traitlets import Instance
1517

1618
try:
@@ -75,13 +77,18 @@ def load_extension(self, module_str):
7577
"""
7678
if module_str in self.loaded:
7779
return "already loaded"
78-
80+
7981
from IPython.utils.syspathcontext import prepended_to_syspath
80-
82+
8183
with self.shell.builtin_trap:
8284
if module_str not in sys.modules:
8385
with prepended_to_syspath(self.ipython_extension_dir):
84-
import_module(module_str)
86+
mod = import_module(module_str)
87+
if mod.__file__.startswith(self.ipython_extension_dir):
88+
print(("Loading extensions from {dir} is deprecated. "
89+
"We recommend managing extensions like any "
90+
"other Python packages, in site-packages.").format(
91+
dir=compress_user(self.ipython_extension_dir)))
8592
mod = sys.modules[module_str]
8693
if self._call_load_ipython_extension(mod):
8794
self.loaded.add(module_str)
@@ -168,3 +175,5 @@ def install_extension(self, url, filename=None):
168175
filename = os.path.join(self.ipython_extension_dir, filename)
169176
copy(url, filename)
170177
return filename
178+
179+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Loading extensions from ``ipython_extension_dir`` print a warning that this location is pending
2+
deprecation. This should only affect users still having extensions installed with ``%install_ext``
3+
which has been deprecated since IPython 4.0, and removed in 5.0. extensions still present in
4+
``ipython_extension_dir`` may shadow more recently installed versions using pip. It is thus
5+
recommended to clean ``ipython_extension_dir`` of any extension now available as a package.

0 commit comments

Comments
 (0)