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
def parse_args(args=None):
import argparse
parser = argparse.ArgumentParser(description='Run a Python command line with Cython')
parser.add_argument('-c', metavar='CODE', dest='command',
import optparse # tried argparse, but it doesn't stop at the first (interspersed) positional argument
parser = optparse.OptionParser(description='Run a Python command line with Cython')
parser.disable_interspersed_args()
parser.add_option('-c', metavar='CODE', dest='command',
help='program passed in as string')
parser.add_argument('--python', metavar='PYTHON', dest='python', default=sys.executable,
parser.add_option('--python', metavar='PYTHON', dest='python', default=sys.executable,
help='Python interpreter to use')
parser.add_argument('-X', metavar='NAME=VALUE', dest='directives', action='append',
parser.add_option('-X', metavar='NAME=VALUE', dest='directives', action='append',
help='Compiler directives to set during compilation')
parser.add_argument('-V', '--version', action='store_true',
parser.add_option('-V', '--version', action='store_true',
help='print the Python and Cython version numbers and exit')
parser.add_argument('file_args', nargs='*',
help='program read from script file')
return parser.parse_args(args)
......@@ -86,21 +85,21 @@ def run_python_file(python, file_args, directives=None):
def main():
args = parse_args()
python = args.python
options, args = parse_args()
python = options.python
if args.version:
if options.version:
print_versions(python)
return
if args.command:
run_cython_command(python, args.command, args.file_args)
if options.command:
run_cython_command(python, options.command, args)
if args.file_args:
if args.file_args[0] == '-':
run_python_stdin(python, args.file_args[1:], args.directives)
if args:
if args[0] == '-':
run_python_stdin(python, args[1:], options.directives)
else:
run_python_file(python, args.file_args, args.directives)
run_python_file(python, args, options.directives)
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