cythonmagic.py
43 lines
| 1.4 KiB
| text/x-python
|
PythonLexer
Brian Granger
|
r7031 | # -*- coding: utf-8 -*- | ||
""" | ||||
Matthias Bussonnier
|
r17910 | The cython magic has been integrated into Cython itself, | ||
which is now released in version 0.21. | ||||
Bradley M. Froehle
|
r8893 | |||
Matthias Bussonnier
|
r18302 | cf github `Cython` organisation, `Cython` repo, under the | ||
Matthias Bussonnier
|
r17910 | file `Cython/Build/IpythonMagic.py` | ||
Brian Granger
|
r7031 | """ | ||
#----------------------------------------------------------------------------- | ||||
# Copyright (C) 2010-2011, 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. | ||||
#----------------------------------------------------------------------------- | ||||
Bradley M. Froehle
|
r8095 | from __future__ import print_function | ||
Matthias Bussonnier
|
r18302 | import IPython.utils.version as version | ||
Brian Granger
|
r7031 | try: | ||
Matthias Bussonnier
|
r17910 | import Cython | ||
except: | ||||
Cython = None | ||||
MinRK
|
r9894 | |||
try: | ||||
Matthias Bussonnier
|
r17910 | from Cython.Build.IpythonMagic import CythonMagics | ||
except : | ||||
pass | ||||
Brian Granger
|
r7037 | |||
Brian Granger
|
r7031 | |||
Matthias Bussonnier
|
r17910 | ## still load the magic in IPython 3.x, remove completely in future versions. | ||
Brian Granger
|
r7031 | def load_ipython_extension(ip): | ||
"""Load the extension in IPython.""" | ||||
Matthias Bussonnier
|
r17910 | |||
Giuseppe Venturini
|
r20736 | print("""The Cython magic has been moved to the Cython package, hence """) | ||
print("""`%load_ext cythonmagic` is deprecated; please use `%load_ext Cython` instead.""") | ||||
Matthias Bussonnier
|
r17910 | |||
Matthias Bussonnier
|
r18302 | if Cython is None or not version.check_version(Cython.__version__, "0.21"): | ||
Matthias Bussonnier
|
r17910 | print("You need Cython version >=0.21 to use the Cython magic") | ||
return | ||||
Matthias Bussonnier
|
r17914 | print("""\nThough, because I am nice, I'll still try to load it for you this time.""") | ||
Cython.load_ipython_extension(ip) | ||||