|
5 | 5 | # Distributed under the terms of the Modified BSD License. |
6 | 6 |
|
7 | 7 | import os |
| 8 | +import os.path |
| 9 | +import warnings |
8 | 10 | from shutil import copyfile |
9 | 11 | import sys |
10 | 12 | from importlib import import_module |
11 | 13 |
|
12 | 14 | 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 |
14 | 16 | from traitlets import Instance |
15 | 17 |
|
16 | 18 | try: |
@@ -75,13 +77,18 @@ def load_extension(self, module_str): |
75 | 77 | """ |
76 | 78 | if module_str in self.loaded: |
77 | 79 | return "already loaded" |
78 | | - |
| 80 | + |
79 | 81 | from IPython.utils.syspathcontext import prepended_to_syspath |
80 | | - |
| 82 | + |
81 | 83 | with self.shell.builtin_trap: |
82 | 84 | if module_str not in sys.modules: |
83 | 85 | 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))) |
85 | 92 | mod = sys.modules[module_str] |
86 | 93 | if self._call_load_ipython_extension(mod): |
87 | 94 | self.loaded.add(module_str) |
@@ -168,3 +175,5 @@ def install_extension(self, url, filename=None): |
168 | 175 | filename = os.path.join(self.ipython_extension_dir, filename) |
169 | 176 | copy(url, filename) |
170 | 177 | return filename |
| 178 | + |
| 179 | + |
0 commit comments