##// END OF EJS Templates
BUG: Fix pprint failure on non-string __qualname__ or __name__....
BUG: Fix pprint failure on non-string __qualname__ or __name__. Fixes a bug where pprint would fail to correctly render a class whose __qualname__ is not a string, or a class that doesn't have a __qualname__ and whose __name__ is not a string.

File last commit:

r21607:259842bf
r21803:95c4d0b1
Show More
extension.py
96 lines | 3.6 KiB | text/x-python | PythonLexer
Fernando Perez
Create core.magics.extension according to new API.
r6967 """Implementation of magic functions for the extension machinery.
"""
Thomas Kluyver
Convert print statements to print function calls...
r13348 from __future__ import print_function
Fernando Perez
Create core.magics.extension according to new API.
r6967 #-----------------------------------------------------------------------------
# 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
Bradley M. Froehle
Better error messages for common magic commands....
r8278 from IPython.core.error import UsageError
Fernando Perez
Renamed @register_magics to @magics_class to avoid confusion....
r6973 from IPython.core.magic import Magics, magics_class, line_magic
Matthias Bussonnier
Deprecate and undocument install_ext...
r21514 from warnings import warn
Fernando Perez
Create core.magics.extension according to new API.
r6967
#-----------------------------------------------------------------------------
# Magic implementation classes
#-----------------------------------------------------------------------------
Fernando Perez
Renamed @register_magics to @magics_class to avoid confusion....
r6973 @magics_class
Fernando Perez
Create core.magics.extension according to new API.
r6967 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.
"""
Aaron Meurer
Fix grammar and spacing in a warning message
r21607 warn("%install_ext` is deprecated, please distribute your extension "
"as a python package.", UserWarning)
Fernando Perez
Create core.magics.extension according to new API.
r6967 opts, args = self.parse_options(parameter_s, 'n:')
try:
filename = self.shell.extension_manager.install_extension(args,
opts.get('n'))
except ValueError as e:
Thomas Kluyver
Convert print statements to print function calls...
r13348 print(e)
Fernando Perez
Create core.magics.extension according to new API.
r6967 return
filename = os.path.basename(filename)
Thomas Kluyver
Convert print statements to print function calls...
r13348 print("Installed %s. To use it, type:" % filename)
print(" %%load_ext %s" % os.path.splitext(filename)[0])
Fernando Perez
Create core.magics.extension according to new API.
r6967
@line_magic
def load_ext(self, module_str):
"""Load an IPython extension by its module name."""
Bradley M. Froehle
Better error messages for common magic commands....
r8278 if not module_str:
raise UsageError('Missing module name.')
Thomas Kluyver
Add message when trying to %load_ext a module that is not an IPython extension.
r8586 res = self.shell.extension_manager.load_extension(module_str)
if res == 'already loaded':
Thomas Kluyver
Convert print statements to print function calls...
r13348 print("The %s extension is already loaded. To reload it, use:" % module_str)
print(" %reload_ext", module_str)
Thomas Kluyver
Add message when trying to %load_ext a module that is not an IPython extension.
r8586 elif res == 'no load function':
Thomas Kluyver
Convert print statements to print function calls...
r13348 print("The %s module is not an IPython extension." % module_str)
Fernando Perez
Create core.magics.extension according to new API.
r6967
@line_magic
def unload_ext(self, module_str):
Thomas Kluyver
Extension manager refuses to load extension more than once
r8549 """Unload an IPython extension by its module name.
Not all extensions can be unloaded, only those which define an
``unload_ipython_extension`` function.
"""
Bradley M. Froehle
Better error messages for common magic commands....
r8278 if not module_str:
raise UsageError('Missing module name.')
Thomas Kluyver
Extension manager refuses to load extension more than once
r8549
res = self.shell.extension_manager.unload_extension(module_str)
if res == 'no unload function':
Thomas Kluyver
Convert print statements to print function calls...
r13348 print("The %s extension doesn't define how to unload it." % module_str)
Thomas Kluyver
Extension manager refuses to load extension more than once
r8549 elif res == "not loaded":
Thomas Kluyver
Convert print statements to print function calls...
r13348 print("The %s extension is not loaded." % module_str)
Fernando Perez
Create core.magics.extension according to new API.
r6967
@line_magic
def reload_ext(self, module_str):
"""Reload an IPython extension by its module name."""
Bradley M. Froehle
Better error messages for common magic commands....
r8278 if not module_str:
raise UsageError('Missing module name.')
Fernando Perez
Create core.magics.extension according to new API.
r6967 self.shell.extension_manager.reload_extension(module_str)