Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
b5846e0c
Commit
b5846e0c
authored
Jul 08, 2016
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support "%%cython -3" cell magic in IPython
parent
7fa11da9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
4 deletions
+27
-4
Cython/Build/IpythonMagic.py
Cython/Build/IpythonMagic.py
+9
-3
Cython/Build/Tests/TestIpythonMagic.py
Cython/Build/Tests/TestIpythonMagic.py
+18
-1
No files found.
Cython/Build/IpythonMagic.py
View file @
b5846e0c
...
...
@@ -151,6 +151,10 @@ class CythonMagics(Magics):
self
.
_import_all
(
module
)
@
magic_arguments
.
magic_arguments
()
@
magic_arguments
.
argument
(
'-3'
,
dest
=
'cython3'
,
action
=
'store_true'
,
default
=
False
,
help
=
"Switch to Python 3 syntax."
)
@
magic_arguments
.
argument
(
'-c'
,
'--compile-args'
,
action
=
'append'
,
default
=
[],
help
=
"Extra flags to pass to compiler via the `extra_compile_args` "
...
...
@@ -265,9 +269,11 @@ class CythonMagics(Magics):
try
:
opts
=
dict
(
quiet
=
quiet
,
annotate
=
args
.
annotate
,
force
=
True
,
)
annotate
=
args
.
annotate
,
force
=
True
,
)
if
args
.
cython3
:
opts
[
'language_level'
]
=
3
build_extension
.
extensions
=
cythonize
([
extension
],
**
opts
)
except
CompileError
:
return
...
...
Cython/Build/Tests/TestIpythonMagic.py
View file @
b5846e0c
...
...
@@ -22,10 +22,19 @@ except ImportError:
from
Cython.TestUtils
import
CythonTest
ip
=
get_ipython
()
code
=
py3compat
.
str_to_unicode
(
"""def f(x):
code
=
py3compat
.
str_to_unicode
(
"""
\
def f(x):
return 2*x
"""
)
cython3_code
=
py3compat
.
str_to_unicode
(
"""
\
def f(x):
return 2 / x
def call(x):
return f(*(x,))
"""
)
if
sys
.
platform
==
'win32'
:
# not using IPython's decorators here because they depend on "nose"
...
...
@@ -77,6 +86,14 @@ class TestIPythonMagic(CythonTest):
ip
.
ex
(
'import mymodule; g = mymodule.f(10)'
)
self
.
assertEqual
(
ip
.
user_ns
[
'g'
],
20.0
)
def
test_cython3
(
self
):
# The Cython module named 'mymodule' defines the function f.
ip
.
run_cell_magic
(
'cython'
,
'-3'
,
cython3_code
)
# This module can now be imported in the interactive namespace.
ip
.
ex
(
'g = f(10); h = call(10)'
)
self
.
assertEqual
(
ip
.
user_ns
[
'g'
],
2.0
/
10.0
)
self
.
assertEqual
(
ip
.
user_ns
[
'h'
],
2.0
/
10.0
)
@
skip_win32
def
test_extlibs
(
self
):
code
=
py3compat
.
str_to_unicode
(
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment