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
Xavier Thompson
cython
Commits
7e233ab0
Commit
7e233ab0
authored
Sep 18, 2019
by
realead
Committed by
Stefan Behnel
Sep 18, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix the handling of --annotate-fullc in cythonize.py (GH-3103)
parent
cd031618
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
124 additions
and
26 deletions
+124
-26
Cython/Build/Cythonize.py
Cython/Build/Cythonize.py
+8
-6
Cython/Build/Tests/TestCythonizeArgsParser.py
Cython/Build/Tests/TestCythonizeArgsParser.py
+38
-0
Cython/Compiler/Tests/TestCmdLine.py
Cython/Compiler/Tests/TestCmdLine.py
+5
-20
Cython/Compiler/Tests/Utils.py
Cython/Compiler/Tests/Utils.py
+36
-0
runtests.py
runtests.py
+1
-0
tests/build/cythonize_with_annotate_via_cli.srctree
tests/build/cythonize_with_annotate_via_cli.srctree
+36
-0
No files found.
Cython/Build/Cythonize.py
View file @
7e233ab0
...
...
@@ -192,6 +192,7 @@ def parse_args_raw(parser, args):
def
parse_args
(
args
):
parser
=
create_args_parser
()
options
,
args
=
parse_args_raw
(
parser
,
args
)
if
not
args
:
parser
.
error
(
"no source files provided"
)
if
options
.
build_inplace
:
...
...
@@ -201,11 +202,6 @@ def parse_args(args):
if
options
.
language_level
:
assert
options
.
language_level
in
(
2
,
3
,
'3str'
)
options
.
options
[
'language_level'
]
=
options
.
language_level
return
options
,
args
def
main
(
args
=
None
):
options
,
paths
=
parse_args
(
args
)
if
options
.
lenient
:
# increase Python compatibility by ignoring compile time errors
...
...
@@ -213,11 +209,17 @@ def main(args=None):
Options
.
error_on_uninitialized
=
False
if
options
.
annotate
:
Options
.
annotate
=
Tru
e
Options
.
annotate
=
options
.
annotat
e
if
options
.
no_docstrings
:
Options
.
docstrings
=
False
return
options
,
args
def
main
(
args
=
None
):
options
,
paths
=
parse_args
(
args
)
for
path
in
paths
:
cython_compile
(
path
,
options
)
...
...
Cython/Build/Tests/TestCythonizeArgsParser.py
View file @
7e233ab0
...
...
@@ -2,6 +2,10 @@ from Cython.Build.Cythonize import (
create_args_parser
,
parse_args_raw
,
parse_args
,
parallel_compiles
)
from
Cython.Compiler
import
Options
from
Cython.Compiler.Tests.Utils
import
backup_Options
,
restore_Options
,
check_global_options
from
unittest
import
TestCase
import
sys
...
...
@@ -438,7 +442,41 @@ class TestCythonizeArgsParser(TestCase):
class
TestParseArgs
(
TestCase
):
def
setUp
(
self
):
self
.
_options_backup
=
backup_Options
()
def
tearDown
(
self
):
restore_Options
(
self
.
_options_backup
)
def
check_default_global_options
(
self
,
white_list
=
[]):
self
.
assertEqual
(
check_global_options
(
self
.
_options_backup
,
white_list
),
""
)
def
test_build_set_for_inplace
(
self
):
options
,
args
=
parse_args
([
'foo.pyx'
,
'-i'
])
self
.
assertEqual
(
options
.
build
,
True
)
self
.
check_default_global_options
()
def
test_lenient
(
self
):
options
,
sources
=
parse_args
([
'foo.pyx'
,
'--lenient'
])
self
.
assertEqual
(
sources
,
[
'foo.pyx'
])
self
.
assertEqual
(
Options
.
error_on_unknown_names
,
False
)
self
.
assertEqual
(
Options
.
error_on_uninitialized
,
False
)
self
.
check_default_global_options
([
'error_on_unknown_names'
,
'error_on_uninitialized'
])
def
test_annotate
(
self
):
options
,
sources
=
parse_args
([
'foo.pyx'
,
'--annotate'
])
self
.
assertEqual
(
sources
,
[
'foo.pyx'
])
self
.
assertEqual
(
Options
.
annotate
,
'default'
)
self
.
check_default_global_options
([
'annotate'
])
def
test_annotate_fullc
(
self
):
options
,
sources
=
parse_args
([
'foo.pyx'
,
'--annotate-fullc'
])
self
.
assertEqual
(
sources
,
[
'foo.pyx'
])
self
.
assertEqual
(
Options
.
annotate
,
'fullc'
)
self
.
check_default_global_options
([
'annotate'
])
def
test_no_docstrings
(
self
):
options
,
sources
=
parse_args
([
'foo.pyx'
,
'--no-docstrings'
])
self
.
assertEqual
(
sources
,
[
'foo.pyx'
])
self
.
assertEqual
(
Options
.
docstrings
,
False
)
self
.
check_default_global_options
([
'docstrings'
])
Cython/Compiler/Tests/TestCmdLine.py
View file @
7e233ab0
import
os
import
sys
import
copy
from
unittest
import
TestCase
try
:
from
StringIO
import
StringIO
...
...
@@ -10,32 +9,18 @@ except ImportError:
from
..
import
Options
from
..CmdLine
import
parse_command_line
from
.Utils
import
backup_Options
,
restore_Options
,
check_global_options
class
CmdLineParserTest
(
TestCase
):
def
setUp
(
self
):
backup
=
{}
for
name
,
value
in
vars
(
Options
).
items
():
# we need a deep copy of _directive_defaults, because they can be changed
if
name
==
'_directive_defaults'
:
value
=
copy
.
deepcopy
(
value
)
backup
[
name
]
=
value
self
.
_options_backup
=
backup
self
.
_options_backup
=
backup_Options
()
def
tearDown
(
self
):
no_value
=
object
()
for
name
,
orig_value
in
self
.
_options_backup
.
items
():
if
getattr
(
Options
,
name
,
no_value
)
!=
orig_value
:
setattr
(
Options
,
name
,
orig_value
)
# strip Options from new keys that might have been added:
for
name
in
vars
(
Options
).
keys
():
if
name
not
in
self
.
_options_backup
:
delattr
(
Options
,
name
)
restore_Options
(
self
.
_options_backup
)
def
check_default_global_options
(
self
,
white_list
=
[]):
no_value
=
object
()
for
name
,
orig_value
in
self
.
_options_backup
.
items
():
if
name
not
in
white_list
:
self
.
assertEqual
(
getattr
(
Options
,
name
,
no_value
),
orig_value
,
msg
=
"error in option "
+
name
)
self
.
assertEqual
(
check_global_options
(
self
.
_options_backup
,
white_list
),
""
)
def
check_default_options
(
self
,
options
,
white_list
=
[]):
default_options
=
Options
.
CompilationOptions
(
Options
.
default_options
)
...
...
Cython/Compiler/Tests/Utils.py
0 → 100644
View file @
7e233ab0
import
copy
from
..
import
Options
def
backup_Options
():
backup
=
{}
for
name
,
value
in
vars
(
Options
).
items
():
# we need a deep copy of _directive_defaults, because they can be changed
if
name
==
'_directive_defaults'
:
value
=
copy
.
deepcopy
(
value
)
backup
[
name
]
=
value
return
backup
def
restore_Options
(
backup
):
no_value
=
object
()
for
name
,
orig_value
in
backup
.
items
():
if
getattr
(
Options
,
name
,
no_value
)
!=
orig_value
:
setattr
(
Options
,
name
,
orig_value
)
# strip Options from new keys that might have been added:
for
name
in
vars
(
Options
).
keys
():
if
name
not
in
backup
:
delattr
(
Options
,
name
)
def
check_global_options
(
expected_options
,
white_list
=
[]):
"""
returns error message of "" if check Ok
"""
no_value
=
object
()
for
name
,
orig_value
in
expected_options
.
items
():
if
name
not
in
white_list
:
if
getattr
(
Options
,
name
,
no_value
)
!=
orig_value
:
return
"error in option "
+
name
return
""
runtests.py
View file @
7e233ab0
...
...
@@ -1760,6 +1760,7 @@ class EndToEndTest(unittest.TestCase):
def runTest(self):
self.success = False
commands = (self.commands
.replace("CYTHONIZE", "PYTHON %s" % os.path.join(self.cython_root, 'cythonize.py'))
.replace("CYTHON", "PYTHON %s" % os.path.join(self.cython_root, 'cython.py'))
.replace("PYTHON", sys.executable))
old_path = os.environ.get('PYTHONPATH')
...
...
tests/build/cythonize_with_annotate_via_cli.srctree
0 → 100644
View file @
7e233ab0
CYTHONIZE -i -3 not_annotated.pyx
PYTHON -c "import not_annotated; not_annotated.check()"
CYTHONIZE -i -3 --annotate default_annotated.pyx
PYTHON -c "import default_annotated; default_annotated.check()"
CYTHONIZE -i -3 --annotate-fullc fullc_annotated.pyx
PYTHON -c "import fullc_annotated; fullc_annotated.check()"
######## not_annotated.pyx ########
# check that html-file doesn't exist:
def check():
import os.path as os_path
assert not os_path.isfile(__name__+'.html')
######## default_annotated.pyx ########
# load html-site and check that the marker isn't there:
def check():
from codecs import open
with open(__name__+'.html', 'r', 'utf8') as html_file:
html = html_file.read()
from Cython.Compiler.Annotate import AnnotationCCodeWriter
assert (AnnotationCCodeWriter.COMPLETE_CODE_TITLE not in html) # per default no complete c code
######## fullc_annotated.pyx ########
# load html-site and check that the marker is there:
def check():
from codecs import open
with open(__name__+'.html', 'r', 'utf8') as html_file:
html = html_file.read()
from Cython.Compiler.Annotate import AnnotationCCodeWriter
assert (AnnotationCCodeWriter.COMPLETE_CODE_TITLE in html)
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