Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions metakernel/_metakernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,13 +576,13 @@ def reload_magics(self):
# Make a metakernel/magics if it doesn't exist:
local_magics_dir = get_local_magics_dir()
# Search all of the places there could be magics:
paths = [local_magics_dir,
os.path.join(os.path.dirname(os.path.abspath(__file__)), "magics")]
try:
paths += [os.path.join(os.path.dirname(
paths = [os.path.join(os.path.dirname(
os.path.abspath(inspect.getfile(self.__class__))), "magics")]
except:
pass
paths = []
paths += [local_magics_dir,
os.path.join(os.path.dirname(os.path.abspath(__file__)), "magics")]
for magic_dir in paths:
sys.path.append(magic_dir)
magic_files.extend(glob.glob(os.path.join(magic_dir, "*.py")))
Expand Down
12 changes: 12 additions & 0 deletions metakernel/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# python3
_maxsize = sys.maxsize


class MagicOptionParser(optparse.OptionParser):
def error(self, msg):
raise Exception('Magic Parse error: "%s"' % msg)
Expand All @@ -24,7 +25,18 @@ def exit(self, status=0, msg=None):
## FIXME: override help to also stop processing
## currently --help gives syntax error


class Magic(object):
"""
Base class to define magics for MetaKernel based kernels.

Users can redefine the default magics provided by Metakernel
by creating a module with the exact same name as the
Metakernel magic.

For example, you can override %matplotlib in your kernel by
writing a new magic inside magics/matplotlib_magic.py
"""

def __init__(self, kernel):
self.kernel = kernel
Expand Down