Commits

Alexander Hesse committed a879d58

Moved pypy.config parts to rpython

  • Participants
  • Parent commits 490e3da
  • Branches split-rpython

Comments (0)

Files changed (38)

File pypy/bin/pyinteractive.py

 import pypy
 from pypy.tool import option
 from optparse import make_option
-from pypy.interpreter import main, interactive, error, gateway
-from pypy.config.config import OptionDescription, BoolOption, StrOption
-from pypy.config.config import Config, to_optparse
+from rpython.interpreter import main, interactive, error, gateway
+from rpython.config.config import OptionDescription, BoolOption, StrOption
+from rpython.config.config import Config, to_optparse
 from pypy.config import pypyoption
 
 

File pypy/config/config.py

-import py
-import optparse
-from rpython.tool.pairtype import extendabletype
-
-SUPPRESS_USAGE = optparse.SUPPRESS_USAGE
-
-class AmbigousOptionError(Exception):
-    pass
-
-class NoMatchingOptionFound(AttributeError):
-    pass
-
-class ConfigError(Exception):
-    pass
-
-class ConflictConfigError(ConfigError):
-    pass
-
-class Config(object):
-    _cfgimpl_frozen = False
-    
-    def __init__(self, descr, parent=None, **overrides):
-        self._cfgimpl_descr = descr
-        self._cfgimpl_value_owners = {}
-        self._cfgimpl_parent = parent
-        self._cfgimpl_values = {}
-        self._cfgimpl_warnings = []
-        self._cfgimpl_build(overrides)
-
-    def _cfgimpl_build(self, overrides):
-        for child in self._cfgimpl_descr._children:
-            if isinstance(child, Option):
-                self._cfgimpl_values[child._name] = child.getdefault()
-                self._cfgimpl_value_owners[child._name] = 'default'
-            elif isinstance(child, OptionDescription):
-                self._cfgimpl_values[child._name] = Config(child, parent=self)
-        self.override(overrides)
-
-    def override(self, overrides):
-        for name, value in overrides.iteritems():
-            homeconfig, name = self._cfgimpl_get_home_by_path(name)
-            homeconfig.setoption(name, value, 'default')
-
-    def copy(self, as_default=False, parent=None):
-        result = Config.__new__(self.__class__)
-        result._cfgimpl_descr = self._cfgimpl_descr
-        result._cfgimpl_value_owners = owners = {}
-        result._cfgimpl_parent = parent
-        result._cfgimpl_values = v = {}
-        for child in self._cfgimpl_descr._children:
-            if isinstance(child, Option):
-                v[child._name] = self._cfgimpl_values[child._name]
-                if as_default:
-                    owners[child._name] = 'default'
-                else:
-                    owners[child._name] = (
-                        self._cfgimpl_value_owners[child._name])
-            elif isinstance(child, OptionDescription):
-                v[child._name] = self._cfgimpl_values[child._name].copy(
-                    as_default, parent=result)
-        return result
-
-    def __setattr__(self, name, value):
-        if self._cfgimpl_frozen and getattr(self, name) != value:
-            raise TypeError("trying to change a frozen option object")
-        if name.startswith('_cfgimpl_'):
-            self.__dict__[name] = value
-            return
-        self.setoption(name, value, 'user')
-
-    def __getattr__(self, name):
-        if '.' in name:
-            homeconfig, name = self._cfgimpl_get_home_by_path(name)
-            return getattr(homeconfig, name)
-        if name.startswith('_cfgimpl_'):
-            # if it were in __dict__ it would have been found already
-            raise AttributeError("%s object has no attribute %s" %
-                                 (self.__class__, name))
-        if name not in self._cfgimpl_values:
-            raise AttributeError("%s object has no attribute %s" %
-                                 (self.__class__, name))
-        return self._cfgimpl_values[name]
-
-    def __dir__(self):
-        from_type = dir(type(self))
-        from_dict = list(self.__dict__)
-        extras = list(self._cfgimpl_values)
-        return sorted(set(extras + from_type + from_dict))
-
-    def __delattr__(self, name):
-        # XXX if you use delattr you are responsible for all bad things
-        # happening
-        if name.startswith('_cfgimpl_'):
-            del self.__dict__[name]
-            return
-        self._cfgimpl_value_owners[name] = 'default'
-        opt = getattr(self._cfgimpl_descr, name)
-        if isinstance(opt, OptionDescription):
-            raise AttributeError("can't option subgroup")
-        self._cfgimpl_values[name] = getattr(opt, 'default', None)
-
-    def setoption(self, name, value, who):
-        if name not in self._cfgimpl_values:
-            raise AttributeError('unknown option %s' % (name,))
-        child = getattr(self._cfgimpl_descr, name)
-        oldowner = self._cfgimpl_value_owners[child._name]
-        if oldowner not in ("default", "suggested"):
-            oldvalue = getattr(self, name)
-            if oldvalue == value or who in ("default", "suggested"):
-                return
-            raise ConflictConfigError('cannot override value to %s for '
-                                      'option %s' % (value, name))
-        child.setoption(self, value, who)
-        self._cfgimpl_value_owners[name] = who
-
-    def suggest(self, **kwargs):
-        for name, value in kwargs.items():
-            self.suggestoption(name, value)
-
-    def suggestoption(self, name, value):
-        try:
-            self.setoption(name, value, "suggested")
-        except ConflictConfigError:
-            # setting didn't work, but that is fine, since it is
-            # suggested only
-            pass
-
-    def set(self, **kwargs):
-        all_paths = [p.split(".") for p in self.getpaths()]
-        for key, value in kwargs.iteritems():
-            key_p = key.split('.')
-            candidates = [p for p in all_paths if p[-len(key_p):] == key_p]
-            if len(candidates) == 1:
-                name = '.'.join(candidates[0])
-                homeconfig, name = self._cfgimpl_get_home_by_path(name)
-                homeconfig.setoption(name, value, "user")
-            elif len(candidates) > 1:
-                raise AmbigousOptionError(
-                    'more than one option that ends with %s' % (key, ))
-            else:
-                raise NoMatchingOptionFound(
-                    'there is no option that matches %s' % (key, ))
-
-    def _cfgimpl_get_home_by_path(self, path):
-        """returns tuple (config, name)"""
-        path = path.split('.')
-        for step in path[:-1]:
-            self = getattr(self, step)
-        return self, path[-1]
-
-    def _cfgimpl_get_toplevel(self):
-        while self._cfgimpl_parent is not None:
-            self = self._cfgimpl_parent
-        return self
-
-    def add_warning(self, warning):
-        self._cfgimpl_get_toplevel()._cfgimpl_warnings.append(warning)
-
-    def get_warnings(self):
-        return self._cfgimpl_get_toplevel()._cfgimpl_warnings
-
-    def _freeze_(self):
-        self.__dict__['_cfgimpl_frozen'] = True
-        return True
-
-    def getkey(self):
-        return self._cfgimpl_descr.getkey(self)
-
-    def __hash__(self):
-        return hash(self.getkey())
-
-    def __eq__(self, other):
-        return self.getkey() == other.getkey()
-
-    def __ne__(self, other):
-        return not self == other
-
-    def __iter__(self):
-        for child in self._cfgimpl_descr._children:
-            if isinstance(child, Option):
-                yield child._name, getattr(self, child._name)
-
-    def __str__(self, indent=""):
-        lines = []
-        children = [(child._name, child)
-                    for child in self._cfgimpl_descr._children]
-        children.sort()
-        for name, child in children:
-            if self._cfgimpl_value_owners.get(name, None) == 'default':
-                continue
-            value = getattr(self, name)
-            if isinstance(value, Config):
-                substr = value.__str__(indent + "    ")
-            else:
-                substr = "%s    %s = %s" % (indent, name, value)
-            if substr:
-                lines.append(substr)
-        if indent and not lines:
-            return ''   # hide subgroups with all default values
-        lines.insert(0, "%s[%s]" % (indent, self._cfgimpl_descr._name,))
-        return '\n'.join(lines)
-
-    def getpaths(self, include_groups=False):
-        """returns a list of all paths in self, recursively
-        """
-        return self._cfgimpl_descr.getpaths(include_groups=include_groups)
-
-
-DEFAULT_OPTION_NAME = object()
-
-
-class Option(object):
-    __metaclass__ = extendabletype
-
-    def __init__(self, name, doc, cmdline=DEFAULT_OPTION_NAME):
-        self._name = name
-        self.doc = doc
-        self.cmdline = cmdline
-        
-    def validate(self, value):
-        raise NotImplementedError('abstract base class')
-
-    def getdefault(self):
-        return self.default
-
-    def setoption(self, config, value, who):
-        name = self._name
-        if who == "default" and value is None:
-            pass
-        elif not self.validate(value):
-            raise ConfigError('invalid value %s for option %s' % (value, name))
-        config._cfgimpl_values[name] = value
-
-    def getkey(self, value):
-        return value
-
-    def convert_from_cmdline(self, value):
-        return value
-
-    def add_optparse_option(self, argnames, parser, config):
-        callback = ConfigUpdate(config, self)
-        option = parser.add_option(help=self.doc+" %default",
-                                   action='callback', type=self.opt_type,
-                                   callback=callback, metavar=self._name.upper(),
-                                   *argnames)
-
-        
-class ChoiceOption(Option):
-    opt_type = 'string'
-    
-    def __init__(self, name, doc, values, default=None, requires=None,
-                 suggests=None, cmdline=DEFAULT_OPTION_NAME):
-        super(ChoiceOption, self).__init__(name, doc, cmdline)
-        self.values = values
-        self.default = default
-        if requires is None:
-            requires = {}
-        self._requires = requires
-        if suggests is None:
-            suggests = {}
-        self._suggests = suggests
-
-    def setoption(self, config, value, who):
-        name = self._name
-        for path, reqvalue in self._requires.get(value, []):
-            toplevel = config._cfgimpl_get_toplevel()
-            homeconfig, name = toplevel._cfgimpl_get_home_by_path(path)
-            if who == 'default':
-                who2 = 'default'
-            else:
-                who2 = 'required'
-            homeconfig.setoption(name, reqvalue, who2)
-        for path, reqvalue in self._suggests.get(value, []):
-            toplevel = config._cfgimpl_get_toplevel()
-            homeconfig, name = toplevel._cfgimpl_get_home_by_path(path)
-            homeconfig.suggestoption(name, reqvalue)
-        super(ChoiceOption, self).setoption(config, value, who)
-
-    def validate(self, value):
-        return value is None or value in self.values
-
-    def convert_from_cmdline(self, value):
-        return value.strip()
-
-
-def _getnegation(optname):
-    if optname.startswith("without"):
-        return "with" + optname[len("without"):]
-    if optname.startswith("with"):
-        return "without" + optname[len("with"):]
-    return "no-" + optname
-
-class BoolOption(Option):
-    def __init__(self, name, doc, default=None, requires=None,
-                 suggests=None, validator=None,
-                 cmdline=DEFAULT_OPTION_NAME, negation=True):
-        super(BoolOption, self).__init__(name, doc, cmdline=cmdline)
-        self._requires = requires
-        self._suggests = suggests
-        self.default = default
-        self.negation = negation
-        self._validator = validator
-
-    def validate(self, value):
-        return isinstance(value, bool)
-
-    def setoption(self, config, value, who):
-        name = self._name
-        if value and self._validator is not None:
-            toplevel = config._cfgimpl_get_toplevel()
-            self._validator(toplevel)
-        if value and self._requires is not None:
-            for path, reqvalue in self._requires:
-                toplevel = config._cfgimpl_get_toplevel()
-                homeconfig, name = toplevel._cfgimpl_get_home_by_path(path)
-                if who == 'default':
-                    who2 = 'default'
-                else:
-                    who2 = 'required'
-                homeconfig.setoption(name, reqvalue, who2)
-        if value and self._suggests is not None:
-            for path, reqvalue in self._suggests:
-                toplevel = config._cfgimpl_get_toplevel()
-                homeconfig, name = toplevel._cfgimpl_get_home_by_path(path)
-                homeconfig.suggestoption(name, reqvalue)
-
-        super(BoolOption, self).setoption(config, value, who)
-
-    def add_optparse_option(self, argnames, parser, config):
-        callback = BoolConfigUpdate(config, self, True)
-        option = parser.add_option(help=self.doc+" %default",
-                                   action='callback',
-                                   callback=callback, *argnames)
-        if not self.negation:
-            return
-        no_argnames = ["--" + _getnegation(argname.lstrip("-"))
-                           for argname in argnames
-                               if argname.startswith("--")]
-        if len(no_argnames) == 0:
-            no_argnames = ["--" + _getnegation(argname.lstrip("-"))
-                               for argname in argnames]
-        callback = BoolConfigUpdate(config, self, False)
-        option = parser.add_option(help="unset option set by %s %%default" % (argname, ),
-                                   action='callback',
-                                   callback=callback, *no_argnames)
-
-        
-class IntOption(Option):
-    opt_type = 'int'
-    
-    def __init__(self, name, doc, default=None, cmdline=DEFAULT_OPTION_NAME):
-        super(IntOption, self).__init__(name, doc, cmdline)
-        self.default = default
-
-    def validate(self, value):
-        try:
-            int(value)
-        except TypeError:
-            return False
-        return True
-
-    def setoption(self, config, value, who):
-        try:
-            super(IntOption, self).setoption(config, int(value), who)
-        except TypeError, e:
-            raise ConfigError(*e.args)
-
-
-class FloatOption(Option):
-    opt_type = 'float'
-
-    def __init__(self, name, doc, default=None, cmdline=DEFAULT_OPTION_NAME):
-        super(FloatOption, self).__init__(name, doc, cmdline)
-        self.default = default
-
-    def validate(self, value):
-        try:
-            float(value)
-        except TypeError:
-            return False
-        return True
-
-    def setoption(self, config, value, who):
-        try:
-            super(FloatOption, self).setoption(config, float(value), who)
-        except TypeError, e:
-            raise ConfigError(*e.args)
-
-
-class StrOption(Option):
-    opt_type = 'string'
-    
-    def __init__(self, name, doc, default=None, cmdline=DEFAULT_OPTION_NAME):
-        super(StrOption, self).__init__(name, doc, cmdline)
-        self.default = default
-
-    def validate(self, value):
-        return isinstance(value, str)
-
-    def setoption(self, config, value, who):
-        try:
-            super(StrOption, self).setoption(config, value, who)
-        except TypeError, e:
-            raise ConfigError(*e.args)
-
-
-class ArbitraryOption(Option):
-    def __init__(self, name, doc, default=None, defaultfactory=None):
-        super(ArbitraryOption, self).__init__(name, doc, cmdline=None)
-        self.default = default
-        self.defaultfactory = defaultfactory
-        if defaultfactory is not None:
-            assert default is None
-
-    def validate(self, value):
-        return True
-
-    def add_optparse_option(self, *args, **kwargs):
-        return
-
-    def getdefault(self):
-        if self.defaultfactory is not None:
-            return self.defaultfactory()
-        return self.default
-
-
-class OptionDescription(object):
-    __metaclass__ = extendabletype
-
-    cmdline = None
-
-    def __init__(self, name, doc, children):
-        self._name = name
-        self.doc = doc
-        self._children = children
-        self._build()
-
-    def _build(self):
-        for child in self._children:
-            setattr(self, child._name, child)
-
-    def getkey(self, config):
-        return tuple([child.getkey(getattr(config, child._name))
-                      for child in self._children])
-
-    def add_optparse_option(self, argnames, parser, config):
-        return
-
-    def getpaths(self, include_groups=False, currpath=None):
-        """returns a list of all paths in self, recursively
-        
-            currpath should not be provided (helps with recursion)
-        """
-        if currpath is None:
-            currpath = []
-        paths = []
-        for option in self._children:
-            attr = option._name
-            if attr.startswith('_cfgimpl'):
-                continue
-            value = getattr(self, attr)
-            if isinstance(value, OptionDescription):
-                if include_groups:
-                    paths.append('.'.join(currpath + [attr]))
-                currpath.append(attr)
-                paths += value.getpaths(include_groups=include_groups,
-                                        currpath=currpath)
-                currpath.pop()
-            else:
-                paths.append('.'.join(currpath + [attr]))
-        return paths
-
-
-class OptHelpFormatter(optparse.TitledHelpFormatter):
-    extra_useage = None
-
-    def expand_default(self, option):
-        assert self.parser
-        dfls = self.parser.defaults
-        defl = ""
-        choices = None
-        if option.action == 'callback' and isinstance(option.callback, ConfigUpdate):
-            callback = option.callback
-            defl = callback.help_default()
-            if isinstance(callback.option, ChoiceOption):
-                choices = callback.option.values
-        else:
-            val = dfls.get(option.dest)
-            if val is None:
-                pass
-            elif isinstance(val, bool):
-                if val is True and option.action=="store_true":
-                    defl = "default"
-            else:
-                defl = "default: %s" % val
-                
-        if option.type == 'choice':
-            choices = option.choices
-            
-        if choices is not None:
-            choices = "%s=%s" % (option.metavar, '|'.join(choices))
-        else:
-            choices = ""
-        
-        if '%default' in option.help:
-            if choices and defl:
-                sep = ", "
-            else:
-                sep = ""
-            defl = '[%s%s%s]' % (choices, sep, defl)
-            if defl == '[]':
-                defl = ""
-            return option.help.replace("%default", defl)
-        elif choices:
-            return option.help + ' [%s]' % choices 
-
-        return option.help
-
-    def format_usage(self, usage):
-        # XXX bit of a hack
-        result = optparse.TitledHelpFormatter.format_usage(self, usage)
-        if self.extra_useage is not None:
-            return result + "\n" + self.extra_useage + "\n\n"
-        return result
-
-
-
-class ConfigUpdate(object):
-
-    def __init__(self, config, option):
-        self.config = config
-        self.option = option
-
-    def convert_from_cmdline(self, value):
-        return self.option.convert_from_cmdline(value)
-
-    def __call__(self, option, opt_str, value, parser, *args, **kwargs):
-        try:
-            value = self.convert_from_cmdline(value)
-            self.config.setoption(self.option._name, value, who='cmdline')
-        except ConfigError, e:
-            # This OptionValueError is going to exit the translate.py process.
-            # Now is the last chance to print the warnings, which might give
-            # more information...  hack.
-            import sys
-            for warning in self.config.get_warnings():
-                print >> sys.stderr, warning
-            raise optparse.OptionValueError(e.args[0])
-
-    def help_default(self):
-        default = getattr(self.config, self.option._name)
-        owner = self.config._cfgimpl_value_owners[self.option._name]
-        if default is None:
-            if owner == 'default':
-                return ''
-            else:
-                default = '???'
-        return "%s: %s" % (owner, default)
-
-
-class BoolConfigUpdate(ConfigUpdate):
-    def __init__(self, config, option, which_value):
-        super(BoolConfigUpdate, self).__init__(config, option)
-        self.which_value = which_value
-
-    def convert_from_cmdline(self, value):
-        return self.which_value
-
-    def help_default(self):
-        default = getattr(self.config, self.option._name)
-        owner = self.config._cfgimpl_value_owners[self.option._name]
-        if default == self.which_value:
-            return owner
-        else:
-            return ""
-
-
-def to_optparse(config, useoptions=None, parser=None,
-                parserargs=None, parserkwargs=None, extra_useage=None):
-    grps = {}
-    def get_group(name, doc):
-        steps = name.split('.')
-        if len(steps) < 2:
-            return parser
-        grpname = steps[-2]
-        grp = grps.get(grpname, None)
-        if grp is None:
-            grp = grps[grpname] = parser.add_option_group(doc)
-        return grp
-
-    if parser is None:
-        if parserargs is None:
-            parserargs = []
-        if parserkwargs is None:
-            parserkwargs = {}
-        formatter = OptHelpFormatter()
-        formatter.extra_useage = extra_useage
-        parser = optparse.OptionParser(
-            formatter=formatter,
-            *parserargs, **parserkwargs)
-    if useoptions is None:
-        useoptions = config.getpaths(include_groups=True)
-    seen = {}
-    for path in useoptions:
-        if path.endswith(".*"):
-            path = path[:-2]
-            homeconf, name = config._cfgimpl_get_home_by_path(path)
-            subconf = getattr(homeconf, name)
-            children = [
-                path + "." + child
-                for child in subconf.getpaths()]
-            useoptions.extend(children)
-        else:
-            if path in seen:
-                continue
-            seen[path] = True
-            homeconf, name = config._cfgimpl_get_home_by_path(path)
-            option = getattr(homeconf._cfgimpl_descr, name)
-            if option.cmdline is DEFAULT_OPTION_NAME:
-                chunks = ('--%s' % (path.replace('.', '-'),),)
-            elif option.cmdline is None:
-                continue
-            else:
-                chunks = option.cmdline.split(' ')
-            grp = get_group(path, homeconf._cfgimpl_descr.doc)
-            option.add_optparse_option(chunks, grp, homeconf)
-    return parser
-
-
-def make_dict(config):
-    paths = config.getpaths()
-    options = dict([(path, getattr(config, path)) for path in paths])
-    return options
-

