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
Kirill Smelkov
cython
Commits
80e05d82
Commit
80e05d82
authored
May 15, 2019
by
Egor Dranischnikow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
using argparse instead of optparse
parent
cec82f45
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
54 deletions
+54
-54
Cython/Build/Cythonize.py
Cython/Build/Cythonize.py
+54
-54
No files found.
Cython/Build/Cythonize.py
View file @
80e05d82
...
...
@@ -38,35 +38,6 @@ class _FakePool(object):
pass
def
parse_directives
(
option
,
name
,
value
,
parser
):
dest
=
option
.
dest
old_directives
=
dict
(
getattr
(
parser
.
values
,
dest
,
Options
.
get_directive_defaults
()))
directives
=
Options
.
parse_directive_list
(
value
,
relaxed_bool
=
True
,
current_settings
=
old_directives
)
setattr
(
parser
.
values
,
dest
,
directives
)
def
parse_options
(
option
,
name
,
value
,
parser
):
dest
=
option
.
dest
options
=
dict
(
getattr
(
parser
.
values
,
dest
,
{}))
for
opt
in
value
.
split
(
','
):
if
'='
in
opt
:
n
,
v
=
opt
.
split
(
'='
,
1
)
v
=
v
.
lower
()
not
in
(
'false'
,
'f'
,
'0'
,
'no'
)
else
:
n
,
v
=
opt
,
True
options
[
n
]
=
v
setattr
(
parser
.
values
,
dest
,
options
)
def
parse_compile_time_env
(
option
,
name
,
value
,
parser
):
dest
=
option
.
dest
old_env
=
dict
(
getattr
(
parser
.
values
,
dest
,
{}))
new_env
=
Options
.
parse_compile_time_env
(
value
,
current_settings
=
old_env
)
setattr
(
parser
.
values
,
dest
,
new_env
)
def
find_package_base
(
path
):
base_dir
,
package_path
=
os
.
path
.
split
(
path
)
while
is_package_dir
(
base_dir
):
...
...
@@ -149,58 +120,87 @@ def run_distutils(args):
def
create_args_parser
():
from
optparse
import
OptionParser
parser
=
OptionParser
(
usage
=
'%prog [options] [sources and packages]+'
)
from
argparse
import
ArgumentParser
,
Action
class
ParseDirectivesAction
(
Action
):
def
__call__
(
self
,
parser
,
namespace
,
values
,
option_string
=
None
):
old_directives
=
dict
(
getattr
(
namespace
,
self
.
dest
,
Options
.
get_directive_defaults
()))
directives
=
Options
.
parse_directive_list
(
values
,
relaxed_bool
=
True
,
current_settings
=
old_directives
)
setattr
(
namespace
,
self
.
dest
,
directives
)
class
ParseOptionsAction
(
Action
):
def
__call__
(
self
,
parser
,
namespace
,
values
,
option_string
=
None
):
options
=
dict
(
getattr
(
namespace
,
self
.
dest
,
{}))
for
opt
in
values
.
split
(
','
):
if
'='
in
opt
:
n
,
v
=
opt
.
split
(
'='
,
1
)
v
=
v
.
lower
()
not
in
(
'false'
,
'f'
,
'0'
,
'no'
)
else
:
n
,
v
=
opt
,
True
options
[
n
]
=
v
setattr
(
namespace
,
self
.
dest
,
options
)
class
ParseCompileTimeEnvAction
(
Action
):
def
__call__
(
self
,
parser
,
namespace
,
values
,
option_string
=
None
):
old_env
=
dict
(
getattr
(
namespace
,
self
.
dest
,
{}))
new_env
=
Options
.
parse_compile_time_env
(
values
,
current_settings
=
old_env
)
setattr
(
namespace
,
self
.
dest
,
new_env
)
parser
=
ArgumentParser
(
usage
=
'%(prog)s [options] [sources and packages]+'
)
parser
.
add_
option
(
'-X'
,
'--directive'
,
metavar
=
'NAME=VALUE,...'
,
dest
=
'directives'
,
default
=
{},
type
=
"str"
,
action
=
'callback'
,
callback
=
parse_directives
,
parser
.
add_
argument
(
'-X'
,
'--directive'
,
metavar
=
'NAME=VALUE,...'
,
dest
=
'directives'
,
default
=
{},
type
=
str
,
action
=
ParseDirectivesAction
,
help
=
'set a compiler directive'
)
parser
.
add_
option
(
'-E'
,
'--compile-time-env'
,
metavar
=
'NAME=VALUE,...'
,
dest
=
'compile_time_env'
,
default
=
{},
type
=
"str"
,
action
=
'callback'
,
callback
=
parse_compile_time_env
,
parser
.
add_
argument
(
'-E'
,
'--compile-time-env'
,
metavar
=
'NAME=VALUE,...'
,
dest
=
'compile_time_env'
,
default
=
{},
type
=
str
,
action
=
ParseCompileTimeEnvAction
,
help
=
'set a compile time environment variable'
)
parser
.
add_
option
(
'-s'
,
'--option'
,
metavar
=
'NAME=VALUE'
,
dest
=
'options'
,
default
=
{},
type
=
"str"
,
action
=
'callback'
,
callback
=
parse_options
,
parser
.
add_
argument
(
'-s'
,
'--option'
,
metavar
=
'NAME=VALUE'
,
dest
=
'options'
,
default
=
{},
type
=
str
,
action
=
ParseOptionsAction
,
help
=
'set a cythonize option'
)
parser
.
add_
option
(
'-2'
,
dest
=
'language_level'
,
action
=
'store_const'
,
const
=
2
,
default
=
None
,
parser
.
add_
argument
(
'-2'
,
dest
=
'language_level'
,
action
=
'store_const'
,
const
=
2
,
default
=
None
,
help
=
'use Python 2 syntax mode by default'
)
parser
.
add_
option
(
'-3'
,
dest
=
'language_level'
,
action
=
'store_const'
,
const
=
3
,
parser
.
add_
argument
(
'-3'
,
dest
=
'language_level'
,
action
=
'store_const'
,
const
=
3
,
help
=
'use Python 3 syntax mode by default'
)
parser
.
add_
option
(
'--3str'
,
dest
=
'language_level'
,
action
=
'store_const'
,
const
=
'3str'
,
parser
.
add_
argument
(
'--3str'
,
dest
=
'language_level'
,
action
=
'store_const'
,
const
=
'3str'
,
help
=
'use Python 3 syntax mode by default'
)
parser
.
add_
option
(
'-a'
,
'--annotate'
,
dest
=
'annotate'
,
action
=
'store_true'
,
parser
.
add_
argument
(
'-a'
,
'--annotate'
,
dest
=
'annotate'
,
action
=
'store_true'
,
default
=
None
,
help
=
'generate annotated HTML page for source files'
)
parser
.
add_
option
(
'-x'
,
'--exclude'
,
metavar
=
'PATTERN'
,
dest
=
'excludes'
,
parser
.
add_
argument
(
'-x'
,
'--exclude'
,
metavar
=
'PATTERN'
,
dest
=
'excludes'
,
action
=
'append'
,
default
=
[],
help
=
'exclude certain file patterns from the compilation'
)
parser
.
add_
option
(
'-b'
,
'--build'
,
dest
=
'build'
,
action
=
'store_true'
,
parser
.
add_
argument
(
'-b'
,
'--build'
,
dest
=
'build'
,
action
=
'store_true'
,
default
=
None
,
help
=
'build extension modules using distutils'
)
parser
.
add_
option
(
'-i'
,
'--inplace'
,
dest
=
'build_inplace'
,
action
=
'store_true'
,
parser
.
add_
argument
(
'-i'
,
'--inplace'
,
dest
=
'build_inplace'
,
action
=
'store_true'
,
default
=
None
,
help
=
'build extension modules in place using distutils (implies -b)'
)
parser
.
add_
option
(
'-j'
,
'--parallel'
,
dest
=
'parallel'
,
metavar
=
'N'
,
parser
.
add_
argument
(
'-j'
,
'--parallel'
,
dest
=
'parallel'
,
metavar
=
'N'
,
type
=
int
,
default
=
parallel_compiles
,
help
=
(
'run builds in N parallel jobs (default: %d)'
%
parallel_compiles
or
1
))
parser
.
add_
option
(
'-f'
,
'--force'
,
dest
=
'force'
,
action
=
'store_true'
,
parser
.
add_
argument
(
'-f'
,
'--force'
,
dest
=
'force'
,
action
=
'store_true'
,
default
=
None
,
help
=
'force recompilation'
)
parser
.
add_
option
(
'-q'
,
'--quiet'
,
dest
=
'quiet'
,
action
=
'store_true'
,
parser
.
add_
argument
(
'-q'
,
'--quiet'
,
dest
=
'quiet'
,
action
=
'store_true'
,
default
=
None
,
help
=
'be less verbose during compilation'
)
parser
.
add_
option
(
'--lenient'
,
dest
=
'lenient'
,
action
=
'store_true'
,
parser
.
add_
argument
(
'--lenient'
,
dest
=
'lenient'
,
action
=
'store_true'
,
default
=
None
,
help
=
'increase Python compatibility by ignoring some compile time errors'
)
parser
.
add_
option
(
'-k'
,
'--keep-going'
,
dest
=
'keep_going'
,
action
=
'store_true'
,
parser
.
add_
argument
(
'-k'
,
'--keep-going'
,
dest
=
'keep_going'
,
action
=
'store_true'
,
default
=
None
,
help
=
'compile as much as possible, ignore compilation failures'
)
parser
.
add_
option
(
'--no-docstrings'
,
dest
=
'no_docstrings'
,
action
=
'store_true'
,
parser
.
add_
argument
(
'--no-docstrings'
,
dest
=
'no_docstrings'
,
action
=
'store_true'
,
default
=
None
,
help
=
'strip docstrings'
)
parser
.
add_argument
(
'sources'
,
nargs
=
'*'
)
return
parser
def
parse_args_raw
(
parser
,
args
):
return
parser
.
parse_args
(
args
)
options
=
parser
.
parse_args
(
args
)
return
(
options
,
options
.
sources
)
def
parse_args
(
args
):
...
...
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