diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 5c44af4..fab1462 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -2007,7 +2007,7 @@ class InteractiveShell(SingletonConfigurable): self.register_magics(m.AutoMagics, m.BasicMagics, m.CodeMagics, m.ConfigMagics, mf.DeprecatedMagics, m.ExecutionMagics, - mf.ExtensionsMagics, m.HistoryMagics, m.LoggingMagics, + m.ExtensionMagics, m.HistoryMagics, m.LoggingMagics, m.NamespaceMagics, m.OSMagics, mf.PylabMagics ) # FIXME: Move the color initialization to the DisplayHook, which diff --git a/IPython/core/magic_functions.py b/IPython/core/magic_functions.py index 6c4f982..d8dfbea 100644 --- a/IPython/core/magic_functions.py +++ b/IPython/core/magic_functions.py @@ -14,9 +14,6 @@ # Imports #----------------------------------------------------------------------------- -# Stdlib -import os - # Our own packages from IPython.config.application import Application from IPython.core.magic import Magics, register_magics, line_magic @@ -27,53 +24,6 @@ from IPython.testing.skipdoctest import skip_doctest #----------------------------------------------------------------------------- @register_magics -class ExtensionsMagics(Magics): - """Magics to manage the IPython extensions system.""" - - @line_magic - def install_ext(self, parameter_s=''): - """Download and install an extension from a URL, e.g.:: - - %install_ext https://bitbucket.org/birkenfeld/ipython-physics/raw/d1310a2ab15d/physics.py - - The URL should point to an importable Python module - either a .py file - or a .zip file. - - Parameters: - - -n filename : Specify a name for the file, rather than taking it from - the URL. - """ - opts, args = self.parse_options(parameter_s, 'n:') - try: - filename = self.shell.extension_manager.install_extension(args, - opts.get('n')) - except ValueError as e: - print e - return - - filename = os.path.basename(filename) - print "Installed %s. To use it, type:" % filename - print " %%load_ext %s" % os.path.splitext(filename)[0] - - - @line_magic - def load_ext(self, module_str): - """Load an IPython extension by its module name.""" - return self.shell.extension_manager.load_extension(module_str) - - @line_magic - def unload_ext(self, module_str): - """Unload an IPython extension by its module name.""" - self.shell.extension_manager.unload_extension(module_str) - - @line_magic - def reload_ext(self, module_str): - """Reload an IPython extension by its module name.""" - self.shell.extension_manager.reload_extension(module_str) - - -@register_magics class PylabMagics(Magics): """Magics related to matplotlib's pylab support""" diff --git a/IPython/core/magics/__init__.py b/IPython/core/magics/__init__.py index 61b319e..afcf318 100644 --- a/IPython/core/magics/__init__.py +++ b/IPython/core/magics/__init__.py @@ -18,6 +18,7 @@ from .basic import BasicMagics from .code import CodeMagics, MacroToEdit from .config import ConfigMagics from .execution import ExecutionMagics +from .extension import ExtensionMagics from .history import HistoryMagics from .logging import LoggingMagics from .namespace import NamespaceMagics diff --git a/IPython/core/magics/extension.py b/IPython/core/magics/extension.py new file mode 100644 index 0000000..9425eff --- /dev/null +++ b/IPython/core/magics/extension.py @@ -0,0 +1,69 @@ +"""Implementation of magic functions for the extension machinery. +""" +#----------------------------------------------------------------------------- +# Copyright (c) 2012 The IPython Development Team. +# +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +# Stdlib +import os + +# Our own packages +from IPython.core.magic import Magics, register_magics, line_magic + +#----------------------------------------------------------------------------- +# Magic implementation classes +#----------------------------------------------------------------------------- + +@register_magics +class ExtensionMagics(Magics): + """Magics to manage the IPython extensions system.""" + + @line_magic + def install_ext(self, parameter_s=''): + """Download and install an extension from a URL, e.g.:: + + %install_ext https://bitbucket.org/birkenfeld/ipython-physics/raw/d1310a2ab15d/physics.py + + The URL should point to an importable Python module - either a .py file + or a .zip file. + + Parameters: + + -n filename : Specify a name for the file, rather than taking it from + the URL. + """ + opts, args = self.parse_options(parameter_s, 'n:') + try: + filename = self.shell.extension_manager.install_extension(args, + opts.get('n')) + except ValueError as e: + print e + return + + filename = os.path.basename(filename) + print "Installed %s. To use it, type:" % filename + print " %%load_ext %s" % os.path.splitext(filename)[0] + + + @line_magic + def load_ext(self, module_str): + """Load an IPython extension by its module name.""" + return self.shell.extension_manager.load_extension(module_str) + + @line_magic + def unload_ext(self, module_str): + """Unload an IPython extension by its module name.""" + self.shell.extension_manager.unload_extension(module_str) + + @line_magic + def reload_ext(self, module_str): + """Reload an IPython extension by its module name.""" + self.shell.extension_manager.reload_extension(module_str)