def make_cmdline_overview(descr, title=True): content = Rest() if title: content.add( Title("Overview of Command Line Options for '%s'" % (descr._name, ), abovechar="=", belowchar="=")) cmdlines = [] config = Config(descr) for path in config.getpaths(include_groups=False): subconf, step = config._cfgimpl_get_home_by_path(path) fullpath = (descr._name + "." + path) subdescr = getattr(subconf._cfgimpl_descr, step) cmdline = get_cmdline(subdescr.cmdline, fullpath) if cmdline is not None: header = _get_section_header(cmdline, fullpath, subdescr) cmdlines.append((header, cmdline, fullpath, subdescr)) cmdlines.sort(key=lambda x: (x[0], x[1].strip("-"))) currheader = "" curr = content for header, cmdline, fullpath, subdescr in cmdlines: if header != currheader: content.add(Title(header, abovechar="", belowchar="=")) curr = content.add(Paragraph()) currheader = header curr.add( ListItem(Link(cmdline + ":", fullpath + ".html"), Text(subdescr.doc))) return content
def get_combined_translation_config(other_optdescr=None, existing_config=None, overrides=None, translating=False): if overrides is None: overrides = {} d = BoolOption("translating", "indicates whether we are translating currently", default=False, cmdline=None) if other_optdescr is None: children = [] newname = "" else: children = [other_optdescr] newname = other_optdescr._name if existing_config is None: children += [d, translation_optiondescription] else: children += [ child for child in existing_config._cfgimpl_descr._children if child._name != newname ] descr = OptionDescription("pypy", "all options", children) config = Config(descr, **overrides) if translating: config.translating = True if existing_config is not None: for child in existing_config._cfgimpl_descr._children: if child._name == newname: continue value = getattr(existing_config, child._name) config._cfgimpl_values[child._name] = value return config
def get_content(self, txtpath, encoding): if txtpath.basename == "commandline.rst": result = [] for line in txtpath.read().splitlines(): if line.startswith('.. GENERATE:'): start = line[len('.. GENERATE:'):].strip() descr = start_to_descr[start] line = make_cmdline_overview(descr, title=False).text() result.append(line) return "\n".join(result) fullpath = txtpath.purebasename start = fullpath.split(".")[0] path = fullpath.rsplit(".", 1)[0] basedescr = start_to_descr.get(start) if basedescr is None: return txtpath.read() if fullpath.count(".") == 0: descr = basedescr path = "" else: conf = Config(basedescr) subconf, step = conf._cfgimpl_get_home_by_path( fullpath.split(".", 1)[1]) descr = getattr(subconf._cfgimpl_descr, step) text = unicode(descr.make_rest_doc(path).text()) if txtpath.check(file=True): content = txtpath.read() if content: text += "\nDescription\n===========" return u"%s\n\n%s" % (text, unicode(txtpath.read(), encoding)) return text
def test_check_documentation(): def check_file_exists(fn): assert configdocdir.join(fn).check() from pypy.doc.config.generate import all_optiondescrs configdocdir = thisdir.dirpath().dirpath().join("doc", "config") for descr in all_optiondescrs: prefix = descr._name c = Config(descr) for path in c.getpaths(include_groups=True): fn = prefix + "." + path + ".txt" yield fn, check_file_exists, fn
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
default=False, cmdline="--withext-%s" % extname ) for extname in OPTIONAL_EXTS] hippy_optiondescription = OptionDescription("optexts", "Optional extensions", optexts_descriptions) # You need this top-level container when calling Config ctor directly. # You don't need this is the target because the opt parser does this part. top_hippy_optiondescription = \ OptionDescription("hippy", "all options", [ BoolOption("translating", "Are we translating?", default=False), hippy_optiondescription]) OPTIONS = Config(top_hippy_optiondescription) # default config def set_options(config): import sys thismod = sys.modules[__name__] setattr(thismod, "OPTIONS", config) def enable_all_optional_extensions(): for extname in OPTIONAL_EXTS: setattr(OPTIONS.optexts, extname, True) @specialize.memo() def is_optional_extension_enabled(extname):
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