示例#1
0
def parse_command_line(args):
    from Pyrex.Compiler.Main import CompilationOptions, default_options

    def pop_arg():
        if args:
            return args.pop(0)
        else:
            bad_usage()

    def get_param(option):
        tail = option[2:]
        if tail:
            return tail
        else:
            return pop_arg()

    options = CompilationOptions(default_options)
    sources = []
    while args:
        if args[0].startswith("-"):
            option = pop_arg()
            if option in ("-v", "--version"):
                options.show_version = 1
            elif option in ("-l", "--create-listing"):
                options.use_listing_file = 1
            elif option in ("-C", "--compile"):
                options.c_only = 0
            elif option in ("-X", "--link"):
                options.c_only = 0
                options.obj_only = 0
            elif option in ("-+", "--cplus"):
                options.cplus = 1
            elif option.startswith("-I"):
                options.include_path.append(get_param(option))
            elif option == "--include-dir":
                options.include_path.append(pop_arg())
            elif option in ("-o", "--output-file"):
                options.output_file = pop_arg()
            elif option in ("-r", "--recursive"):
                options.recursive = 1
            elif option in ("-t", "--timestamps"):
                options.timestamps = 1
            elif option in ("-f", "--force"):
                options.timestamps = 0
            else:
                bad_usage()
        else:
            arg = pop_arg()
            if has_suffix(arg, pyx_suffixes):
                sources.append(arg)
            elif arg.endswith(".o"):
                options.objects.append(arg)
            else:
                print >>sys.stderr, "pyrexc: %s: Unknown filename suffix" % arg
    if options.objects and len(sources) > 1:
        print >>sys.stderr, "pyrexc: Only one source file allowed together with .o files"
    if options.use_listing_file and len(sources) > 1:
        print >>sys.stderr, "pyrexc: Only one source file allowed when using -o"
        sys.exit(1)
    return options, sources
示例#2
0
def parse_command_line(args):
    from Pyrex.Compiler.Main import \
     CompilationOptions, default_options

    def pop_arg(option=None):
        if args:
            return args.pop(0)
        elif option:
            fail("Missing argument for %s" % option)
        else:
            fail("Missing argument")

    def pop_option():
        option = args.pop(0)
        if option.startswith("--"):
            value = None
        else:
            value = option[2:]
            option = option[:2]
        return option, value

    def get_param(arg):
        option, value = arg
        if value:
            return value
        else:
            return pop_arg(option)

    options = CompilationOptions(default_options)
    sources = []
    while args:
        if args[0].startswith("-"):
            arg = pop_option()
            option, value = arg
            if option in ("-?", "--help"):
                show_usage()
            elif option in ("-V", "--version"):
                options.show_version = 1
            elif option in ("-v", "--verbose"):
                options.verbose = 1
            elif option in ("-e", "--create-listing"):
                options.use_listing_file = 1
            elif option in ("-C", "--compile"):
                options.c_only = 0
            elif option in ("-X", "--link"):
                options.c_only = 0
                options.obj_only = 0
            elif option in ("-+", "--cplus"):
                options.cplus = 1
            elif option in ("-I", "--include-dir"):
                options.include_path.append(get_param(arg))
            elif option in ("-o", "--output-file"):
                options.output_file = get_param(arg)
            elif option in ("-r", "--recursive"):
                options.recursive = 1
            elif option in ("-t", "--timestamps"):
                options.timestamps = 1
            elif option in ("-f", "--force"):
                options.timestamps = 0
            elif option in ("-N", "--numpy"):
                options.include_path.append(get_numpy_include_dir())
            elif option in ("-L", "--library_dir"):
                options.library_path.append(get_param(arg))
            elif option in ("-l", "--library"):
                options.libraries.append(get_param(arg))
            elif option in ("-F", "--framework_dir"):
                options.framework_path.append(get_param(arg))
            elif option == "--framework":
                options.frameworks.append(get_param(arg))
            else:
                bad_option(option)
        else:
            arg = pop_arg()
            if has_suffix(arg, pyx_suffixes):
                sources.append(arg)
            elif arg.endswith(".o"):
                options.objects.append(arg)
            else:
                print >>sys.stderr, \
                 "pyrexc: %s: Unknown filename suffix" % arg
    if options.objects and len(sources) > 1:
        print >>sys.stderr, \
         "pyrexc: Only one source file allowed together with .o files"
    if options.use_listing_file and len(sources) > 1:
        print >>sys.stderr, \
         "pyrexc: Only one source file allowed when using -o"
        sys.exit(1)
    return options, sources
