'Compile and import everything from a Cython code cell.
The contents of the cell are written to a `.pyx` file in the
directory `IPYTHONDIR/cython` using a filename with the hash of the
code. This file is then cythonized and compiled. The resulting module
is imported and all of its symbols are injected into the user\'s
namespace. The usage is similar to that of `%%cython_pyximport` but
you don\'t have to pass a module name::
%%cython
def f(x):
return 2.0*x
To compile OpenMP codes, pass the required  `--compile-args`
and `--link-args`.  For example with gcc::
%%cython --compile-args=-fopenmp --link-args=-fopenmp'

@magic_arguments.magic_arguments()
@magic_arguments.argument('-3', dest='language_level', action='store_const', const=3, default=None, help='Select    Python    3    syntax.')
@magic_arguments.argument('-2', dest='language_level', action='store_const', const=2, default=None, help='Select    Python    2    syntax.')
@magic_arguments.argument('-c', '--compile-args', action='append', default=[], help='Extra    flags    to    pass    to    compiler    via    the    `extra_compile_args`    Extension    flag    (can    be    specified        multiple    times).')
@magic_arguments.argument('--link-args', action='append', default=[], help='Extra    flags    to    pass    to    linker    via    the    `extra_link_args`    Extension    flag    (can    be    specified        multiple    times).')
@magic_arguments.argument('-l', '--lib', action='append', default=[], help='Add    a    library    to    link    the    extension    against    (can    be    specified    multiple    times).')
@magic_arguments.argument('-n', '--name', help='Specify    a    name    for    the    Cython    module.')
@magic_arguments.argument('-L', dest='library_dirs', metavar='dir', action='append', default=[], help='Add    a    path    to    the    list    of    library    directories    (can    be    specified    multiple    times).')
@magic_arguments.argument('-I', '--include', action='append', default=[], help='Add    a    path    to    the    list    of    include    directories    (can    be    specified    multiple    times).')
@magic_arguments.argument('-S', '--src', action='append', default=[], help='Add    a    path    to    the    list    of    src    files    (can    be    specified    multiple    times).')
@magic_arguments.argument('-+', '--cplus', action='store_true', default=False, help='Output    a    C++    rather    than    C    file.')
@magic_arguments.argument('-f', '--force', action='store_true', default=False, help='Force    the    compilation    of    a    new    module,    even    if    the    source    has    been    previously    compiled.')
@magic_arguments.argument('-a', '--annotate', action='store_true', default=False, help='Produce    a    colorized    HTML    version    of    the    source.')
@cell_magic
def cython(self, line, cell):

    args = magic_arguments.parse_argstring(self.cython, line)
    code = (cell if cell.endswith('\n') else (cell + '\n'))
    lib_dir = os.path.join(get_ipython_cache_dir(), 'cython')
    quiet = True
    key = (code, line, sys.version_info, sys.executable, cython_version)
    if (not os.path.exists(lib_dir)):
        os.makedirs(lib_dir)
    if args.force:
        key += (time.time(),)
    if args.name:
        module_name = py3compat.unicode_to_str(args.name)
    else:
        module_name = ('_cython_magic_' + hashlib.md5(str(key).encode('utf-8')).hexdigest())
    module_path = os.path.join(lib_dir, (module_name + self.so_ext))
    have_module = os.path.isfile(module_path)
    need_cythonize = (not have_module)
    if args.annotate:
        html_file = os.path.join(lib_dir, (module_name + '.html'))
        if (not os.path.isfile(html_file)):
            need_cythonize = True
    if need_cythonize:
        c_include_dirs = args.include
        c_src_files = list(map(str, args.src))
        if ('numpy' in code):
            import numpy
            c_include_dirs.append(numpy.get_include())
        pyx_file = os.path.join(lib_dir, (module_name + '.pyx'))
        pyx_file = py3compat.cast_bytes_py2(pyx_file, encoding=sys.getfilesystemencoding())
        with io.open(pyx_file, 'w', encoding='utf-8') as f:
            f.write(code)
        extension = Extension(name=module_name, sources=([pyx_file] + c_src_files), include_dirs=c_include_dirs, library_dirs=args.library_dirs, extra_compile_args=args.compile_args, extra_link_args=args.link_args, libraries=args.lib, language=('c++' if args.cplus else 'c'))
        build_extension = self._get_build_extension()
        try:
            opts = dict(quiet=quiet, annotate=args.annotate, force=True)
            if (args.language_level is not None):
                assert (args.language_level in (2, 3))
                opts['language_level'] = args.language_level
            elif (sys.version_info[0] > 2):
                opts['language_level'] = 3
            build_extension.extensions = cythonize([extension], **opts)
        except CompileError:
            return
    if (not have_module):
        build_extension.build_temp = os.path.dirname(pyx_file)
        build_extension.build_lib = lib_dir
        build_extension.run()
        self._code_cache[key] = module_name
    module = imp.load_dynamic(module_name, module_path)
    self._import_all(module)
    if args.annotate:
        try:
            with io.open(html_file, encoding='utf-8') as f:
                annotated_html = f.read()
        except IOError as e:
            print('Cython    completed    successfully    but    the    annotated    source    could    not    be    read.', file=sys.stderr)
            print(e, file=sys.stderr)
        else:
            return display.HTML(self.clean_annotated_html(annotated_html))
