Show More
@@ -90,7 +90,7 b' class CythonMagics(Magics):' | |||||
90 | if not module_name: |
|
90 | if not module_name: | |
91 | raise ValueError('module name must be given') |
|
91 | raise ValueError('module name must be given') | |
92 | fname = module_name + '.pyx' |
|
92 | fname = module_name + '.pyx' | |
93 |
with open(fname, 'w') |
|
93 | with io.open(fname, 'w', encoding='utf-8'): | |
94 | f.write(cell) |
|
94 | f.write(cell) | |
95 | if 'pyximport' not in sys.modules: |
|
95 | if 'pyximport' not in sys.modules: | |
96 | import pyximport |
|
96 | import pyximport | |
@@ -113,7 +113,7 b' class CythonMagics(Magics):' | |||||
113 | """Compile and import everything from a Cython code cell. |
|
113 | """Compile and import everything from a Cython code cell. | |
114 |
|
114 | |||
115 | The contents of the cell are written to a `.pyx` file in the |
|
115 | The contents of the cell are written to a `.pyx` file in the | |
116 |
|
|
116 | directory `IPYTHONDIR/cython` using a filename with the hash of the code. | |
117 | This file is then cythonized and compiled. The resulting module |
|
117 | This file is then cythonized and compiled. The resulting module | |
118 | is imported and all of its symbols are injected into the user's |
|
118 | is imported and all of its symbols are injected into the user's | |
119 | namespace. The usage is similar to that of `%%cython_pyximport` but |
|
119 | namespace. The usage is similar to that of `%%cython_pyximport` but | |
@@ -125,7 +125,8 b' class CythonMagics(Magics):' | |||||
125 | """ |
|
125 | """ | |
126 | args = parse_argstring(self.cython, line) |
|
126 | args = parse_argstring(self.cython, line) | |
127 | code = cell if cell.endswith('\n') else cell+'\n' |
|
127 | code = cell if cell.endswith('\n') else cell+'\n' | |
128 | lib_dir=os.path.expanduser('~/.cython/magic') |
|
128 | # distutils.Extension cannot handle sources that a unicode | |
|
129 | lib_dir=str(os.path.join(self.shell.ipython_dir,'cython')) | |||
129 | cython_include_dirs=['.'] |
|
130 | cython_include_dirs=['.'] | |
130 | force=args.force |
|
131 | force=args.force | |
131 | quiet=True |
|
132 | quiet=True | |
@@ -145,8 +146,9 b' class CythonMagics(Magics):' | |||||
145 | import numpy |
|
146 | import numpy | |
146 | c_include_dirs.append(numpy.get_include()) |
|
147 | c_include_dirs.append(numpy.get_include()) | |
147 | pyx_file = os.path.join(lib_dir, module_name + '.pyx') |
|
148 | pyx_file = os.path.join(lib_dir, module_name + '.pyx') | |
148 |
with open(pyx_file, 'w') |
|
149 | with io.open(pyx_file, 'w', encoding='utf-8'): | |
149 | f.write(code) |
|
150 | f.write(code) | |
|
151 | print [pyx_file] | |||
150 | extension = Extension( |
|
152 | extension = Extension( | |
151 | name = module_name, |
|
153 | name = module_name, | |
152 | sources = [pyx_file], |
|
154 | sources = [pyx_file], |
General Comments 0
You need to be logged in to leave comments.
Login now