Skip to content

Commit 1851621

Browse files
committed
let pcython script parse the main script arguments and pass them on instead of incorrectly rejecting them as unknown
1 parent bd412b8 commit 1851621

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

bin/pcython

+20-21
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@ import subprocess
1212

1313

1414
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')
2726

2827
return parser.parse_args(args)
2928

@@ -86,21 +85,21 @@ def run_python_file(python, file_args, directives=None):
8685

8786

8887
def main():
89-
args = parse_args()
90-
python = args.python
88+
options, args = parse_args()
89+
python = options.python
9190

92-
if args.version:
91+
if options.version:
9392
print_versions(python)
9493
return
9594

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)
9897

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)
102101
else:
103-
run_python_file(python, args.file_args, args.directives)
102+
run_python_file(python, args, options.directives)
104103

105104

106105
if __name__ == '__main__':

0 commit comments

Comments
 (0)