##// END OF EJS Templates
More code review changes:...
Brian Granger -
Show More
@@ -0,0 +1,7
1 .. _extensions_cythonmagic:
2
3 ===========
4 cythonmagic
5 ===========
6
7 .. automodule:: IPython.extensions.cythonmagic
@@ -15,6 +15,7 Parts of this code were taken from Cython.inline.
15 15 # The full license is in the file COPYING.txt, distributed with this software.
16 16 #-----------------------------------------------------------------------------
17 17
18 import io
18 19 import os, sys
19 20 from importlib import import_module
20 21 import imp
@@ -32,6 +33,7 from IPython.testing.skipdoctest import skip_doctest
32 33 from IPython.core.magic_arguments import (
33 34 argument, magic_arguments, parse_argstring
34 35 )
36 from IPython.utils import py3compat
35 37
36 38 import Cython
37 39 from Cython.Compiler.Errors import CompileError
@@ -90,7 +92,7 class CythonMagics(Magics):
90 92 if not module_name:
91 93 raise ValueError('module name must be given')
92 94 fname = module_name + '.pyx'
93 with io.open(fname, 'w', encoding='utf-8'):
95 with io.open(fname, 'w', encoding='utf-8') as f:
94 96 f.write(cell)
95 97 if 'pyximport' not in sys.modules:
96 98 import pyximport
@@ -125,8 +127,7 class CythonMagics(Magics):
125 127 """
126 128 args = parse_argstring(self.cython, line)
127 129 code = cell if cell.endswith('\n') else cell+'\n'
128 # distutils.Extension cannot handle sources that a unicode
129 lib_dir=str(os.path.join(self.shell.ipython_dir,'cython'))
130 lib_dir=os.path.join(self.shell.ipython_dir, 'cython')
130 131 cython_include_dirs=['.']
131 132 force=args.force
132 133 quiet=True
@@ -146,9 +147,9 class CythonMagics(Magics):
146 147 import numpy
147 148 c_include_dirs.append(numpy.get_include())
148 149 pyx_file = os.path.join(lib_dir, module_name + '.pyx')
149 with io.open(pyx_file, 'w', encoding='utf-8'):
150 pyx_file = py3compat.unicode_to_str(pyx_file, encoding=sys.getfilesystemencoding())
151 with io.open(pyx_file, 'w', encoding='utf-8') as f:
150 152 f.write(code)
151 print [pyx_file]
152 153 extension = Extension(
153 154 name = module_name,
154 155 sources = [pyx_file],
@@ -4,10 +4,11
4 4 import os
5 5 import nose.tools as nt
6 6
7 from IPython.utils import py3compat
7 8
8 code = """def f(x):
9 code = py3compat.str_to_unicode("""def f(x):
9 10 return 2*x
10 """
11 """)
11 12
12 13 try:
13 14 import Cython
@@ -39,7 +40,8 def test_cython():
39 40 ip = get_ipython()
40 41 ip.run_cell_magic('cython', '', code)
41 42 ip.ex('g = f(10)')
42 nt.assert_equals(ip.user_ns['g'], 20.0)
43 nt.assert_equals(ip.user_ns['g'], 20.0)
44
43 45
44 46
45 47
@@ -148,6 +148,7 have['wx'] = test_for('wx')
148 148 have['wx.aui'] = test_for('wx.aui')
149 149 have['qt'] = test_for('IPython.external.qt')
150 150 have['sqlite3'] = test_for('sqlite3')
151 have['cython'] = test_for('Cython')
151 152
152 153 have['tornado'] = test_for('tornado.version_info', (2,1,0), callback=None)
153 154
@@ -268,6 +269,9 def make_exclude():
268 269 ipjoin('zmq', 'pylab'),
269 270 ])
270 271
272 if not have['cython']:
273 exclusions.extend([ipjoin('extensions', 'cythonmagic')])
274
271 275 if not have['tornado']:
272 276 exclusions.append(ipjoin('frontend', 'html'))
273 277
@@ -71,6 +71,7 Extensions bundled with IPython
71 71 :maxdepth: 1
72 72
73 73 autoreload
74 cythonmagic
74 75 parallelmagic
75 76 storemagic
76 77 sympyprinting
General Comments 0
You need to be logged in to leave comments. Login now