def create_instance(self, family_name, instance_name_or_spec): dtu.check_isinstance(instance_name_or_spec, (dict, str)) family = self.get_family(family_name) if not family.valid: msg = ('Cannot instantiate %r because its family %r is invalid.' % (instance_name_or_spec, family_name)) msg += '\n\n' + dtu.indent(family.error_if_invalid, " > ") raise dtu.DTConfigException(msg) if isinstance(instance_name_or_spec, str): instance_name = instance_name_or_spec dtu.check_is_in('instance', instance_name, family.instances) instance = family.instances[instance_name] if not instance.valid: msg = ('Cannot instantiate %r because it is invalid:\n%s' % (instance_name, dtu.indent(instance.error_if_invalid, '> '))) raise dtu.DTConfigException(msg) res = dtu.instantiate(instance.constructor, instance.parameters) elif isinstance(instance_name_or_spec, dict): _name, spec = _parse_inline_spec(instance_name_or_spec) res = dtu.instantiate(spec.constructor, spec.parameters) else: assert False interface = dtu.import_name(family.interface) if not isinstance(res, interface): msg = ('I expected that %r would be a %s but it is a %s.' % (instance_name, interface.__name__, type(res).__name__)) raise dtu.DTConfigException(msg) return res
def eval_name(x, name_tuple): if not name_tuple: return x else: first = name_tuple[0] rest = name_tuple[1:] dtu.check_is_in('value', first, x, EvaluationError) xx = x[first] return eval_name(xx, rest)
def eval(self, rdb): db_entry = rdb.query_results_one(branch=self.branch, date=self.date, commit=self.commit) check_isinstance(db_entry, ResultDBEntry) # print('Results= %s' % db_entry.__repr__()) results = db_entry.results dtu.check_is_in('analyzer', self.analyzer, results, EvaluationError) logs = results[self.analyzer] dtu.check_is_in('log', self.log, logs, EvaluationError) forlog = logs[self.log] val = eval_name(forlog, self.statistic) return val
def create_instance(self, family_name, instance_name): family = self.get_family(family_name) if not family.valid: msg = ('Cannot instantiate %r because its family %r is invalid.' % (instance_name, family_name)) raise DTConfigException(msg) check_is_in('instance', instance_name, family.instances) instance = family.instances[instance_name] if not instance.valid: msg = ('Cannot instantiate because it is invalid:\n%s' % indent(instance.error_if_invalid, '> ')) raise DTConfigException(msg) res = instantiate(instance.constructor, instance.parameters) interface = import_name(family.interface) if not isinstance(res, interface): msg = ('I expected that %r would be a %s but it is a %s.' % (instance_name, interface.__name__, type(res).__name__)) raise DTConfigException(msg) return res
def get_family(self, x): dtu.check_is_in('family', x, self.family_name2config) return self.family_name2config[x]