Skip to content

Commit

Permalink
Remove old mentions and uses of ipython_extension_dir (#14310)
Browse files Browse the repository at this point in the history
The bulk of this functionality was removed in IPython 8.6.0, but there
were still mentions of it in the docs and in the reload code.

The extant mentions of `.ipython/extensions` in code came up as a source
of confusion in #14263.
  • Loading branch information
Carreau committed Jan 29, 2024
2 parents 112e596 + c55d9f3 commit 93ffc15
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions IPython/core/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,22 @@ def load_ipython_extension(ipython):
the only argument. You can do anything you want with IPython at
that point, including defining new magic and aliases, adding new
components, etc.
You can also optionally define an :func:`unload_ipython_extension(ipython)`
function, which will be called if the user unloads or reloads the extension.
The extension manager will only call :func:`load_ipython_extension` again
if the extension is reloaded.
You can put your extension modules anywhere you want, as long as
they can be imported by Python's standard import mechanism. However,
to make it easy to write extensions, you can also put your extensions
in ``os.path.join(self.ipython_dir, 'extensions')``. This directory
is added to ``sys.path`` automatically.
they can be imported by Python's standard import mechanism.
"""

shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', allow_none=True)

def __init__(self, shell=None, **kwargs):
super(ExtensionManager, self).__init__(shell=shell, **kwargs)
self.shell.observe(
self._on_ipython_dir_changed, names=('ipython_dir',)
)
self.loaded = set()

@property
def ipython_extension_dir(self):
return os.path.join(self.shell.ipython_dir, u'extensions')

def _on_ipython_dir_changed(self, change):
ensure_dir_exists(self.ipython_extension_dir)

def load_extension(self, module_str: str):
"""Load an IPython extension by its module name.
Expand Down Expand Up @@ -124,16 +111,14 @@ def reload_extension(self, module_str: str):
:func:`reload` is called and then the :func:`load_ipython_extension`
function of the module, if it exists is called.
"""
from IPython.utils.syspathcontext import prepended_to_syspath

if BUILTINS_EXTS.get(module_str, False) is True:
module_str = "IPython.extensions." + module_str

if (module_str in self.loaded) and (module_str in sys.modules):
self.unload_extension(module_str)
mod = sys.modules[module_str]
with prepended_to_syspath(self.ipython_extension_dir):
reload(mod)
reload(mod)
if self._call_load_ipython_extension(mod):
self.loaded.add(module_str)
else:
Expand Down

0 comments on commit 93ffc15

Please sign in to comment.