Ejemplo n.º 1
0
        def interpret_instance_spec(filename, data):
            dtu.dt_check_isinstance('data', data, dict)

            basename = os.path.basename(filename)
            instance_name = dtu.id_from_basename_pattern(
                basename, c.instances_pattern)

            if c.default_constructor is not None and not 'constructor' in data:
                description = '(not given)'
                constructor = c.default_constructor
                parameters = OrderedDict(data)
            else:
                description = data.pop('description')
                dtu.dt_check_isinstance('description', description, str)

                constructor = data.pop('constructor')
                dtu.dt_check_isinstance('constructor', constructor, str)

                parameters = data.pop('parameters')
                dtu.dt_check_isinstance('parameters', parameters,
                                        (dict, NoneType))

                if parameters is None: parameters = {}

            return EasyAlgoInstance(family_name=c.family_name,
                                    instance_name=instance_name,
                                    description=description,
                                    filename=filename,
                                    constructor=constructor,
                                    parameters=parameters,
                                    valid=True,
                                    error_if_invalid=None)
Ejemplo n.º 2
0
def interpret_easy_algo_config(filename, data):
    """ Interprets the family config """
    basename = os.path.basename(filename)
    family_name = dtu.id_from_basename_pattern(basename, EasyAlgoDB.pattern)
    instances_pattern = '*.%s.yaml' % family_name
    #     tests_pattern = '*.%s_test.yaml' % family_name

    dtu.dt_check_isinstance('contents', data, dict)

    description = data.pop('description')
    dtu.dt_check_isinstance('description', description, str)

    interface = data.pop('interface')
    dtu.dt_check_isinstance('interface', interface, str)

    locations = data.pop('locations', None)
    default_constructor = data.pop('default_constructor', None)

    if data:
        msg = 'Extra keys in configuration: %s' % list(data)
        raise dtu.DTConfigException(msg)

    return EasyAlgoFamily(interface=interface,
                          family_name=family_name,
                          filename=filename,
                          instances=None,
                          instances_pattern=instances_pattern,
                          description=description,
                          valid=True,
                          locations=locations,
                          default_constructor=default_constructor,
                          error_if_invalid=False)
Ejemplo n.º 3
0
def _parse_inline_spec(x):
    dtu.check_isinstance(x, dict)
    if len(x) != 1:
        msg = 'Invalid spec: length is %d' % len(x)
        dtu.raise_desc(ValueError, msg, x=x)
    key = list(x)[0]
    value = x[key]

    value = copy.deepcopy(value)
    if 'description' in value:
        description = value.pop('description')
        dtu.dt_check_isinstance('description', description, str)
    else:
        description = None

    constructor = value.pop('constructor')
    dtu.dt_check_isinstance('constructor', constructor, str)

    parameters = value.pop('parameters')
    dtu.dt_check_isinstance('parameters', parameters, (dict, NoneType))

    if parameters is None: parameters = {}

    res = SpecValues(constructor=constructor,
                     parameters=parameters,
                     description=description)
    return key, res