File pypy/config/makerestdoc.py

 from pypy.tool.rest.rst import Rest, Paragraph, Strong, ListItem, Title, Link
 from pypy.tool.rest.rst import Directive, Em, Quote, Text
 
-from pypy.config.config import ChoiceOption, BoolOption, StrOption, IntOption
-from pypy.config.config import FloatOption, OptionDescription, Option, Config
-from pypy.config.config import ArbitraryOption, DEFAULT_OPTION_NAME
-from pypy.config.config import _getnegation
+from rpython.config.config import ChoiceOption, BoolOption, StrOption, IntOption
+from rpython.config.config import FloatOption, OptionDescription, Option, Config
+from rpython.config.config import ArbitraryOption, DEFAULT_OPTION_NAME
+from rpython.config.config import _getnegation
 
 configdocdir = py.path.local(__file__).dirpath().dirpath().join("doc", "config")
 

File pypy/config/parse.py

-
-
-def parse_info(text):
-    """See test_parse.py."""
-    text = text.lstrip()
-    result = {}
-    if (text+':').index(':') > (text+'=').index('='):
-        # found a '=' before a ':' means that we have the new format
-        current = {0: ''}
-        indentation_prefix = None
-        for line in text.splitlines():
-            line = line.rstrip()
-            if not line:
-                continue
-            realline = line.lstrip()
-            indent = len(line) - len(realline)
-            #
-            # 'indentation_prefix' is set when the previous line was a [group]
-            if indentation_prefix is not None:
-                assert indent > max(current)     # missing indent?
-                current[indent] = indentation_prefix
-                indentation_prefix = None
-                #
-            else:
-                # in case of dedent, must kill the extra items from 'current'
-                for n in current.keys():
-                    if n > indent:
-                        del current[n]
-            #
-            prefix = current[indent]      # KeyError if bad dedent
-            #
-            if realline.startswith('[') and realline.endswith(']'):
-                indentation_prefix = prefix + realline[1:-1] + '.'
-            else:
-                # build the whole dotted key and evaluate the value
-                i = realline.index(' = ')
-                key = prefix + realline[:i]
-                value = realline[i+3:]
-                value = eval(value, {})
-                result[key] = value
-        #
-    else:
-        # old format
-        for line in text.splitlines():
-            i = line.index(':')
-            key = line[:i].strip()
-            value = line[i+1:].strip()
-            try:
-                value = int(value)
-            except ValueError:
-                if value in ('True', 'False', 'None'):
-                    value = eval(value, {})
-            result[key] = value
-        #
-    return result

