@@ -12,18 +12,17 @@ import subprocess
12
12
13
13
14
14
def parse_args (args = None ):
15
- import argparse
16
- parser = argparse .ArgumentParser (description = 'Run a Python command line with Cython' )
17
- parser .add_argument ('-c' , metavar = 'CODE' , dest = 'command' ,
18
- help = 'program passed in as string' )
19
- parser .add_argument ('--python' , metavar = 'PYTHON' , dest = 'python' , default = sys .executable ,
20
- help = 'Python interpreter to use' )
21
- parser .add_argument ('-X' , metavar = 'NAME=VALUE' , dest = 'directives' , action = 'append' ,
22
- help = 'Compiler directives to set during compilation' )
23
- parser .add_argument ('-V' , '--version' , action = 'store_true' ,
24
- help = 'print the Python and Cython version numbers and exit' )
25
- parser .add_argument ('file_args' , nargs = '*' ,
26
- help = 'program read from script file' )
15
+ import optparse # tried argparse, but it doesn't stop at the first (interspersed) positional argument
16
+ parser = optparse .OptionParser (description = 'Run a Python command line with Cython' )
17
+ parser .disable_interspersed_args ()
18
+ parser .add_option ('-c' , metavar = 'CODE' , dest = 'command' ,
19
+ help = 'program passed in as string' )
20
+ parser .add_option ('--python' , metavar = 'PYTHON' , dest = 'python' , default = sys .executable ,
21
+ help = 'Python interpreter to use' )
22
+ parser .add_option ('-X' , metavar = 'NAME=VALUE' , dest = 'directives' , action = 'append' ,
23
+ help = 'Compiler directives to set during compilation' )
24
+ parser .add_option ('-V' , '--version' , action = 'store_true' ,
25
+ help = 'print the Python and Cython version numbers and exit' )
27
26
28
27
return parser .parse_args (args )
29
28
@@ -86,21 +85,21 @@ def run_python_file(python, file_args, directives=None):
86
85
87
86
88
87
def main ():
89
- args = parse_args ()
90
- python = args .python
88
+ options , args = parse_args ()
89
+ python = options .python
91
90
92
- if args .version :
91
+ if options .version :
93
92
print_versions (python )
94
93
return
95
94
96
- if args .command :
97
- run_cython_command (python , args .command , args . file_args )
95
+ if options .command :
96
+ run_cython_command (python , options .command , args )
98
97
99
- if args . file_args :
100
- if args . file_args [0 ] == '-' :
101
- run_python_stdin (python , args . file_args [1 :], args .directives )
98
+ if args :
99
+ if args [0 ] == '-' :
100
+ run_python_stdin (python , args [1 :], options .directives )
102
101
else :
103
- run_python_file (python , args . file_args , args .directives )
102
+ run_python_file (python , args , options .directives )
104
103
105
104
106
105
if __name__ == '__main__' :
0 commit comments