def get_optp(conf): optp = to_optparse(conf) opts = optp.option_list for i in [g.option_list for g in optp.option_groups]: opts += i opt_s = [i.get_opt_string() for i in opts] return opt_s
def get_standard_options(): config = get_pypy_config() parser = to_optparse(config, useoptions=["objspace.*"], extra_useage=extra_useage) parser.add_option( '-H', action="callback", callback=run_tb_server, help="use web browser for traceback info") return config, parser
config.objspace.std.suggest(withprebuiltchar=True) config.objspace.std.suggest(withsharingdict=True) # xxx other options? ropes maybe? # completely disable geninterp in a level 0 translation if level == '0': config.objspace.suggest(geninterp=False) # some optimizations have different effects depending on the typesystem if type_system == 'ootype': config.objspace.std.suggest(multimethods="doubledispatch") def enable_allworkingmodules(config): if config.translation.type_system == 'ootype': modules = working_oo_modules else: modules = working_modules # ignore names from 'essential_modules', notably 'exceptions', which # may not be present in config.objspace.usemodules at all modules = [name for name in modules if name not in essential_modules] config.objspace.usemodules.suggest(**dict.fromkeys(modules, True)) if __name__ == '__main__': config = get_pypy_config() print config.getpaths() parser = to_optparse(config) #, useoptions=["translation.*"]) option, args = parser.parse_args() print config
def opt_parser(self, config): parser = to_optparse(config, useoptions=["objspace.*"], parserkwargs={'usage': self.usage}) return parser
def main_(argv=None): starttime = time.time() config, parser = option.get_standard_options() interactiveconfig = Config(cmdline_optiondescr) to_optparse(interactiveconfig, parser=parser) parser.add_option('--cc', type=str, action="callback", callback=set_compiler, help="Compiler to use for compiling generated C") args = option.process_options(parser, argv[1:]) if interactiveconfig.verbose: error.RECORD_INTERPLEVEL_TRACEBACK = True # --allworkingmodules takes really long to start up, but can be forced on config.objspace.suggest(allworkingmodules=False) if config.objspace.allworkingmodules: pypyoption.enable_allworkingmodules(config) # create the object space space = option.make_objspace(config) space._starttime = starttime space.setitem(space.sys.w_dict, space.wrap('executable'), space.wrap(argv[0])) # set warning control options (if any) warn_arg = interactiveconfig.warn if warn_arg is not None: space.appexec([space.wrap(warn_arg)], """(arg): import sys sys.warnoptions.append(arg)""") w_path = space.sys.get('path') path = os.getenv('PYTHONPATH') if path: path = path.split(os.pathsep) else: path = [] path.insert(0, '') for i, dir in enumerate(path): space.call_method(w_path, 'insert', space.wrap(i), space.wrap(dir)) # store the command-line arguments into sys.argv go_interactive = interactiveconfig.interactive banner = '' exit_status = 0 if interactiveconfig.runcommand is not None: args = ['-c'] + args for arg in args: space.call_method(space.sys.get('argv'), 'append', space.wrap(arg)) # load the source of the program given as command-line argument if interactiveconfig.runcommand is not None: def doit(): main.run_string(interactiveconfig.runcommand, space=space) elif interactiveconfig.runmodule: def doit(): main.run_module(interactiveconfig.runmodule, args, space=space) elif args: scriptdir = os.path.dirname(os.path.abspath(args[0])) space.call_method(space.sys.get('path'), 'insert', space.wrap(0), space.wrap(scriptdir)) def doit(): main.run_file(args[0], space=space) else: def doit(): pass space.call_method(space.sys.get('argv'), 'append', space.wrap('')) go_interactive = 1 banner = None try: def do_start(): space.startup() pypy_init(space, space.wrap(not interactiveconfig.no_site_import)) if main.run_toplevel(space, do_start, verbose=interactiveconfig.verbose): # compile and run it if not main.run_toplevel( space, doit, verbose=interactiveconfig.verbose): exit_status = 1 # start the interactive console if go_interactive or os.getenv('PYTHONINSPECT'): try: import readline except: pass con = interactive.PyPyConsole( space, verbose=interactiveconfig.verbose, completer=interactiveconfig.completer) if banner == '': banner = '%s / %s' % (con.__class__.__name__, repr(space)) con.interact(banner) exit_status = 0 finally: def doit(): space.finish() main.run_toplevel(space, doit, verbose=interactiveconfig.verbose) return exit_status
def parse_options_and_load_target(): opt_parser = optparse.OptionParser(usage="%prog [options] [target] [target-specific-options]", prog="translate", formatter=OptHelpFormatter(), add_help_option=False) opt_parser.disable_interspersed_args() config = get_combined_translation_config( overrides=OVERRIDES, translating=True) to_optparse(config, parser=opt_parser, useoptions=['translation.*']) translateconfig = Config(translate_optiondescr) to_optparse(translateconfig, parser=opt_parser) options, args = opt_parser.parse_args() # set goals and skipped_goals reset = False for name, _, _, _ in GOALS: if name.startswith('?'): continue if getattr(translateconfig.goal_options, name): if name not in translateconfig.goals: translateconfig.goals.append(name) if getattr(translateconfig.goal_options, 'no_'+name): if name not in translateconfig.skipped_goals: if not reset: translateconfig.skipped_goals[:] = [] reset = True translateconfig.skipped_goals.append(name) if args: arg = args[0] args = args[1:] if os.path.isfile(arg+'.py'): assert not os.path.isfile(arg), ( "ambiguous file naming, please rename %s" % arg) translateconfig.targetspec = arg elif os.path.isfile(arg) and arg.endswith('.py'): translateconfig.targetspec = arg[:-3] else: log.ERROR("Could not find target %r" % (arg, )) sys.exit(1) # apply the platform settings set_platform(config) targetspec = translateconfig.targetspec targetspec_dic = load_target(targetspec) if args and not targetspec_dic.get('take_options', False): log.WARNING("target specific arguments supplied but will be ignored: %s" % ' '.join(args)) # give the target the possibility to get its own configuration options # into the config if 'get_additional_config_options' in targetspec_dic: optiondescr = targetspec_dic['get_additional_config_options']() config = get_combined_translation_config( optiondescr, existing_config=config, translating=True) # apply the optimization level settings set_opt_level(config, translateconfig.opt) # let the target modify or prepare itself # based on the config if 'handle_config' in targetspec_dic: targetspec_dic['handle_config'](config, translateconfig) # perform checks (if any) on the final config final_check_config(config) if translateconfig.help: opt_parser.print_help() if 'print_help' in targetspec_dic: print "\n\nTarget specific help:\n\n" targetspec_dic['print_help'](config) print "\n\nFor detailed descriptions of the command line options see" print "http://codespeak.net/pypy/dist/pypy/doc/config/commandline.html" sys.exit(0) return targetspec_dic, translateconfig, config, args
# extra optimizations with the JIT if level == 'jit': config.objspace.std.suggest(withcelldict=True) config.objspace.std.suggest(withmapdict=True) def enable_allworkingmodules(config): if config.translation.type_system == 'ootype': modules = working_oo_modules else: modules = working_modules if config.translation.sandbox: modules = default_modules # ignore names from 'essential_modules', notably 'exceptions', which # may not be present in config.objspace.usemodules at all modules = [name for name in modules if name not in essential_modules] config.objspace.usemodules.suggest(**dict.fromkeys(modules, True)) def enable_translationmodules(config): modules = translation_modules modules = [name for name in modules if name not in essential_modules] config.objspace.usemodules.suggest(**dict.fromkeys(modules, True)) if __name__ == '__main__': config = get_pypy_config() print config.getpaths() parser = to_optparse(config) #, useoptions=["translation.*"]) option, args = parser.parse_args() print config
def main_(argv=None): starttime = time.time() config, parser = option.get_standard_options() interactiveconfig = Config(cmdline_optiondescr) to_optparse(interactiveconfig, parser=parser) args = option.process_options(parser, argv[1:]) if interactiveconfig.verbose: error.RECORD_INTERPLEVEL_TRACEBACK = True # create the object space space = option.make_objspace(config) space._starttime = starttime #assert 'pypy.tool.udir' not in sys.modules, ( # "running py.py should not import pypy.tool.udir, which is\n" # "only for testing or translating purposes.") # ^^^ _socket and other rctypes-based modules need udir space.setitem(space.sys.w_dict,space.wrap('executable'),space.wrap(argv[0])) # store the command-line arguments into sys.argv go_interactive = interactiveconfig.interactive banner = '' exit_status = 0 if interactiveconfig.runcommand is not None: args = ['-c'] + args for arg in args: space.call_method(space.sys.get('argv'), 'append', space.wrap(arg)) # load the source of the program given as command-line argument if interactiveconfig.runcommand is not None: def doit(): main.run_string(interactiveconfig.runcommand, space=space) elif interactiveconfig.runmodule: def doit(): main.run_module(interactiveconfig.runmodule, args, space=space) elif args: scriptdir = os.path.dirname(os.path.abspath(args[0])) space.call_method(space.sys.get('path'), 'insert', space.wrap(0), space.wrap(scriptdir)) def doit(): main.run_file(args[0], space=space) else: def doit(): pass space.call_method(space.sys.get('argv'), 'append', space.wrap('')) go_interactive = 1 banner = None try: def do_start(): space.startup() pypy_init(space, space.wrap(not interactiveconfig.no_site_import)) if main.run_toplevel(space, do_start, verbose=interactiveconfig.verbose): # compile and run it if not main.run_toplevel(space, doit, verbose=interactiveconfig.verbose): exit_status = 1 # start the interactive console if go_interactive or getenv_w(space, 'PYTHONINSPECT'): con = interactive.PyPyConsole( space, verbose=interactiveconfig.verbose, completer=interactiveconfig.completer) if banner == '': banner = '%s / %s'%(con.__class__.__name__, repr(space)) con.interact(banner) exit_status = 0 finally: def doit(): space.finish() main.run_toplevel(space, doit, verbose=interactiveconfig.verbose) return exit_status
def parse_options_and_load_target(): opt_parser = optparse.OptionParser( usage="%prog [options] [target] [target-specific-options]", prog="translate", formatter=OptHelpFormatter(), add_help_option=False) opt_parser.disable_interspersed_args() config = get_combined_translation_config(overrides=OVERRIDES, translating=True) to_optparse(config, parser=opt_parser, useoptions=['translation.*']) translateconfig = Config(translate_optiondescr) to_optparse(translateconfig, parser=opt_parser) options, args = opt_parser.parse_args() # set goals and skipped_goals reset = False for name, _, _, _ in GOALS: if name.startswith('?'): continue if getattr(translateconfig.goal_options, name): if name not in translateconfig.goals: translateconfig.goals.append(name) if getattr(translateconfig.goal_options, 'no_' + name): if name not in translateconfig.skipped_goals: if not reset: translateconfig.skipped_goals[:] = [] reset = True translateconfig.skipped_goals.append(name) if args: arg = args[0] args = args[1:] if os.path.isfile(arg + '.py'): assert not os.path.isfile(arg), ( "ambiguous file naming, please rename %s" % arg) translateconfig.targetspec = arg elif os.path.isfile(arg) and arg.endswith('.py'): translateconfig.targetspec = arg[:-3] else: log.ERROR("Could not find target %r" % (arg, )) sys.exit(1) # apply the platform settings set_platform(config) targetspec = translateconfig.targetspec targetspec_dic = load_target(targetspec) if args and not targetspec_dic.get('take_options', False): log.WARNING( "target specific arguments supplied but will be ignored: %s" % ' '.join(args)) # give the target the possibility to get its own configuration options # into the config if 'get_additional_config_options' in targetspec_dic: optiondescr = targetspec_dic['get_additional_config_options']() config = get_combined_translation_config(optiondescr, existing_config=config, translating=True) # apply the optimization level settings set_opt_level(config, translateconfig.opt) # let the target modify or prepare itself # based on the config if 'handle_config' in targetspec_dic: targetspec_dic['handle_config'](config, translateconfig) # perform checks (if any) on the final config final_check_config(config) if translateconfig.help: opt_parser.print_help() if 'print_help' in targetspec_dic: print "\n\nTarget specific help:\n\n" targetspec_dic['print_help'](config) print "\n\nFor detailed descriptions of the command line options see" print "http://pypy.readthedocs.org/en/latest/config/commandline.html" sys.exit(0) return targetspec_dic, translateconfig, config, args
def main_(argv=None): starttime = time.time() config, parser = option.get_standard_options() interactiveconfig = Config(cmdline_optiondescr) to_optparse(interactiveconfig, parser=parser) parser.add_option( '--cc', type=str, action="callback", callback=set_compiler, help="Compiler to use for compiling generated C") args = option.process_options(parser, argv[1:]) if interactiveconfig.verbose: error.RECORD_INTERPLEVEL_TRACEBACK = True # --allworkingmodules takes really long to start up, but can be forced on config.objspace.suggest(allworkingmodules=False) if config.objspace.allworkingmodules: pypyoption.enable_allworkingmodules(config) if config.objspace.usemodules._continuation: config.translation.continuation = True if config.objspace.usemodules.thread: config.translation.thread = True # create the object space space = option.make_objspace(config) space._starttime = starttime space.setitem(space.sys.w_dict, space.wrap('executable'), space.wrap(argv[0])) # call pypy_initial_path: the side-effect is that it sets sys.prefix and # sys.exec_prefix srcdir = os.path.dirname(os.path.dirname(pypy.__file__)) space.appexec([space.wrap(srcdir)], """(srcdir): import sys sys.pypy_initial_path(srcdir) """) # set warning control options (if any) warn_arg = interactiveconfig.warn if warn_arg is not None: space.appexec([space.wrap(warn_arg)], """(arg): import sys sys.warnoptions.append(arg)""") w_path = space.sys.get('path') path = os.getenv('PYTHONPATH') if path: path = path.split(os.pathsep) else: path = [] path.insert(0, '') for i, dir in enumerate(path): space.call_method(w_path, 'insert', space.wrap(i), space.wrap(dir)) # store the command-line arguments into sys.argv go_interactive = interactiveconfig.interactive banner = '' exit_status = 0 command = None if interactiveconfig.runcommand: command = args[0] args[0] = '-c' if interactiveconfig.runmodule: command = args.pop(0) for arg in args: space.call_method(space.sys.get('argv'), 'append', space.wrap(arg)) # load the source of the program given as command-line argument if interactiveconfig.runcommand: def doit(): main.run_string(command, space=space) elif interactiveconfig.runmodule: def doit(): main.run_module(command, args, space=space) elif args: scriptdir = os.path.dirname(os.path.abspath(args[0])) space.call_method(space.sys.get('path'), 'insert', space.wrap(0), space.wrap(scriptdir)) def doit(): main.run_file(args[0], space=space) else: def doit(): pass space.call_method(space.sys.get('argv'), 'append', space.wrap('')) go_interactive = 1 banner = None try: def do_start(): space.startup() pypy_init(space, space.wrap(not interactiveconfig.no_site_import)) if main.run_toplevel(space, do_start, verbose=interactiveconfig.verbose): # compile and run it if not main.run_toplevel(space, doit, verbose=interactiveconfig.verbose): exit_status = 1 # start the interactive console if go_interactive or os.getenv('PYTHONINSPECT'): try: import readline except: pass con = interactive.PyPyConsole( space, verbose=interactiveconfig.verbose, completer=interactiveconfig.completer) if banner == '': banner = '%s / %s'%(con.__class__.__name__, repr(space)) con.interact(banner) exit_status = 0 finally: def doit(): space.finish() main.run_toplevel(space, doit, verbose=interactiveconfig.verbose) return exit_status
def main_(argv=None): starttime = time.time() config, parser = option.get_standard_options() interactiveconfig = Config(cmdline_optiondescr) to_optparse(interactiveconfig, parser=parser) args = option.process_options(parser, argv[1:]) if interactiveconfig.verbose: error.RECORD_INTERPLEVEL_TRACEBACK = True # create the object space space = option.make_objspace(config) space._starttime = starttime space.setitem(space.sys.w_dict, space.wrap('executable'), space.wrap(argv[0])) # store the command-line arguments into sys.argv go_interactive = interactiveconfig.interactive banner = '' exit_status = 0 if interactiveconfig.runcommand is not None: args = ['-c'] + args for arg in args: space.call_method(space.sys.get('argv'), 'append', space.wrap(arg)) # load the source of the program given as command-line argument if interactiveconfig.runcommand is not None: def doit(): main.run_string(interactiveconfig.runcommand, space=space) elif interactiveconfig.runmodule: def doit(): main.run_module(interactiveconfig.runmodule, args, space=space) elif args: scriptdir = os.path.dirname(os.path.abspath(args[0])) space.call_method(space.sys.get('path'), 'insert', space.wrap(0), space.wrap(scriptdir)) def doit(): main.run_file(args[0], space=space) else: def doit(): pass space.call_method(space.sys.get('argv'), 'append', space.wrap('')) go_interactive = 1 banner = None try: def do_start(): space.startup() pypy_init(space, space.wrap(not interactiveconfig.no_site_import)) if main.run_toplevel(space, do_start, verbose=interactiveconfig.verbose): # compile and run it if not main.run_toplevel( space, doit, verbose=interactiveconfig.verbose): exit_status = 1 # start the interactive console if go_interactive or getenv_w(space, 'PYTHONINSPECT'): try: import readline except: pass con = interactive.PyPyConsole( space, verbose=interactiveconfig.verbose, completer=interactiveconfig.completer) if banner == '': banner = '%s / %s' % (con.__class__.__name__, repr(space)) con.interact(banner) exit_status = 0 finally: def doit(): space.finish() main.run_toplevel(space, doit, verbose=interactiveconfig.verbose) return exit_status
def process_options(): jsconfig = Config(js_optiondescr) parser = to_optparse(jsconfig, parserkwargs={"usage": __doc__}) parser.disable_interspersed_args() options, args = parser.parse_args() return args, jsconfig