File pypy/config/pypyoption.py

 
 import py
 
-from pypy.config.config import (OptionDescription, BoolOption, IntOption,
+from rpython.config.config import (OptionDescription, BoolOption, IntOption,
   ChoiceOption, StrOption, to_optparse, ConflictConfigError)
-from pypy.config.translationoption import IS_64_BITS
+from rpython.config.translationoption import IS_64_BITS
 
 
 modulepath = py.path.local(__file__).dirpath().dirpath().join("module")

File pypy/config/support.py

-
-""" Some support code
-"""
-
-import re, sys, os, subprocess
-
-def detect_number_of_processors(filename_or_file='/proc/cpuinfo'):
-    if os.environ.get('MAKEFLAGS'):
-        return 1    # don't override MAKEFLAGS.  This will call 'make' without any '-j' option
-    if sys.platform == 'darwin':
-        return darwin_get_cpu_count()
-    elif not sys.platform.startswith('linux'):
-        return 1    # implement me
-    try:
-        if isinstance(filename_or_file, str):
-            f = open(filename_or_file, "r")
-        else:
-            f = filename_or_file
-        count = max([int(re.split('processor.*(\d+)', line)[1])
-                    for line in f.readlines()
-                    if line.startswith('processor')]) + 1
-        if count >= 4:
-            return max(count // 2, 3)
-        else:
-            return count
-    except:
-        return 1 # we really don't want to explode here, at worst we have 1
-
-def darwin_get_cpu_count(cmd = "/usr/sbin/sysctl hw.ncpu"):
-    try:
-        proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
-        # 'hw.ncpu: 20'
-        count = proc.communicate()[0].rstrip()[8:]
-        return int(count)
-    except (OSError, ValueError):
-        return 1

File pypy/config/test/test_config.py

-from pypy.config.config import *
-import py, sys
-
-def make_description():
-    gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
-    gcdummy = BoolOption('dummy', 'dummy', default=False)
-    booloption = BoolOption('bool', 'Test boolean option', default=True)
-    intoption = IntOption('int', 'Test int option', default=0)
-    floatoption = FloatOption('float', 'Test float option', default=2.3)
-    stroption = StrOption('str', 'Test string option', default="abc")
-
-    wantref_option = BoolOption('wantref', 'Test requires', default=False,
-                                    requires=[('gc.name', 'ref')])
-    wantframework_option = BoolOption('wantframework', 'Test requires',
-                                      default=False,
-                                      requires=[('gc.name', 'framework')])
-    
-    gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
-    descr = OptionDescription('pypy', '', [gcgroup, booloption,
-                                           wantref_option, stroption,
-                                           wantframework_option,
-                                           intoption])
-    return descr
-
-def test_base_config():
-    descr = make_description()
-    config = Config(descr, bool=False)
-
-    assert config.gc.name == 'ref'
-    config.gc.name = 'framework'
-    assert config.gc.name == 'framework'
-    assert getattr(config, "gc.name") == 'framework'
-
-    assert config.gc.float == 2.3
-    assert config.int == 0
-    config.gc.float = 3.4
-    config.int = 123
-    assert config.gc.float == 3.4
-    assert config.int == 123
-
-    assert not config.wantref
-
-    assert config.str == "abc"
-    config.str = "def"
-    assert config.str == "def"
-
-    py.test.raises(ConfigError, 'config.gc.name = "foo"')
-    py.test.raises(AttributeError, 'config.gc.foo = "bar"')
-    py.test.raises(ConfigError, 'config.bool = 123')
-    py.test.raises(ConfigError, 'config.int = "hello"')
-    py.test.raises(ConfigError, 'config.gc.float = None')
-
-    config = Config(descr, bool=False)
-    assert config.gc.name == 'ref'
-    config.wantframework = True
-    py.test.raises(ConfigError, 'config.gc.name = "ref"')
-    config.gc.name = "framework"
-
-def test___dir__():
-    descr = make_description()
-    config = Config(descr, bool=False)
-    attrs = dir(config)
-    assert '__repr__' in attrs        # from the type
-    assert '_cfgimpl_values' in attrs # from self
-    if sys.version_info >= (2, 6):
-        assert 'gc' in attrs              # custom attribute
-    #
-    attrs = dir(config.gc)
-    if sys.version_info >= (2, 6):
-        assert 'name' in attrs
-        assert 'dummy' in attrs
-        assert 'float' in attrs
-
-def test_arbitrary_option():
-    descr = OptionDescription("top", "", [
-        ArbitraryOption("a", "no help", default=None)
-    ])
-    config = Config(descr)
-    config.a = []
-    config.a.append(1)
-    assert config.a == [1]
-
-    descr = OptionDescription("top", "", [
-        ArbitraryOption("a", "no help", defaultfactory=list)
-    ])
-    c1 = Config(descr)
-    c2 = Config(descr)
-    c1.a.append(1)
-    assert c2.a == []
-    assert c1.a == [1]
-
-def test_annotator_folding():
-    from rpython.translator.interactive import Translation
-
-    gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
-    gcgroup = OptionDescription('gc', '', [gcoption])
-    descr = OptionDescription('pypy', '', [gcgroup])
-    config = Config(descr)
-    
-    def f(x):
-        if config.gc.name == 'ref':
-            return x + 1
-        else:
-            return 'foo'
-
-    t = Translation(f, [int])
-    t.rtype()
-    
-    block = t.context.graphs[0].startblock
-    assert len(block.exits[0].target.operations) == 0
-    assert len(block.operations) == 1
-    assert len(block.exits) == 1
-    assert block.operations[0].opname == 'int_add'
-
-    assert config._freeze_()
-    # does not raise, since it does not change the attribute
-    config.gc.name = "ref"
-    py.test.raises(TypeError, 'config.gc.name = "framework"')
-
-def test_compare_configs():
-    descr = make_description()
-    conf1 = Config(descr)
-    conf2 = Config(descr, wantref=True)
-    assert conf1 != conf2
-    assert hash(conf1) != hash(conf2)
-    assert conf1.getkey() != conf2.getkey()
-    conf1.wantref = True
-    assert conf1 == conf2
-    assert hash(conf1) == hash(conf2)
-    assert conf1.getkey() == conf2.getkey()
-
-def test_loop():
-    descr = make_description()
-    conf = Config(descr)
-    for (name, value), (gname, gvalue) in \
-        zip(conf.gc, [("name", "ref"), ("dummy", False)]):
-        assert name == gname
-        assert value == gvalue
-        
-def test_to_optparse():
-    gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref',
-                                cmdline='--gc -g')
-    gcgroup = OptionDescription('gc', '', [gcoption])
-    descr = OptionDescription('pypy', '', [gcgroup])
-    config = Config(descr)
-    
-    parser = to_optparse(config, ['gc.name'])
-    (options, args) = parser.parse_args(args=['--gc=framework'])
-    
-    assert config.gc.name == 'framework'
-    
-
-    config = Config(descr)
-    parser = to_optparse(config, ['gc.name'])
-    (options, args) = parser.parse_args(args=['-g ref'])
-    assert config.gc.name == 'ref'
-
-    # XXX strange exception
-    py.test.raises(SystemExit,
-                    "(options, args) = parser.parse_args(args=['-g foobar'])")
-
-def test_to_optparse_number():
-    intoption = IntOption('int', 'Int option test', cmdline='--int -i')
-    floatoption = FloatOption('float', 'Float option test', 
-                                cmdline='--float -f')
-    descr = OptionDescription('test', '', [intoption, floatoption])
-    config = Config(descr)
-
-    parser = to_optparse(config, ['int', 'float'])
-    (options, args) = parser.parse_args(args=['-i 2', '--float=0.1'])
-
-    assert config.int == 2
-    assert config.float == 0.1
-    
-    py.test.raises(SystemExit,
-        "(options, args) = parser.parse_args(args=['--int=foo', '-f bar'])")
-    
-def test_to_optparse_bool():
-    booloption1 = BoolOption('bool1', 'Boolean option test', default=False,
-                             cmdline='--bool1 -b')
-    booloption2 = BoolOption('bool2', 'Boolean option test', default=True,
-                             cmdline='--with-bool2 -c')
-    booloption3 = BoolOption('bool3', 'Boolean option test', default=True,
-                             cmdline='--bool3')
-    booloption4 = BoolOption('bool4', 'Boolean option test', default=True,
-                             cmdline='--bool4', negation=False)
-    descr = OptionDescription('test', '', [booloption1, booloption2,
-                                           booloption3, booloption4])
-    config = Config(descr)
-
-    parser = to_optparse(config, ['bool1', 'bool2'])
-    (options, args) = parser.parse_args(args=['-b'])
-
-    assert config.bool1
-    assert config.bool2
-
-    config = Config(descr)
-    parser = to_optparse(config, ['bool1', 'bool2', 'bool3', 'bool4'])
-    (options, args) = parser.parse_args(args=['--without-bool2', '--no-bool3',
-                                              '--bool4'])
-    assert not config.bool1
-    assert not config.bool2
-    assert not config.bool3
-
-    py.test.raises(SystemExit,
-            "(options, args) = parser.parse_args(args=['-bfoo'])")
-    py.test.raises(SystemExit,
-            "(options, args) = parser.parse_args(args=['--no-bool4'])")
-
-def test_config_start():
-    descr = make_description()
-    config = Config(descr)
-    parser = to_optparse(config, ["gc.*"])
-
-    options, args = parser.parse_args(args=["--gc-name=framework", "--gc-dummy"])
-    assert config.gc.name == "framework"
-    assert config.gc.dummy
-
-def test_star_works_recursively():
-    descr = OptionDescription("top", "", [
-        OptionDescription("a", "", [
-            BoolOption("b1", "", default=False, cmdline="--b1"),
-            OptionDescription("sub", "", [
-                BoolOption("b2", "", default=False, cmdline="--b2")
-            ])
-        ]),
-        BoolOption("b3", "", default=False, cmdline="--b3"),
-    ])
-    config = Config(descr)
-    assert not config.a.b1
-    assert not config.a.sub.b2
-    parser = to_optparse(config, ['a.*'])
-    options, args = parser.parse_args(args=["--b1", "--b2"])
-    assert config.a.b1
-    assert config.a.sub.b2
-    py.test.raises(SystemExit,
-            "(options, args) = parser.parse_args(args=['--b3'])")
-
-    config = Config(descr)
-    assert not config.a.b1
-    assert not config.a.sub.b2
-    # does not lead to an option conflict
-    parser = to_optparse(config, ['a.*', 'a.sub.*']) 
-    options, args = parser.parse_args(args=["--b1", "--b2"])
-    assert config.a.b1
-    assert config.a.sub.b2
-    
-def test_optparse_path_options():
-    gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
-    gcgroup = OptionDescription('gc', '', [gcoption])
-    descr = OptionDescription('pypy', '', [gcgroup])
-    config = Config(descr)
-    
-    parser = to_optparse(config, ['gc.name'])
-    (options, args) = parser.parse_args(args=['--gc-name=framework'])
-
-    assert config.gc.name == 'framework'
-
-def test_getpaths():
-    descr = make_description()
-    config = Config(descr)
-    
-    assert config.getpaths() == ['gc.name', 'gc.dummy', 'gc.float', 'bool',
-                                 'wantref', 'str', 'wantframework',
-                                 'int']
-    assert config.getpaths() == descr.getpaths()
-    assert config.gc.getpaths() == ['name', 'dummy', 'float']
-    assert config.gc.getpaths() == descr.gc.getpaths()
-    assert config.getpaths(include_groups=True) == [
-        'gc', 'gc.name', 'gc.dummy', 'gc.float',
-        'bool', 'wantref', 'str', 'wantframework', 'int']
-    assert config.getpaths(True) == descr.getpaths(True)
-
-def test_underscore_in_option_name():
-    descr = OptionDescription("opt", "", [
-        BoolOption("_foobar", "", default=False),
-    ])
-    config = Config(descr)
-    parser = to_optparse(config)
-    assert parser.has_option("--_foobar")
-
-def test_none():
-    dummy1 = BoolOption('dummy1', 'doc dummy', default=False, cmdline=None)
-    dummy2 = BoolOption('dummy2', 'doc dummy', default=False, cmdline='--dummy')
-    group = OptionDescription('group', '', [dummy1, dummy2])
-    config = Config(group)
-
-    parser = to_optparse(config)
-    py.test.raises(SystemExit,
-        "(options, args) = parser.parse_args(args=['--dummy1'])")
- 
-def test_requirements_from_top():
-    descr = OptionDescription("test", '', [
-        BoolOption("toplevel", "", default=False),
-        OptionDescription("sub", '', [
-            BoolOption("opt", "", default=False,
-                       requires=[("toplevel", True)])
-        ])
-    ])
-    config = Config(descr)
-    config.sub.opt = True
-    assert config.toplevel
-
-def test_requirements_for_choice():
-    descr = OptionDescription("test", '', [
-        BoolOption("toplevel", "", default=False),
-        OptionDescription("s", '', [
-            ChoiceOption("type_system", "", ["ll", "oo"], "ll"),
-            ChoiceOption("backend", "",
-                         ["c", "cli"], "c",
-                         requires={
-                             "c": [("s.type_system", "ll"),
-                                   ("toplevel", True)],
-                             "cli": [("s.type_system", "oo")],
-                         })
-        ])
-    ])
-    config = Config(descr)
-    config.s.backend = "cli"
-    assert config.s.type_system == "oo"
-
-def test_choice_with_no_default():
-    descr = OptionDescription("test", "", [
-        ChoiceOption("backend", "", ["c", "cli"])])
-    config = Config(descr)
-    assert config.backend is None
-    config.backend = "c"
-
-def test_overrides_are_defaults():
-    descr = OptionDescription("test", "", [
-        BoolOption("b1", "", default=False, requires=[("b2", False)]),
-        BoolOption("b2", "", default=False),
-        ])
-    config = Config(descr, b2=True)
-    assert config.b2
-    config.b1 = True
-    assert not config.b2
-    print config._cfgimpl_value_owners
-
-def test_overrides_require_as_default():
-    descr = OptionDescription("test", "", [
-        ChoiceOption("backend", "", ['c', 'cli'], 'c',
-                     requires={'c': [('type_system', 'll')],
-                               'cli': [('type_system', 'oo')]}),
-        ChoiceOption("type_system", "", ['ll', 'oo'], 'll')
-        ])
-    config = Config(descr, backend='c')
-    config.set(backend=None, type_system=None)
-    config = Config(descr, backend='c')
-    config.set(backend='cli')
-    assert config.backend == 'cli'
-    assert config.type_system == 'oo'
-
-def test_overrides_require_as_default_boolopt():
-    descr = OptionDescription("test", "", [
-        BoolOption("backend", "", default=False,
-                   requires=[('type_system', True)]),
-        BoolOption("type_system", "", default=False)
-        ])
-    config = Config(descr, backend=True)
-    config.set(backend=False)
-    config.set(type_system=False)
-    assert config.backend == False
-    assert config.type_system == False
-
-def test_overrides_dont_change_user_options():
-    descr = OptionDescription("test", "", [
-        BoolOption("b", "", default=False)])
-    config = Config(descr)
-    config.b = True
-    config.override({'b': False})
-    assert config.b
-    
-def test_str():
-    descr = make_description()
-    c = Config(descr)
-    print c # does not crash
-
-def test_dwim_set():
-    descr = OptionDescription("opt", "", [
-        OptionDescription("sub", "", [
-            BoolOption("b1", ""),
-            ChoiceOption("c1", "", ['a', 'b', 'c'], 'a'),
-            BoolOption("d1", ""),
-        ]),
-        BoolOption("b2", ""),
-        BoolOption("d1", ""),
-    ])
-    c = Config(descr)
-    c.set(b1=False, c1='b')
-    assert not c.sub.b1
-    assert c.sub.c1 == 'b'
-    # new config, because you cannot change values once they are set
-    c = Config(descr)
-    c.set(b2=False, **{'sub.c1': 'c'})
-    assert not c.b2
-    assert c.sub.c1 == 'c'
-    py.test.raises(AmbigousOptionError, "c.set(d1=True)")
-    py.test.raises(NoMatchingOptionFound, "c.set(unknown='foo')")
-
-def test_more_set():
-    descr = OptionDescription("opt", "", [
-        OptionDescription("s1", "", [
-            BoolOption("a", "", default=False)]),
-        IntOption("int", "", default=42)])
-    d = {'s1.a': True, 'int': 23}
-    config = Config(descr)
-    config.set(**d)
-    assert config.s1.a
-    assert config.int == 23
-
-def test_optparse_help():
-    import cStringIO
-    descr = OptionDescription("opt", "", [
-        BoolOption("bool1", 'do bool1', default=False, cmdline='--bool1'),
-        BoolOption("bool2", 'do bool2', default=False, cmdline='--bool2', negation=False),
-        BoolOption("bool3", 'do bool3', default=True, cmdline='--bool3'),
-        ChoiceOption("choice", "choose!", ['a', 'b', 'c'], 'a', '--choice'),
-        ChoiceOption("choice2", "choose2!", ['x', 'y', 'z'], None, '--choice2'),
-        StrOption("str", 'specify xyz', default='hello', cmdline='--str'),
-    ])
-    conf = Config(descr)
-    parser = to_optparse(conf)
-    out = cStringIO.StringIO()
-    parser.print_help(out)
-    help = out.getvalue()
-    #print help
-    assert "do bool1\n" in help
-    assert "unset option set by --bool1 [default]" in help
-    assert "do bool2\n" in help
-    assert "do bool3 [default]" in help
-    assert "choose! [CHOICE=a|b|c, default: a]" in help
-    assert "choose2! [CHOICE2=x|y|z]" in help
-    assert "specify xyz [default: hello]" in help
-
-def test_make_dict():
-    descr = OptionDescription("opt", "", [
-        OptionDescription("s1", "", [
-            BoolOption("a", "", default=False)]),
-        IntOption("int", "", default=42)])
-    config = Config(descr)
-    d = make_dict(config)
-    assert d == {"s1.a": False, "int": 42}
-    config.int = 43
-    config.s1.a = True
-    d = make_dict(config)
-    assert d == {"s1.a": True, "int": 43}
-
-def test_copy():
-    descr = OptionDescription("opt", "", [
-        OptionDescription("s1", "", [
-            BoolOption("a", "", default=False)]),
-        IntOption("int", "", default=42)])
-    c1 = Config(descr)
-    c1.int = 43
-    c2 = c1.copy()
-    assert c2.int == 43
-    assert not c2.s1.a
-    c2.s1.a = True
-    assert c2.s1.a
-    py.test.raises(ConfigError, "c2.int = 44")
-    c2 = c1.copy(as_default=True)
-    assert c2.int == 43
-    assert not c2.s1.a
-    c2.s1.a = True
-    assert c2.s1.a
-    c2.int = 44 # does not crash
-
-def test_bool_suggests():
-    descr = OptionDescription("test", '', [
-        BoolOption("toplevel", "", default=False),
-        BoolOption("opt", "", default=False,
-                   suggests=[("toplevel", True)])
-    ])
-    c = Config(descr)
-    assert not c.toplevel
-    assert not c.opt
-    c.opt = True
-    assert c.opt
-    assert c.toplevel
-    # does not crash
-    c.toplevel = False
-    assert not c.toplevel
-
-    c = Config(descr)
-    c.toplevel = False
-    assert not c.toplevel
-    # does not crash
-    c.opt = True
-    assert c.opt
-    assert not c.toplevel
-
-def test_suggests_can_fail():
-    descr = OptionDescription("test", '', [
-        BoolOption("t1", "", default=False),
-        BoolOption("t2", "", default=False,
-                   requires=[("t3", True)]),
-        BoolOption("t3", "", default=False),
-        BoolOption("opt", "", default=False,
-                   suggests=[("t1", True), ("t2", True)])
-    ])
-    c = Config(descr)
-    assert not c.t1
-    assert not c.t2
-    assert not c.t3
-    assert not c.opt
-    c.opt = True
-    assert c.opt
-    assert c.t1
-    assert c.t2
-    assert c.t3
-    # does not crash
-    c.t2 = False
-    assert not c.t2
-
-    c = Config(descr)
-    c.t3 = False
-    assert not c.t3
-    # does not crash
-    c.opt = True
-    assert c.opt
-    assert not c.t3
-    assert not c.t2
-
-def test_suggests_can_fail_choiceopt():
-    # this is what occurs in "./translate.py --gcrootfinder=asmgcc --jit"
-    # with --jit suggesting the boehm gc, but --gcrootfinder requiring the
-    # framework gctransformer.
-    descr = OptionDescription("test", '', [
-        ChoiceOption("t1", "", ["a", "b"], default="a"),
-        ChoiceOption("t2", "", ["c", "d"], default="c",
-                     requires={"d": [("t3", "f")]}),
-        ChoiceOption("t3", "", ["e", "f"], default="e"),
-        ChoiceOption("opt", "", ["g", "h"], default="g",
-                     suggests={"h": [("t1", "b"), ("t2", "d")]})
-    ])
-    c = Config(descr)
-    assert c.t1 == 'a'
-    assert c.t2 == 'c'
-    assert c.t3 == 'e'
-    assert c.opt == 'g'
-    c.opt = "h"
-    assert c.opt == 'h'
-    assert c.t1 == 'b'
-    assert c.t2 == 'd'
-    assert c.t3 == 'f'
-    # does not crash
-    c.t2 = 'c'
-    assert c.t2 == 'c'
-
-    c = Config(descr)
-    c.t3 = 'e'
-    assert c.t3 == 'e'
-    # does not crash
-    c.opt = 'h'
-    assert c.opt == 'h'
-    assert c.t3 == 'e'
-    assert c.t2 == 'c'
-
-
-def test_choice_suggests():
-    descr = OptionDescription("test", '', [
-        BoolOption("toplevel", "", default=False),
-        ChoiceOption("opt", "", ["a", "b", "c"],
-                     "a",
-                     suggests={"b": [("toplevel", True)]})
-    ])
-    c = Config(descr)
-    assert not c.toplevel
-    assert c.opt == "a"
-    c.opt = "b"
-    assert c.opt == "b"
-    assert c.toplevel
-    # does not crash
-    c.toplevel = False
-    assert not c.toplevel
-
-    c = Config(descr)
-    c.toplevel = False
-    assert not c.toplevel
-    # does not crash
-    c.opt = "b"
-    assert c.opt == "b"
-    assert not c.toplevel
-
-
-def test_bogus_suggests():
-    descr = OptionDescription("test", '', [
-        BoolOption("toplevel", "", suggests=[("opt", "bogusvalue")]),
-        ChoiceOption("opt", "", ["a", "b", "c"], "a"),
-    ])
-    c = Config(descr)
-    py.test.raises(ConfigError, "c.toplevel = True")
-
-
-def test_delattr():
-    descr = OptionDescription("opt", "", [
-    OptionDescription("s1", "", [
-        BoolOption("a", "", default=False)]),
-    IntOption("int", "", default=42)])
-    c = Config(descr)
-    c.int = 45
-    assert c.int == 45
-    del c.int
-    assert c.int == 42
-    c.int = 45
-    assert c.int == 45
-
-def test_validator():
-    def my_validator_1(config):
-        assert config is c
-
-    def my_validator_2(config):
-        assert config is c
-        raise ConflictConfigError
-
-    descr = OptionDescription("opt", "", [
-        BoolOption('booloption1', 'option test1', default=False,
-                   validator=my_validator_1),
-        BoolOption('booloption2', 'option test2', default=False,
-                   validator=my_validator_2),
-        BoolOption('booloption3', 'option test3', default=False,
-                   requires=[("booloption2", True)]),
-        BoolOption('booloption4', 'option test4', default=False,
-                   suggests=[("booloption2", True)]),
-        ])
-    c = Config(descr)
-    c.booloption1 = True
-    py.test.raises(ConfigError, "c.booloption2 = True")
-    assert c.booloption2 is False
-    py.test.raises(ConfigError, "c.booloption3 = True")
-    assert c.booloption2 is False
-    c.booloption4 = True
-    assert c.booloption2 is False
-    c.booloption2 = False
-    assert c.booloption2 is False
-
-def test_suggested_owner_does_not_override():
-    descr = OptionDescription("test", '', [
-        BoolOption("toplevel", "", default=False),
-        BoolOption("opt", "", default=False,
-                   suggests=[("toplevel", False)]),
-        BoolOption("opt2", "", default=False,
-                   suggests=[("toplevel", True)]),
-    ])
-    c = Config(descr)
-    c.toplevel = False
-    c.opt = True      # bug: sets owner of toplevel back to 'suggested'
-    c.opt2 = True     # and this overrides toplevel because it's only suggested
-    assert c.toplevel == False
-    assert c.opt == True
-    assert c.opt2 == True

File pypy/config/test/test_makerestdoc.py

-from pypy.config.config import *
+from rpython.config.config import *
 from pypy.config.makerestdoc import make_cmdline_overview
 
 from pypy.tool.rest.rest import process as restcheck

File pypy/config/test/test_parse.py

-from pypy.config.parse import parse_info
-
-
-def test_parse_new_format():
-    assert (parse_info("[foo]\n"
-                       "    bar = True\n")
-            == {'foo.bar': True})
-    
-    assert (parse_info("[objspace]\n"
-                       "    x = 'hello'\n"
-                       "[translation]\n"
-                       "    bar = 42\n"
-                       "    [egg]\n"
-                       "        something = None\n"
-                       "    foo = True\n")
-            == {
-        'translation.foo': True,
-        'translation.bar': 42,
-        'translation.egg.something': None,
-        'objspace.x': 'hello',
-        })
-
-    assert parse_info("simple = 43\n") == {'simple': 43}
-
-
-def test_parse_old_format():
-    assert (parse_info("                          objspace.allworkingmodules: True\n"
-                       "                    objspace.disable_call_speedhacks: False\n"
-                       "                                 objspace.extmodules: None\n"
-                       "                        objspace.std.prebuiltintfrom: -5\n")
-            == {
-        'objspace.allworkingmodules': True,
-        'objspace.disable_call_speedhacks': False,
-        'objspace.extmodules': None,
-        'objspace.std.prebuiltintfrom': -5,
-        })

File pypy/config/test/test_pypyoption.py

 import py
 from pypy.config.pypyoption import get_pypy_config, set_pypy_opt_level
-from pypy.config.config import Config, ConfigError
-from pypy.config.translationoption import set_opt_level
+from rpython.config.config import Config, ConfigError
+from rpython.config.translationoption import set_opt_level
 
 thisdir = py.path.local(__file__).dirpath()
 

File pypy/config/test/test_support.py

-
-from cStringIO import StringIO
-from pypy.config import support
-import os, sys, py
-
-cpuinfo = """
-processor\t: 0
-
-processor\t: 1
-vendor_id\t: GenuineIntel
-cpu family\t: 6
-model\t\t: 37
-model name\t: Intel(R) Core(TM) i7 CPU       L 620  @ 2.00GHz
-stepping\t: 2
-
-processor\t: 2
-vendor_id\t: GenuineIntel
-cpu family\t: 6
-model\t\t: 37
-model name\t: Intel(R) Core(TM) i7 CPU       L 620  @ 2.00GHz
-stepping\t: 2
-
-processor\t: 3
-vendor_id\t: GenuineIntel
-cpu family\t: 6
-model\t\t: 37
-model name\t: Intel(R) Core(TM) i7 CPU       L 620  @ 2.00GHz
-stepping\t: 2
-cpu MHz\t\t: 1199.000
-cache size\t: 4096 KB
-physical id\t: 0
-siblings\t: 4
-"""
-
-class FakeEnviron:
-    def __init__(self, value):
-        self._value = value
-    def get(self, varname):
-        assert varname == 'MAKEFLAGS'
-        return self._value
-
-def test_cpuinfo_linux():
-    if not sys.platform.startswith('linux'):
-        py.test.skip("linux only")
-    saved = os.environ
-    try:
-        os.environ = FakeEnviron(None)
-        assert support.detect_number_of_processors(StringIO(cpuinfo)) == 3
-        assert support.detect_number_of_processors('random crap that does not exist') == 1
-        os.environ = FakeEnviron('-j2')
-        assert support.detect_number_of_processors(StringIO(cpuinfo)) == 1
-    finally:
-        os.environ = saved
-
-def test_cpuinfo_darwin():
-    if sys.platform != 'darwin':
-        py.test.skip('mac only')
-    saved_func = support.darwin_get_cpu_count
-    saved = os.environ
-    def count():
-        return 42
-    try:
-        support.darwin_get_cpu_count = count
-        os.environ = FakeEnviron(None)
-        assert support.detect_number_of_processors() == 42
-        os.environ = FakeEnviron('-j2')
-        assert support.detect_number_of_processors() == 1
-    finally:
-        os.environ = saved
-        support.darwin_get_cpu_count = saved_func
-
-def test_darwin_get_cpu_count():
-    if sys.platform != 'darwin':
-        py.test.skip('mac only')
-    assert support.darwin_get_cpu_count() > 0 # hopefully
-    assert support.darwin_get_cpu_count("false") == 1

File pypy/config/test/test_translationoption.py

-import py
-from pypy.config.translationoption import get_combined_translation_config
-from pypy.config.translationoption import set_opt_level
-from pypy.config.config import ConflictConfigError
-
-
-def test_no_gcrootfinder_with_boehm():
-    config = get_combined_translation_config()
-    config.translation.gcrootfinder = "shadowstack"
-    py.test.raises(ConflictConfigError, set_opt_level, config, '0')

File pypy/config/translationoption.py

-import py, os, sys
-from pypy.config.config import OptionDescription, BoolOption, IntOption, ArbitraryOption, FloatOption
-from pypy.config.config import ChoiceOption, StrOption, to_optparse, Config
-from pypy.config.config import ConfigError
-from pypy.config.support import detect_number_of_processors
-
-DEFL_INLINE_THRESHOLD = 32.4    # just enough to inline add__Int_Int()
-# and just small enough to prevend inlining of some rlist functions.
-
-DEFL_PROF_BASED_INLINE_THRESHOLD = 32.4
-DEFL_CLEVER_MALLOC_REMOVAL_INLINE_THRESHOLD = 32.4
-DEFL_LOW_INLINE_THRESHOLD = DEFL_INLINE_THRESHOLD / 2.0
-
-DEFL_GC = "minimark"
-if sys.platform.startswith("linux"):
-    DEFL_ROOTFINDER_WITHJIT = "asmgcc"
-else:
-    DEFL_ROOTFINDER_WITHJIT = "shadowstack"
-
-IS_64_BITS = sys.maxint > 2147483647
-
-PLATFORMS = [
-    'maemo',
-    'host',
-    'distutils',
-    'arm',
-]
-
-translation_optiondescription = OptionDescription(
-        "translation", "Translation Options", [
-    BoolOption("continuation", "enable single-shot continuations",
-               default=False, cmdline="--continuation",
-               requires=[("translation.type_system", "lltype")]),
-    ChoiceOption("type_system", "Type system to use when RTyping",
-                 ["lltype", "ootype"], cmdline=None, default="lltype",
-                 requires={
-                     "ootype": [
-                                ("translation.backendopt.constfold", False),
-                                ("translation.backendopt.clever_malloc_removal", False),
-                                ("translation.gc", "boehm"), # it's not really used, but some jit code expects a value here
-                                ]
-                     }),
-    ChoiceOption("backend", "Backend to use for code generation",
-                 ["c", "cli", "jvm"], default="c",
-                 requires={
-                     "c":      [("translation.type_system", "lltype")],
-                     "cli":    [("translation.type_system", "ootype")],
-                     "jvm":    [("translation.type_system", "ootype")],
-                     },
-                 cmdline="-b --backend"),
-
-    BoolOption("shared", "Build as a shared library",
-               default=False, cmdline="--shared"),
-
-    BoolOption("log", "Include debug prints in the translation (PYPYLOG=...)",
-               default=True, cmdline="--log"),
-
-    # gc
-    ChoiceOption("gc", "Garbage Collection Strategy",
-                 ["boehm", "ref", "semispace", "statistics",
-                  "generation", "hybrid", "minimark", "none"],
-                  "ref", requires={
-                     "ref": [("translation.rweakref", False), # XXX
-                             ("translation.gctransformer", "ref")],
-                     "none": [("translation.rweakref", False), # XXX
-                             ("translation.gctransformer", "none")],
-                     "semispace": [("translation.gctransformer", "framework")],
-                     "statistics": [("translation.gctransformer", "framework")],
-                     "generation": [("translation.gctransformer", "framework")],
-                     "hybrid": [("translation.gctransformer", "framework")],
-                     "boehm": [("translation.continuation", False),  # breaks
-                               ("translation.gctransformer", "boehm")],
-                     "minimark": [("translation.gctransformer", "framework")],
-                     },
-                  cmdline="--gc"),
-    ChoiceOption("gctransformer", "GC transformer that is used - internal",
-                 ["boehm", "ref", "framework", "none"],
-                 default="ref", cmdline=None,
-                 requires={
-                     "boehm": [("translation.gcrootfinder", "n/a"),
-                               ("translation.gcremovetypeptr", False)],
-                     "ref": [("translation.gcrootfinder", "n/a"),
-                             ("translation.gcremovetypeptr", False)],
-                     "none": [("translation.gcrootfinder", "n/a"),
-                              ("translation.gcremovetypeptr", False)],
-                 }),
-    BoolOption("gcremovetypeptr", "Remove the typeptr from every object",
-               default=IS_64_BITS, cmdline="--gcremovetypeptr"),
-    ChoiceOption("gcrootfinder",
-                 "Strategy for finding GC Roots (framework GCs only)",
-                 ["n/a", "shadowstack", "asmgcc"],
-                 "shadowstack",
-                 cmdline="--gcrootfinder",
-                 requires={
-                     "shadowstack": [("translation.gctransformer", "framework")],
-                     "asmgcc": [("translation.gctransformer", "framework"),
-                                ("translation.backend", "c")],
-                    }),
-
-    # other noticeable options
-    BoolOption("thread", "enable use of threading primitives",
-               default=False, cmdline="--thread"),
-    BoolOption("sandbox", "Produce a fully-sandboxed executable",
-               default=False, cmdline="--sandbox",
-               requires=[("translation.thread", False)],
-               suggests=[("translation.gc", "generation"),
-                         ("translation.gcrootfinder", "shadowstack")]),
-    BoolOption("rweakref", "The backend supports RPython-level weakrefs",
-               default=True),
-
-    # JIT generation: use -Ojit to enable it
-    BoolOption("jit", "generate a JIT",
-               default=False,
-               suggests=[("translation.gc", DEFL_GC),
-                         ("translation.gcrootfinder", DEFL_ROOTFINDER_WITHJIT),
-                         ("translation.list_comprehension_operations", True)]),
-    ChoiceOption("jit_backend", "choose the backend for the JIT",
-                 ["auto", "x86", "x86-without-sse2", 'arm'],
-                 default="auto", cmdline="--jit-backend"),
-    ChoiceOption("jit_profiler", "integrate profiler support into the JIT",
-                 ["off", "oprofile"],
-                 default="off"),
-    BoolOption("check_str_without_nul",
-               "Forbid NUL chars in strings in some external function calls",
-               default=False, cmdline=None),
-
-    # misc
-    BoolOption("verbose", "Print extra information", default=False),
-    StrOption("cc", "Specify compiler to use for compiling generated C", cmdline="--cc"),
-    StrOption("profopt", "Specify profile based optimization script",
-              cmdline="--profopt"),
-    BoolOption("noprofopt", "Don't use profile based optimization",
-               default=False, cmdline="--no-profopt", negation=False),
-    BoolOption("instrument", "internal: turn instrumentation on",
-               default=False, cmdline=None),
-    BoolOption("countmallocs", "Count mallocs and frees", default=False,
-               cmdline=None),
-    ChoiceOption("fork_before",
-                 "(UNIX) Create restartable checkpoint before step",
-                 ["annotate", "rtype", "backendopt", "database", "source",
-                  "pyjitpl"],
-                 default=None, cmdline="--fork-before"),
-    BoolOption("dont_write_c_files",
-               "Make the C backend write everyting to /dev/null. " +
-               "Useful for benchmarking, so you don't actually involve the disk",
-               default=False, cmdline="--dont-write-c-files"),
-    ArbitraryOption("instrumentctl", "internal",
-               default=None),
-    StrOption("output", "Output file name", cmdline="--output"),
-    StrOption("secondaryentrypoints",
-            "Comma separated list of keys choosing secondary entrypoints",
-            cmdline="--entrypoints", default=""),
-
-    BoolOption("dump_static_data_info", "Dump static data info",
-               cmdline="--dump_static_data_info",
-               default=False, requires=[("translation.backend", "c")]),
-
-    # portability options
-    BoolOption("no__thread",
-               "don't use __thread for implementing TLS",
-               default=False, cmdline="--no__thread", negation=False),
-##  --- not supported since a long time.  Use the env vars CFLAGS/LDFLAGS.
-##    StrOption("compilerflags", "Specify flags for the C compiler",
-##               cmdline="--cflags"),
-##    StrOption("linkerflags", "Specify flags for the linker (C backend only)",
-##               cmdline="--ldflags"),
-    IntOption("make_jobs", "Specify -j argument to make for compilation"
-              " (C backend only)",
-              cmdline="--make-jobs", default=detect_number_of_processors()),
-
-    # Flags of the TranslationContext:
-    BoolOption("simplifying", "Simplify flow graphs", default=True),
-    BoolOption("list_comprehension_operations",
-               "When true, look for and special-case the sequence of "
-               "operations that results from a list comprehension and "
-               "attempt to pre-allocate the list",
-               default=False,
-               cmdline='--listcompr'),
-    IntOption("withsmallfuncsets",
-              "Represent groups of less funtions than this as indices into an array",
-               default=0),
-    BoolOption("taggedpointers",
-               "When true, enable the use of tagged pointers. "
-               "If false, use normal boxing",
-               default=False),
-
-    # options for ootype
-    OptionDescription("ootype", "Object Oriented Typesystem options", [
-        BoolOption("mangle", "Mangle names of class members", default=True),
-    ]),
-
-    OptionDescription("backendopt", "Backend Optimization Options", [
-        # control inlining
-        BoolOption("inline", "Do basic inlining and malloc removal",
-                   default=True),
-        FloatOption("inline_threshold", "Threshold when to inline functions",
-                  default=DEFL_INLINE_THRESHOLD, cmdline="--inline-threshold"),
-        StrOption("inline_heuristic", "Dotted name of an heuristic function "
-                  "for inlining",
-                default="rpython.translator.backendopt.inline.inlining_heuristic",
-                cmdline="--inline-heuristic"),
-
-        BoolOption("print_statistics", "Print statistics while optimizing",
-                   default=False),
-        BoolOption("merge_if_blocks", "Merge if ... elif chains",
-                   cmdline="--if-block-merge", default=True),
-        BoolOption("raisingop2direct_call",
-                   "Transform operations that can implicitly raise an "
-                   "exception into calls to functions that explicitly "
-                   "raise exceptions",
-                   default=False, cmdline="--raisingop2direct_call"),
-        BoolOption("mallocs", "Remove mallocs", default=True),
-        BoolOption("constfold", "Constant propagation",
-                   default=True),
-        # control profile based inlining
-        StrOption("profile_based_inline",
-                  "Use call count profiling to drive inlining"
-                  ", specify arguments",
-                  default=None),   # cmdline="--prof-based-inline" fix me
-        FloatOption("profile_based_inline_threshold",
-                    "Threshold when to inline functions "
-                    "for profile based inlining",
-                  default=DEFL_PROF_BASED_INLINE_THRESHOLD,
-                  ),   # cmdline="--prof-based-inline-threshold" fix me
-        StrOption("profile_based_inline_heuristic",
-                  "Dotted name of an heuristic function "
-                  "for profile based inlining",
-                default="rpython.translator.backendopt.inline.inlining_heuristic",
-                ),  # cmdline="--prof-based-inline-heuristic" fix me
-        # control clever malloc removal
-        BoolOption("clever_malloc_removal",
-                   "Drives inlining to remove mallocs in a clever way",
-                   default=False,
-                   cmdline="--clever-malloc-removal"),
-        FloatOption("clever_malloc_removal_threshold",
-                    "Threshold when to inline functions in "
-                    "clever malloc removal",
-                  default=DEFL_CLEVER_MALLOC_REMOVAL_INLINE_THRESHOLD,
-                  cmdline="--clever-malloc-removal-threshold"),
-        StrOption("clever_malloc_removal_heuristic",
-                  "Dotted name of an heuristic function "
-                  "for inlining in clever malloc removal",
-                default="rpython.translator.backendopt.inline.inlining_heuristic",
-                cmdline="--clever-malloc-removal-heuristic"),
-
-        BoolOption("remove_asserts",
-                   "Remove operations that look like 'raise AssertionError', "
-                   "which lets the C optimizer remove the asserts",
-                   default=False),
-        BoolOption("really_remove_asserts",
-                   "Really remove operations that look like 'raise AssertionError', "
-                   "without relying on the C compiler",
-                   default=False),
-
-        BoolOption("stack_optimization",
-                   "Tranform graphs in SSI form into graphs tailored for "
-                   "stack based virtual machines (only for backends that support it)",
-                   default=True),
-        BoolOption("storesink", "Perform store sinking", default=True),
-        BoolOption("none",
-                   "Do not run any backend optimizations",
-                   requires=[('translation.backendopt.inline', False),
-                             ('translation.backendopt.inline_threshold', 0),
-                             ('translation.backendopt.merge_if_blocks', False),
-                             ('translation.backendopt.mallocs', False),
-                             ('translation.backendopt.constfold', False)])
-    ]),
-
-    OptionDescription("cli", "GenCLI options", [
-        BoolOption("trace_calls", "Trace function calls", default=False,
-                   cmdline="--cli-trace-calls"),
-        BoolOption("exception_transformer", "Use exception transformer", default=False),
-    ]),
-    ChoiceOption("platform",
-                 "target platform", ['host'] + PLATFORMS, default='host',
-                 cmdline='--platform'),
-
-])
-
-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
-
-# ____________________________________________________________
-
-OPT_LEVELS = ['0', '1', 'size', 'mem', '2', '3', 'jit']
-DEFAULT_OPT_LEVEL = '2'
-
-OPT_TABLE_DOC = {
-    '0':    'No optimization.  Uses the Boehm GC.',
-    '1':    'Enable a default set of optimizations.  Uses the Boehm GC.',
-    'size': 'Optimize for the size of the executable.  Uses the Boehm GC.',
-    'mem':  'Optimize for run-time memory usage and use a memory-saving GC.',
-    '2':    'Enable most optimizations and use a high-performance GC.',
-    '3':    'Enable all optimizations and use a high-performance GC.',
-    'jit':  'Enable the JIT.',
-    }
-
-OPT_TABLE = {
-    #level:  gc          backend optimizations...
-    '0':    'boehm       nobackendopt',
-    '1':    'boehm       lowinline',
-    'size': 'boehm       lowinline     remove_asserts',
-    'mem':  DEFL_GC + '  lowinline     remove_asserts    removetypeptr',
-    '2':    DEFL_GC + '  extraopts',
-    '3':    DEFL_GC + '  extraopts     remove_asserts',
-    'jit':  DEFL_GC + '  extraopts     jit',
-    }
-
-def final_check_config(config):
-    # XXX: this should be a real config option, but it is hard to refactor it;
-    # instead, we "just" patch it from here
-    from rpython.rlib import rfloat
-    if config.translation.type_system == 'ootype':
-        rfloat.USE_SHORT_FLOAT_REPR = False
-
-def set_opt_level(config, level):
-    """Apply optimization suggestions on the 'config'.
-    The optimizations depend on the selected level and possibly on the backend.
-    """
-    # warning: during some tests, the type_system and the backend may be
-    # unspecified and we get None.  It shouldn't occur in translate.py though.
-    type_system = config.translation.type_system
-    backend = config.translation.backend
-
-    try:
-        opts = OPT_TABLE[level]
-    except KeyError:
-        raise ConfigError("no such optimization level: %r" % (level,))
-    words = opts.split()
-    gc = words.pop(0)
-
-    # set the GC (only meaningful with lltype)
-    # but only set it if it wasn't already suggested to be something else
-    if config.translation._cfgimpl_value_owners['gc'] != 'suggested':
-        config.translation.suggest(gc=gc)
-
-    # set the backendopts
-    for word in words:
-        if word == 'nobackendopt':
-            config.translation.backendopt.suggest(none=True)
-        elif word == 'lowinline':
-            config.translation.backendopt.suggest(inline_threshold=
-                                                DEFL_LOW_INLINE_THRESHOLD)
-        elif word == 'remove_asserts':
-            config.translation.backendopt.suggest(remove_asserts=True)
-        elif word == 'extraopts':
-            config.translation.suggest(withsmallfuncsets=5)
-        elif word == 'jit':
-            config.translation.suggest(jit=True)
-        elif word == 'removetypeptr':
-            config.translation.suggest(gcremovetypeptr=True)
-        else:
-            raise ValueError(word)
-
-    # list_comprehension_operations is needed for translation, because
-    # make_sure_not_resized often relies on it, so we always enable them
-    config.translation.suggest(list_comprehension_operations=True)
-
-    # finally, make the choice of the gc definitive.  This will fail
-    # if we have specified strange inconsistent settings.
-    config.translation.gc = config.translation.gc
-
-# ----------------------------------------------------------------
-
-def set_platform(config):
-    from rpython.translator.platform import set_platform
-    set_platform(config.translation.platform, config.translation.cc)
-
-def get_platform(config):
-    from rpython.translator.platform import pick_platform
-    opt = config.translation.platform
-    cc = config.translation.cc
-    return pick_platform(opt, cc)

File pypy/conftest.py

     option = config.option
 
 def _set_platform(opt, opt_str, value, parser):
-    from pypy.config.translationoption import PLATFORMS
+    from rpython.config.translationoption import PLATFORMS
     from rpython.translator.platform import set_platform
     if value not in PLATFORMS:
         raise ValueError("%s not in %s" % (value, PLATFORMS))

File pypy/doc/config/confrest.py

 from pypy.doc.confrest import *
 from pypy.config.makerestdoc import make_cmdline_overview
-from pypy.config.config import Config
-from pypy.config import pypyoption, translationoption
+from pypy.config import pypyoption
+from rpython.config.config import Config
+from rpython.config import translationoption