def entry_point(argv): if not objectmodel.we_are_translated(): import sys sys.setrecursionlimit(10000) if pycketconfig is not None: from rpython.config.config import to_optparse if '--linklets' in argv: to_optparse(pycketconfig).parse_args(['--linklets']) try: if pycketconfig is not None and pycketconfig.pycket.linklets: return actual_entry(argv) else: return old_pycket_actual_entry(argv) except SchemeException, e: print "ERROR:" print e.format_error() raise # to see interpreter-level traceback
def target(driver, args): driver.exe_name = 'nolang-c' config = driver.config from rpython.config.config import to_optparse, SUPPRESS_USAGE parser = to_optparse(config, parserkwargs={'usage': SUPPRESS_USAGE}) parser.parse_args(args) from nolang.main import main return main, None
def target(driver, args): driver.exe_name = 'hippy-c' config = driver.config from rpython.config.config import to_optparse, SUPPRESS_USAGE parser = to_optparse(config, parserkwargs={'usage': SUPPRESS_USAGE }) parser.parse_args(args) from hippy.hippyoption import set_options set_options(config) from hippy.main import entry_point return entry_point, None
def target(driver, args): #pragma: no cover from rpython.config.config import to_optparse from pycket.config import expose_options, compute_executable_suffix config = driver.config parser = to_optparse(config, useoptions=["pycket.*"]) parser.parse_args(args) if config.pycket.with_branch: import subprocess base_name = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).strip() else: base_name = 'pycket' base_name += '-%(backend)s' if not config.translation.jit: base_name += '-%(backend)s-nojit' driver.exe_name = base_name + compute_executable_suffix(config) # it's important that the very first thing we do, before importing anything # else from pycket is call expose_options expose_options(config) entry_point = make_entry_point(config) return entry_point, None
def target(driver, args): driver.exe_name = 'hippy-c' config = driver.config from rpython.config.config import to_optparse, SUPPRESS_USAGE parser = to_optparse(config, parserkwargs={'usage': SUPPRESS_USAGE }) parser.parse_args(args) from hippy.hippyoption import ( OPTIONAL_EXTS, is_optional_extension_enabled, HippyOptionError) from hippy.hippyoption import set_options set_options(config) for ext in OPTIONAL_EXTS: asked = getattr(config.optexts, ext) if asked and not is_optional_extension_enabled(ext): raise HippyOptionError("%s extension sources are missing!" % ext) from hippy.main import entry_point return entry_point, None
config.objspace.std.suggest(withsmalllong=True) # extra optimizations with the JIT if level == 'jit': config.objspace.std.suggest(withcelldict=True) config.objspace.std.suggest(withmapdict=True) def enable_allworkingmodules(config): modules = working_modules.copy() 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 opt_parser(self, config): parser = to_optparse(config, useoptions=["objspace.*"], parserkwargs={'usage': self.usage}) return parser
config.objspace.std.suggest(withcelldict=True) config.objspace.std.suggest(withmapdict=True) def enable_allworkingmodules(config): if config.translation.backend == 'js': modules = working_js_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 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(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) else: show_help(translateconfig, opt_parser, None, config) # print the version of the host # (if it's PyPy, it includes the hg checksum) log.info(sys.version) # 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) # show the target-specific help if --help was given show_help(translateconfig, opt_parser, targetspec_dic, config) # 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) return targetspec_dic, translateconfig, config, args
def parser(config): return to_optparse(config, useoptions=["rsqueak.*"])
def get_standard_options(): config = get_pypy_config() parser = to_optparse(config, useoptions=["objspace.*"], extra_useage=extra_useage) return config, parser
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(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) else: show_help(translateconfig, opt_parser, None, config) # print the version of the host # (if it's PyPy, it includes the hg checksum) log.info(sys.version) # 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) # show the target-specific help if --help was given show_help(translateconfig, opt_parser, targetspec_dic, config) # 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) return targetspec_dic, translateconfig, config, args
def print_help(config): to_optparse(config).print_help()
def main_(argv=None): starttime = time.time() config, parser = option.get_standard_options() interactiveconfig = Config(cmdline_optiondescr) to_optparse(interactiveconfig, parser=parser) def set_family_of_options(option, opt, value, parser): from pypy.config.pypyoption import set_pypy_opt_level set_pypy_opt_level(config, value) parser.add_option( '--cc', type=str, action="callback", callback=set_compiler, help="Compiler to use for compiling generated C") parser.add_option( '--opt', type=str, action="callback", callback=set_family_of_options, help="Set the family of options based on -opt=0,1,2,jit...") 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])) if interactiveconfig.optimize: #change the optimize flag's value and set __debug__ to False space.appexec([], """(): import sys flags = list(sys.flags) flags[6] = 2 sys.flags = type(sys.flags)(flags) import __pypy__ __pypy__.set_debug(False) """) # call pypy_find_stdlib: the side-effect is that it sets sys.prefix and # sys.exec_prefix executable = argv[0] space.appexec([space.wrap(executable)], """(executable): import sys sys.pypy_find_stdlib(executable) """) # 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_fsdecoded(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) def set_family_of_options(option, opt, value, parser): from pypy.config.pypyoption import set_pypy_opt_level set_pypy_opt_level(config, value) parser.add_option('--cc', type=str, action="callback", callback=set_compiler, help="Compiler to use for compiling generated C") parser.add_option( '--opt', type=str, action="callback", callback=set_family_of_options, help="Set the family of options based on -opt=0,1,2,jit...") 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) config.objspace.usemodules.struct = True 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])) if interactiveconfig.optimize: #change the optimize flag's value and set __debug__ to False space.appexec([], """(): import sys flags = list(sys.flags) flags[3] = 2 sys.flags = type(sys.flags)(flags) __builtins__.__dict__['__debug__'] = False """) # call pypy_find_stdlib: the side-effect is that it sets sys.prefix and # sys.exec_prefix executable = argv[0] space.appexec([space.wrap(executable)], """(executable): import sys sys.pypy_find_stdlib(executable) """) # 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.newfilename(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