##// END OF EJS Templates
Renamed @register_magics to @magics_class to avoid confusion....
Fernando Perez -
Show More
@@ -38,7 +38,7 b' from IPython.utils.warn import error, warn'
38
38
39 # A dict we'll use for each class that has magics, used as temporary storage to
39 # A dict we'll use for each class that has magics, used as temporary storage to
40 # pass information between the @line/cell_magic method decorators and the
40 # pass information between the @line/cell_magic method decorators and the
41 # @register_magics class decorator, because the method decorators have no
41 # @magics_class class decorator, because the method decorators have no
42 # access to the class when they run. See for more details:
42 # access to the class when they run. See for more details:
43 # http://stackoverflow.com/questions/2366713/can-a-python-decorator-of-an-instance-method-access-the-class
43 # http://stackoverflow.com/questions/2366713/can-a-python-decorator-of-an-instance-method-access-the-class
44
44
@@ -82,7 +82,7 b' def needs_local_scope(func):'
82 # Class and method decorators for registering magics
82 # Class and method decorators for registering magics
83 #-----------------------------------------------------------------------------
83 #-----------------------------------------------------------------------------
84
84
85 def register_magics(cls):
85 def magics_class(cls):
86 cls.registered = True
86 cls.registered = True
87 cls.magics = dict(line = magics['line'],
87 cls.magics = dict(line = magics['line'],
88 cell = magics['cell'])
88 cell = magics['cell'])
@@ -294,7 +294,7 b' class Magics(object):'
294 - Use the method decorators `@line_magic` and `@cell_magic` to decorate
294 - Use the method decorators `@line_magic` and `@cell_magic` to decorate
295 individual methods as magic functions, AND
295 individual methods as magic functions, AND
296
296
297 - Use the class decorator `@register_magics` to ensure that the magic
297 - Use the class decorator `@magics_class` to ensure that the magic
298 methods are properly registered at the instance level upon instance
298 methods are properly registered at the instance level upon instance
299 initialization.
299 initialization.
300
300
@@ -312,7 +312,7 b' class Magics(object):'
312 def __init__(self, shell):
312 def __init__(self, shell):
313 if not(self.__class__.registered):
313 if not(self.__class__.registered):
314 raise ValueError('Magics subclass without registration - '
314 raise ValueError('Magics subclass without registration - '
315 'did you forget to apply @register_magics?')
315 'did you forget to apply @magics_class?')
316 self.shell = shell
316 self.shell = shell
317 self.options_table = {}
317 self.options_table = {}
318 # The method decorators are run when the instance doesn't exist yet, so
318 # The method decorators are run when the instance doesn't exist yet, so
@@ -12,7 +12,7 b''
12 # Imports
12 # Imports
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14
14
15 from ..magic import Magics, register_magics
15 from ..magic import Magics, magics_class
16 from .auto import AutoMagics
16 from .auto import AutoMagics
17 from .basic import BasicMagics
17 from .basic import BasicMagics
18 from .code import CodeMagics, MacroToEdit
18 from .code import CodeMagics, MacroToEdit
@@ -30,7 +30,7 b' from .pylab import PylabMagics'
30 # Magic implementation classes
30 # Magic implementation classes
31 #-----------------------------------------------------------------------------
31 #-----------------------------------------------------------------------------
32
32
33 @register_magics
33 @magics_class
34 class UserMagics(Magics):
34 class UserMagics(Magics):
35 """Placeholder for user-defined magics to be added at runtime.
35 """Placeholder for user-defined magics to be added at runtime.
36
36
@@ -13,7 +13,7 b''
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14
14
15 # Our own packages
15 # Our own packages
16 from IPython.core.magic import Bunch, Magics, register_magics, line_magic
16 from IPython.core.magic import Bunch, Magics, magics_class, line_magic
17 from IPython.testing.skipdoctest import skip_doctest
17 from IPython.testing.skipdoctest import skip_doctest
18 from IPython.utils.warn import error
18 from IPython.utils.warn import error
19
19
@@ -21,7 +21,7 b' from IPython.utils.warn import error'
21 # Magic implementation classes
21 # Magic implementation classes
22 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
23
23
24 @register_magics
24 @magics_class
25 class AutoMagics(Magics):
25 class AutoMagics(Magics):
26 """Magics that control various autoX behaviors."""
26 """Magics that control various autoX behaviors."""
27
27
@@ -20,7 +20,7 b' from pprint import pformat'
20
20
21 # Our own packages
21 # Our own packages
22 from IPython.core.error import UsageError
22 from IPython.core.error import UsageError
23 from IPython.core.magic import Magics, register_magics, line_magic
23 from IPython.core.magic import Magics, magics_class, line_magic
24 from IPython.core.prefilter import ESC_MAGIC
24 from IPython.core.prefilter import ESC_MAGIC
25 from IPython.utils.text import format_screen
25 from IPython.utils.text import format_screen
26 from IPython.core import magic_arguments, page
26 from IPython.core import magic_arguments, page
@@ -33,7 +33,7 b' from IPython.utils.warn import warn, error'
33 # Magics class implementation
33 # Magics class implementation
34 #-----------------------------------------------------------------------------
34 #-----------------------------------------------------------------------------
35
35
36 @register_magics
36 @magics_class
37 class BasicMagics(Magics):
37 class BasicMagics(Magics):
38 """Magics that provide central IPython functionality.
38 """Magics that provide central IPython functionality.
39
39
@@ -23,7 +23,7 b' from urllib2 import urlopen'
23 # Our own packages
23 # Our own packages
24 from IPython.core.error import TryNext
24 from IPython.core.error import TryNext
25 from IPython.core.macro import Macro
25 from IPython.core.macro import Macro
26 from IPython.core.magic import Magics, register_magics, line_magic
26 from IPython.core.magic import Magics, magics_class, line_magic
27 from IPython.testing.skipdoctest import skip_doctest
27 from IPython.testing.skipdoctest import skip_doctest
28 from IPython.utils import openpy
28 from IPython.utils import openpy
29 from IPython.utils import py3compat
29 from IPython.utils import py3compat
@@ -39,7 +39,7 b' from IPython.utils.warn import warn'
39 class MacroToEdit(ValueError): pass
39 class MacroToEdit(ValueError): pass
40
40
41
41
42 @register_magics
42 @magics_class
43 class CodeMagics(Magics):
43 class CodeMagics(Magics):
44 """Magics related to code management (loading, saving, editing, ...)."""
44 """Magics related to code management (loading, saving, editing, ...)."""
45
45
@@ -17,14 +17,14 b' import re'
17
17
18 # Our own packages
18 # Our own packages
19 from IPython.core.error import UsageError
19 from IPython.core.error import UsageError
20 from IPython.core.magic import Magics, register_magics, line_magic
20 from IPython.core.magic import Magics, magics_class, line_magic
21 from IPython.utils.warn import error
21 from IPython.utils.warn import error
22
22
23 #-----------------------------------------------------------------------------
23 #-----------------------------------------------------------------------------
24 # Magic implementation classes
24 # Magic implementation classes
25 #-----------------------------------------------------------------------------
25 #-----------------------------------------------------------------------------
26
26
27 @register_magics
27 @magics_class
28 class ConfigMagics(Magics):
28 class ConfigMagics(Magics):
29
29
30 def __init__(self, shell):
30 def __init__(self, shell):
@@ -13,13 +13,13 b''
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14
14
15 # Our own packages
15 # Our own packages
16 from IPython.core.magic import Magics, register_magics, line_magic
16 from IPython.core.magic import Magics, magics_class, line_magic
17
17
18 #-----------------------------------------------------------------------------
18 #-----------------------------------------------------------------------------
19 # Magic implementation classes
19 # Magic implementation classes
20 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
21
21
22 @register_magics
22 @magics_class
23 class DeprecatedMagics(Magics):
23 class DeprecatedMagics(Magics):
24 """Magics slated for later removal."""
24 """Magics slated for later removal."""
25
25
@@ -36,7 +36,7 b' from IPython.core import debugger, oinspect'
36 from IPython.core import page
36 from IPython.core import page
37 from IPython.core.error import UsageError
37 from IPython.core.error import UsageError
38 from IPython.core.macro import Macro
38 from IPython.core.macro import Macro
39 from IPython.core.magic import (Magics, register_magics, line_magic,
39 from IPython.core.magic import (Magics, magics_class, line_magic,
40 on_off, needs_local_scope)
40 on_off, needs_local_scope)
41 from IPython.testing.skipdoctest import skip_doctest
41 from IPython.testing.skipdoctest import skip_doctest
42 from IPython.utils import py3compat
42 from IPython.utils import py3compat
@@ -50,7 +50,7 b' from IPython.utils.warn import warn, error'
50 # Magic implementation classes
50 # Magic implementation classes
51 #-----------------------------------------------------------------------------
51 #-----------------------------------------------------------------------------
52
52
53 @register_magics
53 @magics_class
54 class ExecutionMagics(Magics):
54 class ExecutionMagics(Magics):
55 """Magics related to code execution, debugging, profiling, etc.
55 """Magics related to code execution, debugging, profiling, etc.
56
56
@@ -16,13 +16,13 b''
16 import os
16 import os
17
17
18 # Our own packages
18 # Our own packages
19 from IPython.core.magic import Magics, register_magics, line_magic
19 from IPython.core.magic import Magics, magics_class, line_magic
20
20
21 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
22 # Magic implementation classes
22 # Magic implementation classes
23 #-----------------------------------------------------------------------------
23 #-----------------------------------------------------------------------------
24
24
25 @register_magics
25 @magics_class
26 class ExtensionMagics(Magics):
26 class ExtensionMagics(Magics):
27 """Magics to manage the IPython extensions system."""
27 """Magics to manage the IPython extensions system."""
28
28
@@ -19,7 +19,7 b' from io import open as io_open'
19
19
20 # Our own packages
20 # Our own packages
21 from IPython.core.error import StdinNotImplementedError
21 from IPython.core.error import StdinNotImplementedError
22 from IPython.core.magic import Magics, register_magics, line_magic
22 from IPython.core.magic import Magics, magics_class, line_magic
23 from IPython.testing.skipdoctest import skip_doctest
23 from IPython.testing.skipdoctest import skip_doctest
24 from IPython.utils import io
24 from IPython.utils import io
25
25
@@ -27,7 +27,7 b' from IPython.utils import io'
27 # Magics class implementation
27 # Magics class implementation
28 #-----------------------------------------------------------------------------
28 #-----------------------------------------------------------------------------
29
29
30 @register_magics
30 @magics_class
31 class HistoryMagics(Magics):
31 class HistoryMagics(Magics):
32
32
33 @skip_doctest
33 @skip_doctest
@@ -17,14 +17,14 b' import os'
17 import sys
17 import sys
18
18
19 # Our own packages
19 # Our own packages
20 from IPython.core.magic import Magics, register_magics, line_magic
20 from IPython.core.magic import Magics, magics_class, line_magic
21 from IPython.utils.warn import warn
21 from IPython.utils.warn import warn
22
22
23 #-----------------------------------------------------------------------------
23 #-----------------------------------------------------------------------------
24 # Magic implementation classes
24 # Magic implementation classes
25 #-----------------------------------------------------------------------------
25 #-----------------------------------------------------------------------------
26
26
27 @register_magics
27 @magics_class
28 class LoggingMagics(Magics):
28 class LoggingMagics(Magics):
29 """Magics related to all logging machinery."""
29 """Magics related to all logging machinery."""
30
30
@@ -20,7 +20,7 b' import sys'
20 # Our own packages
20 # Our own packages
21 from IPython.core import page
21 from IPython.core import page
22 from IPython.core.error import StdinNotImplementedError
22 from IPython.core.error import StdinNotImplementedError
23 from IPython.core.magic import Magics, register_magics, line_magic
23 from IPython.core.magic import Magics, magics_class, line_magic
24 from IPython.testing.skipdoctest import skip_doctest
24 from IPython.testing.skipdoctest import skip_doctest
25 from IPython.utils.encoding import DEFAULT_ENCODING
25 from IPython.utils.encoding import DEFAULT_ENCODING
26 from IPython.utils.path import get_py_filename
26 from IPython.utils.path import get_py_filename
@@ -29,7 +29,7 b' from IPython.utils.path import get_py_filename'
29 # Magic implementation classes
29 # Magic implementation classes
30 #-----------------------------------------------------------------------------
30 #-----------------------------------------------------------------------------
31
31
32 @register_magics
32 @magics_class
33 class NamespaceMagics(Magics):
33 class NamespaceMagics(Magics):
34 """Magics to manage various aspects of the user's namespace.
34 """Magics to manage various aspects of the user's namespace.
35
35
@@ -25,7 +25,7 b' from pprint import pformat'
25 from IPython.core import oinspect
25 from IPython.core import oinspect
26 from IPython.core import page
26 from IPython.core import page
27 from IPython.core.error import UsageError
27 from IPython.core.error import UsageError
28 from IPython.core.magic import (Magics, compress_dhist, register_magics,
28 from IPython.core.magic import (Magics, compress_dhist, magics_class,
29 line_magic)
29 line_magic)
30 from IPython.testing.skipdoctest import skip_doctest
30 from IPython.testing.skipdoctest import skip_doctest
31 from IPython.utils.io import file_read, nlprint
31 from IPython.utils.io import file_read, nlprint
@@ -35,7 +35,7 b' from IPython.utils.terminal import set_term_title'
35 #-----------------------------------------------------------------------------
35 #-----------------------------------------------------------------------------
36 # Magic implementation classes
36 # Magic implementation classes
37 #-----------------------------------------------------------------------------
37 #-----------------------------------------------------------------------------
38 @register_magics
38 @magics_class
39 class OSMagics(Magics):
39 class OSMagics(Magics):
40 """Magics to interact with the underlying OS (shell-type functionality).
40 """Magics to interact with the underlying OS (shell-type functionality).
41 """
41 """
@@ -14,14 +14,14 b''
14
14
15 # Our own packages
15 # Our own packages
16 from IPython.config.application import Application
16 from IPython.config.application import Application
17 from IPython.core.magic import Magics, register_magics, line_magic
17 from IPython.core.magic import Magics, magics_class, line_magic
18 from IPython.testing.skipdoctest import skip_doctest
18 from IPython.testing.skipdoctest import skip_doctest
19
19
20 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
21 # Magic implementation classes
21 # Magic implementation classes
22 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
23
23
24 @register_magics
24 @magics_class
25 class PylabMagics(Magics):
25 class PylabMagics(Magics):
26 """Magics related to matplotlib's pylab support"""
26 """Magics related to matplotlib's pylab support"""
27
27
@@ -29,7 +29,7 b' from IPython.utils.tempdir import TemporaryDirectory'
29 # Test functions begin
29 # Test functions begin
30 #-----------------------------------------------------------------------------
30 #-----------------------------------------------------------------------------
31
31
32 @magic.register_magics
32 @magic.magics_class
33 class DummyMagics(magic.Magics): pass
33 class DummyMagics(magic.Magics): pass
34
34
35 def test_rehashx():
35 def test_rehashx():
@@ -406,10 +406,10 b' def superreload(module, reload=reload, old_objects={}):'
406 #------------------------------------------------------------------------------
406 #------------------------------------------------------------------------------
407
407
408 from IPython.core.hooks import TryNext
408 from IPython.core.hooks import TryNext
409 from IPython.core.magic import Magics, register_magics, line_magic
409 from IPython.core.magic import Magics, magics_class, line_magic
410 from IPython.core.plugin import Plugin
410 from IPython.core.plugin import Plugin
411
411
412 @register_magics
412 @magics_class
413 class AutoreloadMagics(Magics):
413 class AutoreloadMagics(Magics):
414 def __init__(self, *a, **kw):
414 def __init__(self, *a, **kw):
415 super(AutoreloadMagics, self).__init__(*a, **kw)
415 super(AutoreloadMagics, self).__init__(*a, **kw)
@@ -37,7 +37,7 b' Usage'
37 import ast
37 import ast
38 import re
38 import re
39
39
40 from IPython.core.magic import Magics, register_magics, line_magic
40 from IPython.core.magic import Magics, magics_class, line_magic
41 from IPython.testing.skipdoctest import skip_doctest
41 from IPython.testing.skipdoctest import skip_doctest
42
42
43 #-----------------------------------------------------------------------------
43 #-----------------------------------------------------------------------------
@@ -49,7 +49,7 b' Use activate() on a DirectView object to activate it for magics.'
49 """
49 """
50
50
51
51
52 @register_magics
52 @magics_class
53 class ParallelMagics(Magics):
53 class ParallelMagics(Magics):
54 """A set of magics useful when controlling a parallel IPython cluster.
54 """A set of magics useful when controlling a parallel IPython cluster.
55 """
55 """
@@ -14,7 +14,7 b' import inspect, os, sys, textwrap'
14
14
15 from IPython.core.error import UsageError
15 from IPython.core.error import UsageError
16 from IPython.core.fakemodule import FakeModule
16 from IPython.core.fakemodule import FakeModule
17 from IPython.core.magic import Magics, register_magics, line_magic
17 from IPython.core.magic import Magics, magics_class, line_magic
18 from IPython.core.plugin import Plugin
18 from IPython.core.plugin import Plugin
19 from IPython.testing.skipdoctest import skip_doctest
19 from IPython.testing.skipdoctest import skip_doctest
20 from IPython.utils.traitlets import Bool, Instance
20 from IPython.utils.traitlets import Bool, Instance
@@ -53,7 +53,7 b' def restore_data(ip):'
53 restore_dhist(ip)
53 restore_dhist(ip)
54
54
55
55
56 @register_magics
56 @magics_class
57 class StoreMagics(Magics):
57 class StoreMagics(Magics):
58 """Lightweight persistence for python variables.
58 """Lightweight persistence for python variables.
59
59
@@ -29,7 +29,7 b' from contextlib import nested'
29 import warnings
29 import warnings
30
30
31 from IPython.core import ultratb
31 from IPython.core import ultratb
32 from IPython.core.magic import Magics, register_magics, line_magic
32 from IPython.core.magic import Magics, magics_class, line_magic
33 from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
33 from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
34 from IPython.frontend.terminal.ipapp import load_default_config
34 from IPython.frontend.terminal.ipapp import load_default_config
35
35
@@ -42,7 +42,7 b' from IPython.utils.io import ask_yes_no'
42 #-----------------------------------------------------------------------------
42 #-----------------------------------------------------------------------------
43
43
44 # This is an additional magic that is exposed in embedded shells.
44 # This is an additional magic that is exposed in embedded shells.
45 @register_magics
45 @magics_class
46 class EmbeddedMagics(Magics):
46 class EmbeddedMagics(Magics):
47
47
48 @line_magic
48 @line_magic
@@ -25,7 +25,7 b' from contextlib import nested'
25 from IPython.core.error import TryNext, UsageError
25 from IPython.core.error import TryNext, UsageError
26 from IPython.core.usage import interactive_usage, default_banner
26 from IPython.core.usage import interactive_usage, default_banner
27 from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC
27 from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC
28 from IPython.core.magic import Magics, register_magics, line_magic
28 from IPython.core.magic import Magics, magics_class, line_magic
29 from IPython.testing.skipdoctest import skip_doctest
29 from IPython.testing.skipdoctest import skip_doctest
30 from IPython.utils.encoding import get_stream_enc
30 from IPython.utils.encoding import get_stream_enc
31 from IPython.utils import py3compat
31 from IPython.utils import py3compat
@@ -120,7 +120,7 b" def rerun_pasted(shell, name='pasted_block'):"
120 # Terminal-specific magics
120 # Terminal-specific magics
121 #------------------------------------------------------------------------
121 #------------------------------------------------------------------------
122
122
123 @register_magics
123 @magics_class
124 class TerminalMagics(Magics):
124 class TerminalMagics(Magics):
125
125
126 @line_magic
126 @line_magic
General Comments 0
You need to be logged in to leave comments. Login now