From 796ce7f03e421462ea0030581afc135415a8a564 2021-10-21 02:31:50 From: Matthias Bussonnier Date: 2021-10-21 02:31:50 Subject: [PATCH] Merge pull request #13194 from meysam81/meysam/remove-deprecated-stuff feat: remove deprecated code & files ⚰️ --- diff --git a/IPython/__init__.py b/IPython/__init__.py index 0b182bd..7d098bc 100644 --- a/IPython/__init__.py +++ b/IPython/__init__.py @@ -41,11 +41,6 @@ See IPython `README.rst` file for more information: """) -# Make it easy to import extensions - they are always directly on pythonpath. -# Therefore, non-IPython modules can be added to extensions directory. -# This should probably be in ipapp.py. -sys.path.append(os.path.join(os.path.dirname(__file__), "extensions")) - #----------------------------------------------------------------------------- # Setup the top level names #----------------------------------------------------------------------------- diff --git a/IPython/core/extensions.py b/IPython/core/extensions.py index db3b040..ce419e1 100644 --- a/IPython/core/extensions.py +++ b/IPython/core/extensions.py @@ -19,6 +19,9 @@ from traitlets import Instance # Main class #----------------------------------------------------------------------------- +BUILTINS_EXTS = {"storemagic": False, "autoreload": False} + + class ExtensionManager(Configurable): """A class to manage IPython extensions. @@ -62,13 +65,22 @@ class ExtensionManager(Configurable): def _on_ipython_dir_changed(self, change): ensure_dir_exists(self.ipython_extension_dir) - def load_extension(self, module_str): + def load_extension(self, module_str: str): """Load an IPython extension by its module name. Returns the string "already loaded" if the extension is already loaded, "no load function" if the module doesn't have a load_ipython_extension function, or None if it succeeded. """ + try: + return self._load_extension(module_str) + except ModuleNotFoundError: + if module_str in BUILTINS_EXTS: + BUILTINS_EXTS[module_str] = True + return self._load_extension("IPython.extensions." + module_str) + raise + + def _load_extension(self, module_str: str): if module_str in self.loaded: return "already loaded" @@ -89,7 +101,7 @@ class ExtensionManager(Configurable): else: return "no load function" - def unload_extension(self, module_str): + def unload_extension(self, module_str: str): """Unload an IPython extension by its module name. This function looks up the extension's name in ``sys.modules`` and @@ -99,9 +111,11 @@ class ExtensionManager(Configurable): a function to unload itself, "not loaded" if the extension isn't loaded, otherwise None. """ + if BUILTINS_EXTS.get(module_str, False) is True: + module_str = "IPython.extensions." + module_str if module_str not in self.loaded: return "not loaded" - + if module_str in sys.modules: mod = sys.modules[module_str] if self._call_unload_ipython_extension(mod): @@ -109,7 +123,7 @@ class ExtensionManager(Configurable): else: return "no unload function" - def reload_extension(self, module_str): + def reload_extension(self, module_str: str): """Reload an IPython extension by calling reload. If the module has not been loaded before, @@ -119,6 +133,9 @@ class ExtensionManager(Configurable): """ 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] diff --git a/IPython/extensions/cythonmagic.py b/IPython/extensions/cythonmagic.py deleted file mode 100644 index 3c88e7c..0000000 --- a/IPython/extensions/cythonmagic.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -""" -**DEPRECATED** - -The cython magic has been integrated into Cython itself, -which is now released in version 0.21. - -cf github `Cython` organisation, `Cython` repo, under the -file `Cython/Build/IpythonMagic.py` -""" -#----------------------------------------------------------------------------- -# Copyright (C) 2010-2011, IPython Development Team. -#----------------------------------------------------------------------------- - -import warnings - -## still load the magic in IPython 3.x, remove completely in future versions. -def load_ipython_extension(ip): - """Load the extension in IPython.""" - - warnings.warn("""The Cython magic has been moved to the Cython package""") diff --git a/IPython/extensions/rmagic.py b/IPython/extensions/rmagic.py deleted file mode 100644 index ec57639..0000000 --- a/IPython/extensions/rmagic.py +++ /dev/null @@ -1,12 +0,0 @@ -# -*- coding: utf-8 -*- - -#----------------------------------------------------------------------------- -# Copyright (C) 2012 The IPython Development Team -#----------------------------------------------------------------------------- - -import warnings - -def load_ipython_extension(ip): - """Load the extension in IPython.""" - warnings.warn("The rmagic extension in IPython has moved to " - "`rpy2.ipython`, please see `rpy2` documentation.") diff --git a/IPython/extensions/sympyprinting.py b/IPython/extensions/sympyprinting.py deleted file mode 100644 index e6a83cd..0000000 --- a/IPython/extensions/sympyprinting.py +++ /dev/null @@ -1,32 +0,0 @@ -""" -**DEPRECATED** - -A print function that pretty prints sympy Basic objects. - -:moduleauthor: Brian Granger - -Usage -===== - -Once the extension is loaded, Sympy Basic objects are automatically -pretty-printed. - -As of SymPy 0.7.2, maintenance of this extension has moved to SymPy under -sympy.interactive.ipythonprinting, any modifications to account for changes to -SymPy should be submitted to SymPy rather than changed here. This module is -maintained here for backwards compatibility with old SymPy versions. - -""" -#----------------------------------------------------------------------------- -# Copyright (C) 2008 The IPython Development Team -#----------------------------------------------------------------------------- - -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- - -import warnings - -def load_ipython_extension(ip): - warnings.warn("The sympyprinting extension has moved to `sympy`, " - "use `from sympy import init_printing; init_printing()`") diff --git a/docs/source/whatsnew/pr/remove-deprecated-stuff.rst b/docs/source/whatsnew/pr/remove-deprecated-stuff.rst new file mode 100644 index 0000000..2a948e4 --- /dev/null +++ b/docs/source/whatsnew/pr/remove-deprecated-stuff.rst @@ -0,0 +1,8 @@ +Remove Deprecated Stuff +================================ + +We no longer need to add `extensions` to the PYTHONPATH because that is being +handled by `load_extension`. + +We are also removing Cythonmagic, sympyprinting and rmagic as they are now in +other packages and no longer need to be inside IPython.