Commit 18516214 authored by Stefan Behnel's avatar Stefan Behnel

let pcython script parse the main script arguments and pass them on instead of...

let pcython script parse the main script arguments and pass them on instead of incorrectly rejecting them as unknown
parent bd412b84
...@@ -12,18 +12,17 @@ import subprocess ...@@ -12,18 +12,17 @@ import subprocess
def parse_args(args=None): def parse_args(args=None):
import argparse import optparse # tried argparse, but it doesn't stop at the first (interspersed) positional argument
parser = argparse.ArgumentParser(description='Run a Python command line with Cython') parser = optparse.OptionParser(description='Run a Python command line with Cython')
parser.add_argument('-c', metavar='CODE', dest='command', parser.disable_interspersed_args()
help='program passed in as string') parser.add_option('-c', metavar='CODE', dest='command',
parser.add_argument('--python', metavar='PYTHON', dest='python', default=sys.executable, help='program passed in as string')
help='Python interpreter to use') parser.add_option('--python', metavar='PYTHON', dest='python', default=sys.executable,
parser.add_argument('-X', metavar='NAME=VALUE', dest='directives', action='append', help='Python interpreter to use')
help='Compiler directives to set during compilation') parser.add_option('-X', metavar='NAME=VALUE', dest='directives', action='append',
parser.add_argument('-V', '--version', action='store_true', help='Compiler directives to set during compilation')
help='print the Python and Cython version numbers and exit') parser.add_option('-V', '--version', action='store_true',
parser.add_argument('file_args', nargs='*', help='print the Python and Cython version numbers and exit')
help='program read from script file')
return parser.parse_args(args) return parser.parse_args(args)
...@@ -86,21 +85,21 @@ def run_python_file(python, file_args, directives=None): ...@@ -86,21 +85,21 @@ def run_python_file(python, file_args, directives=None):
def main(): def main():
args = parse_args() options, args = parse_args()
python = args.python python = options.python
if args.version: if options.version:
print_versions(python) print_versions(python)
return return
if args.command: if options.command:
run_cython_command(python, args.command, args.file_args) run_cython_command(python, options.command, args)
if args.file_args: if args:
if args.file_args[0] == '-': if args[0] == '-':
run_python_stdin(python, args.file_args[1:], args.directives) run_python_stdin(python, args[1:], options.directives)
else: else:
run_python_file(python, args.file_args, args.directives) run_python_file(python, args, options.directives)
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment