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
8 years ago
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support "%%cython -3" cell magic in IPython
parent
7fa11da9
master
nogil_cypclass_acthon_on_rc8v3
snippets_article
nogil_cypclass_rc8
nogil_cypclass_lock_on_rc8v3
No related merge requests found
Changes
2
Show 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
...
...
This diff is collapsed.
Click to expand it.
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
(
"""
...
...
This diff is collapsed.
Click to expand it.
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