##// END OF EJS Templates
Add support for libraries, include path and compiler args to %%cython...
Fernando Perez -
Show More
@@ -107,6 +107,18 b' class CythonMagics(Magics):'
107
107
108 @magic_arguments()
108 @magic_arguments()
109 @argument(
109 @argument(
110 '-c', '--compile-args', action='append', default=[],
111 help="Extra flag to pass to compiler via the `extra_compile_args` Extension flag (can be called multiple times)."
112 )
113 @argument(
114 '-l', '--lib', action='append', default=[],
115 help="Add a library to link the extension against (can be called multiple times)."
116 )
117 @argument(
118 '-i', '--include', action='append', default=[],
119 help="Add a path to the list of include directories (can be called multiple times)."
120 )
121 @argument(
110 '-f', '--force', action='store_true', default=False,
122 '-f', '--force', action='store_true', default=False,
111 help="Force the compilation of the pyx module even if it hasn't changed"
123 help="Force the compilation of the pyx module even if it hasn't changed"
112 )
124 )
@@ -127,10 +139,10 b' class CythonMagics(Magics):'
127 """
139 """
128 args = parse_argstring(self.cython, line)
140 args = parse_argstring(self.cython, line)
129 code = cell if cell.endswith('\n') else cell+'\n'
141 code = cell if cell.endswith('\n') else cell+'\n'
130 lib_dir=os.path.join(self.shell.ipython_dir, 'cython')
142 lib_dir = os.path.join(self.shell.ipython_dir, 'cython')
131 cython_include_dirs=['.']
143 cython_include_dirs = ['.']
132 force=args.force
144 force = args.force
133 quiet=True
145 quiet = True
134 ctx = Context(cython_include_dirs, default_options)
146 ctx = Context(cython_include_dirs, default_options)
135 key = code, sys.version_info, sys.executable, Cython.__version__
147 key = code, sys.version_info, sys.executable, Cython.__version__
136 module_name = "_cython_magic_" + hashlib.md5(str(key).encode('utf-8')).hexdigest()
148 module_name = "_cython_magic_" + hashlib.md5(str(key).encode('utf-8')).hexdigest()
@@ -141,8 +153,7 b' class CythonMagics(Magics):'
141 os.makedirs(lib_dir)
153 os.makedirs(lib_dir)
142
154
143 if force or not os.path.isfile(module_path):
155 if force or not os.path.isfile(module_path):
144 cflags = []
156 c_include_dirs = args.include
145 c_include_dirs = []
146 if 'numpy' in code:
157 if 'numpy' in code:
147 import numpy
158 import numpy
148 c_include_dirs.append(numpy.get_include())
159 c_include_dirs.append(numpy.get_include())
@@ -154,7 +165,8 b' class CythonMagics(Magics):'
154 name = module_name,
165 name = module_name,
155 sources = [pyx_file],
166 sources = [pyx_file],
156 include_dirs = c_include_dirs,
167 include_dirs = c_include_dirs,
157 extra_compile_args = cflags
168 extra_compile_args = args.compile_args,
169 libraries = args.lib,
158 )
170 )
159 dist = Distribution()
171 dist = Distribution()
160 config_files = dist.find_config_files()
172 config_files = dist.find_config_files()
General Comments 0
You need to be logged in to leave comments. Login now