From 0e0e6a8edd11040316ccc4c1d534b9868e960112 2013-09-21 08:59:35 From: Cyrille Rossant Date: 2013-09-21 08:59:35 Subject: [PATCH] The 'name' argument to the %%cython cell magic is no longer a list. Added test_cython_name. --- diff --git a/IPython/extensions/cythonmagic.py b/IPython/extensions/cythonmagic.py index f184a39..4c1d121 100644 --- a/IPython/extensions/cythonmagic.py +++ b/IPython/extensions/cythonmagic.py @@ -147,7 +147,7 @@ class CythonMagics(Magics): "multiple times)." ) @magic_arguments.argument( - '-n', '--name', action='append', default=[], + '-n', '--name', help="Specify a name for the Cython module." ) @magic_arguments.argument( @@ -209,7 +209,7 @@ class CythonMagics(Magics): key += time.time(), if args.name: - module_name = str(args.name[0]) + module_name = 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) diff --git a/IPython/extensions/tests/test_cythonmagic.py b/IPython/extensions/tests/test_cythonmagic.py index 36685e5..41dea38 100644 --- a/IPython/extensions/tests/test_cythonmagic.py +++ b/IPython/extensions/tests/test_cythonmagic.py @@ -50,6 +50,14 @@ def test_cython(): nt.assert_equal(ip.user_ns['g'], 20.0) +def test_cython_name(): + # The Cython module named 'mymodule' defines the function f. + ip.run_cell_magic('cython', '--name=mymodule', code) + # This module can now be imported in the interactive namespace. + ip.ex('import mymodule; g = mymodule.f(10)') + nt.assert_equal(ip.user_ns['g'], 20.0) + + @dec.skip_win32 def test_extlibs(): code = py3compat.str_to_unicode("""