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
Boxiang Sun
cython
Commits
a4440014
Commit
a4440014
authored
Jul 17, 2016
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
automatically enable language level 3 if jupyter kernel uses Python 3
parent
95768141
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
6 deletions
+23
-6
CHANGES.rst
CHANGES.rst
+4
-0
Cython/Build/IpythonMagic.py
Cython/Build/IpythonMagic.py
+10
-3
Cython/Build/Tests/TestIpythonMagic.py
Cython/Build/Tests/TestIpythonMagic.py
+9
-3
No files found.
CHANGES.rst
View file @
a4440014
...
@@ -53,6 +53,10 @@ Bugs fixed
...
@@ -53,6 +53,10 @@ Bugs fixed
Other changes
Other changes
-------------
-------------
* The "%%cython" IPython/jupyter magic now defaults to the language level of
the current jupyter kernel. The language level can be set explicitly with
"%%cython -2" or "%%cython -3".
* Usage of ``Cython.Distutils.build_ext`` is now discouraged.
* Usage of ``Cython.Distutils.build_ext`` is now discouraged.
...
...
Cython/Build/IpythonMagic.py
View file @
a4440014
...
@@ -152,8 +152,12 @@ class CythonMagics(Magics):
...
@@ -152,8 +152,12 @@ class CythonMagics(Magics):
@
magic_arguments
.
magic_arguments
()
@
magic_arguments
.
magic_arguments
()
@
magic_arguments
.
argument
(
@
magic_arguments
.
argument
(
'-3'
,
dest
=
'cython3'
,
action
=
'store_true'
,
default
=
False
,
'-3'
,
dest
=
'language_level'
,
action
=
'store_const'
,
const
=
3
,
default
=
None
,
help
=
"Switch to Python 3 syntax."
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
(
@
magic_arguments
.
argument
(
'-c'
,
'--compile-args'
,
action
=
'append'
,
default
=
[],
'-c'
,
'--compile-args'
,
action
=
'append'
,
default
=
[],
...
@@ -272,7 +276,10 @@ class CythonMagics(Magics):
...
@@ -272,7 +276,10 @@ class CythonMagics(Magics):
annotate
=
args
.
annotate
,
annotate
=
args
.
annotate
,
force
=
True
,
force
=
True
,
)
)
if
args
.
cython3
:
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
opts
[
'language_level'
]
=
3
build_extension
.
extensions
=
cythonize
([
extension
],
**
opts
)
build_extension
.
extensions
=
cythonize
([
extension
],
**
opts
)
except
CompileError
:
except
CompileError
:
...
...
Cython/Build/Tests/TestIpythonMagic.py
View file @
a4440014
...
@@ -28,7 +28,7 @@ def f(x):
...
@@ -28,7 +28,7 @@ def f(x):
"""
)
"""
)
cython3_code
=
py3compat
.
str_to_unicode
(
"""
\
cython3_code
=
py3compat
.
str_to_unicode
(
"""
\
def f(x):
def f(
int
x):
return 2 / x
return 2 / x
def call(x):
def call(x):
...
@@ -87,13 +87,19 @@ class TestIPythonMagic(CythonTest):
...
@@ -87,13 +87,19 @@ class TestIPythonMagic(CythonTest):
self
.
assertEqual
(
ip
.
user_ns
[
'g'
],
20.0
)
self
.
assertEqual
(
ip
.
user_ns
[
'g'
],
20.0
)
def
test_cython3
(
self
):
def
test_cython3
(
self
):
# The Cython
module named 'mymodule' defines the function f
.
# The Cython
cell defines the functions f() and call()
.
ip
.
run_cell_magic
(
'cython'
,
'-3'
,
cython3_code
)
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)'
)
ip
.
ex
(
'g = f(10); h = call(10)'
)
self
.
assertEqual
(
ip
.
user_ns
[
'g'
],
2.0
/
10.0
)
self
.
assertEqual
(
ip
.
user_ns
[
'g'
],
2.0
/
10.0
)
self
.
assertEqual
(
ip
.
user_ns
[
'h'
],
2.0
/
10.0
)
self
.
assertEqual
(
ip
.
user_ns
[
'h'
],
2.0
/
10.0
)
def
test_cython2
(
self
):
# The Cython cell defines the functions f() and call().
ip
.
run_cell_magic
(
'cython'
,
'-2'
,
cython3_code
)
ip
.
ex
(
'g = f(10); h = call(10)'
)
self
.
assertEqual
(
ip
.
user_ns
[
'g'
],
2
//
10
)
self
.
assertEqual
(
ip
.
user_ns
[
'h'
],
2
//
10
)
@
skip_win32
@
skip_win32
def
test_extlibs
(
self
):
def
test_extlibs
(
self
):
code
=
py3compat
.
str_to_unicode
(
"""
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