示例#3
0
文件: CmdLine.py 项目: jwilk/Pyrex
def parse_command_line(args):
	from Pyrex.Compiler.Main import \
		CompilationOptions, default_options

	def pop_arg(option = None):
		if args:
			return args.pop(0)
		elif option:
			fail("Missing argument for %s" % option)
		else:
			fail("Missing argument")
	
	def pop_option():
		option = args.pop(0)
		if option.startswith("--"):
			value = None
		else:
			value = option[2:]
			option = option[:2]
		return option, value
	
	def get_param(arg):
		option, value = arg
		if value:
			return value
		else:
			return pop_arg(option)

	options = CompilationOptions(default_options)
	sources = []
	while args:
		if args[0].startswith("-"):
			arg = pop_option()
			option, value = arg
			if option in ("-?", "--help"):
				show_usage()
			elif option in ("-V", "--version"):
				options.show_version = 1
			elif option in ("-v", "--verbose"):
				options.verbose = 1
			elif option in ("-e", "--create-listing"):
				options.use_listing_file = 1
			elif option in ("-C", "--compile"):
				options.c_only = 0
			elif option in ("-X", "--link"):
				options.c_only = 0
				options.obj_only = 0
			elif option in ("-+", "--cplus"):
				options.cplus = 1
			elif option in ("-I", "--include-dir"):
				options.include_path.append(get_param(arg))
			elif option in ("-o", "--output-file"):
				options.output_file = get_param(arg)
			elif option in ("-r", "--recursive"):
				options.recursive = 1
			elif option in ("-t", "--timestamps"):
				options.timestamps = 1
			elif option in ("-f", "--force"):
				options.timestamps = 0
			elif option in ("-N", "--numpy"):
				options.include_path.append(get_numpy_include_dir())
			elif option in ("-L", "--library_dir"):
				options.library_path.append(get_param(arg))
			elif option in ("-l", "--library"):
				options.libraries.append(get_param(arg))
			elif option in ("-F", "--framework_dir"):
				options.framework_path.append(get_param(arg))
			elif option == "--framework":
				options.frameworks.append(get_param(arg))
			else:
				bad_option(option)
		else:
			arg = pop_arg()
			if has_suffix(arg, pyx_suffixes):
				sources.append(arg)
			elif arg.endswith(".o"):
				options.objects.append(arg)
			else:
				print >>sys.stderr, \
					"pyrexc: %s: Unknown filename suffix" % arg
	if options.objects and len(sources) > 1:
		print >>sys.stderr, \
			"pyrexc: Only one source file allowed together with .o files"
	if options.use_listing_file and len(sources) > 1:
		print >>sys.stderr, \
			"pyrexc: Only one source file allowed when using -o"
		sys.exit(1)
	return options, sources
示例#4
0
def parse_command_line(args):
    from Pyrex.Compiler.Main import \
        CompilationOptions, default_options

    def pop_arg():
        if args:
            return args.pop(0)
        else:
            bad_usage()

    def get_param(option):
        tail = option[2:]
        if tail:
            return tail
        else:
            return pop_arg()

    options = CompilationOptions(default_options)
    sources = []
    while args:
        if args[0].startswith("-"):
            option = pop_arg()
            if option in ("-v", "--version"):
                options.show_version = 1
            elif option in ("-l", "--create-listing"):
                options.use_listing_file = 1
            elif option in ("-C", "--compile"):
                options.c_only = 0
            elif option in ("-X", "--link"):
                options.c_only = 0
                options.obj_only = 0
            elif option in ("-+", "--cplus"):
                options.cplus = 1
            elif option.startswith("-I"):
                options.include_path.append(get_param(option))
            elif option == "--include-dir":
                options.include_path.append(pop_arg())
            elif option in ("-o", "--output-file"):
                options.output_file = pop_arg()
            elif option in ("-r", "--recursive"):
                options.recursive = 1
            elif option in ("-t", "--timestamps"):
                options.timestamps = 1
            elif option in ("-f", "--force"):
                options.timestamps = 0
            else:
                bad_usage()
        else:
            arg = pop_arg()
            if has_suffix(arg, pyx_suffixes):
                sources.append(arg)
            elif arg.endswith(".o"):
                options.objects.append(arg)
            else:
                print >>sys.stderr, \
                    "pyrexc: %s: Unknown filename suffix" % arg
    if options.objects and len(sources) > 1:
        print >>sys.stderr, \
            "pyrexc: Only one source file allowed together with .o files"
    if options.use_listing_file and len(sources) > 1:
        print >>sys.stderr, \
            "pyrexc: Only one source file allowed when using -o"
        sys.exit(1)
    return options, sources