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
838f26c9
Commit
838f26c9
authored
Jun 11, 2019
by
realead
Committed by
Stefan Behnel
Jun 11, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix interspersed positional arguments in cythonize.py (GH-2988)
parent
f46b869f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
3 deletions
+57
-3
Cython/Build/Cythonize.py
Cython/Build/Cythonize.py
+11
-2
Cython/Build/Tests/TestCythonizeArgsParser.py
Cython/Build/Tests/TestCythonizeArgsParser.py
+46
-1
No files found.
Cython/Build/Cythonize.py
View file @
838f26c9
...
...
@@ -201,8 +201,17 @@ def create_args_parser():
def
parse_args_raw
(
parser
,
args
):
options
=
parser
.
parse_args
(
args
)
return
(
options
,
options
.
sources
)
options
,
unknown
=
parser
.
parse_known_args
(
args
)
sources
=
options
.
sources
# if positional arguments were interspersed
# some of them are in unknown
for
option
in
unknown
:
if
option
.
startswith
(
'-'
):
parser
.
error
(
"unknown option "
+
option
)
else
:
sources
.
append
(
option
)
delattr
(
options
,
'sources'
)
return
(
options
,
sources
)
def
parse_args
(
args
):
...
...
Cython/Build/Tests/TestCythonizeArgsParser.py
View file @
838f26c9
...
...
@@ -4,7 +4,12 @@ from Cython.Build.Cythonize import (
)
from
unittest
import
TestCase
import
argparse
import
sys
try
:
from
StringIO
import
StringIO
except
ImportError
:
from
io
import
StringIO
# doesn't accept 'str' in Py2
class
TestCythonizeArgsParser
(
TestCase
):
...
...
@@ -392,6 +397,46 @@ class TestCythonizeArgsParser(TestCase):
self
.
assertEqual
(
options
.
build_inplace
,
True
)
self
.
assertTrue
(
self
.
are_default
(
options
,
[
'build_inplace'
]))
def
test_interspersed_positional
(
self
):
options
,
sources
=
self
.
parse_args
([
'file1.pyx'
,
'-a'
,
'file2.pyx'
])
self
.
assertEqual
(
sources
,
[
'file1.pyx'
,
'file2.pyx'
])
self
.
assertEqual
(
options
.
annotate
,
'default'
)
self
.
assertTrue
(
self
.
are_default
(
options
,
[
'annotate'
]))
def
test_interspersed_positional2
(
self
):
options
,
sources
=
self
.
parse_args
([
'file1.pyx'
,
'-a'
,
'file2.pyx'
,
'-a'
,
'file3.pyx'
])
self
.
assertEqual
(
sources
,
[
'file1.pyx'
,
'file2.pyx'
,
'file3.pyx'
])
self
.
assertEqual
(
options
.
annotate
,
'default'
)
self
.
assertTrue
(
self
.
are_default
(
options
,
[
'annotate'
]))
def
test_interspersed_positional3
(
self
):
options
,
sources
=
self
.
parse_args
([
'-f'
,
'f1'
,
'f2'
,
'-a'
,
'f3'
,
'f4'
,
'-a'
,
'f5'
])
self
.
assertEqual
(
sources
,
[
'f1'
,
'f2'
,
'f3'
,
'f4'
,
'f5'
])
self
.
assertEqual
(
options
.
annotate
,
'default'
)
self
.
assertEqual
(
options
.
force
,
True
)
self
.
assertTrue
(
self
.
are_default
(
options
,
[
'annotate'
,
'force'
]))
def
test_wrong_option
(
self
):
old_stderr
=
sys
.
stderr
stderr
=
sys
.
stderr
=
StringIO
()
try
:
self
.
assertRaises
(
SystemExit
,
self
.
parse_args
,
[
'--unknown-option'
]
)
finally
:
sys
.
stderr
=
old_stderr
self
.
assertTrue
(
stderr
.
getvalue
())
class
TestParseArgs
(
TestCase
):
def
test_build_set_for_inplace
(
self
):
...
...
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