def __attrs_post_init__(self): if self.doc == "": logger.warning("doc empty for one of the dataloader `args` fields") # parse args self.example = recursive_dict_parse(self.example, 'url', RemoteFile.from_config) self.default = recursive_dict_parse(self.default, 'url', RemoteFile.from_config)
def __attrs_post_init__(self): if self.defined_as is None and self.type is None: raise ValueError("Either defined_as or type need to be specified") # load additional objects for k in self.postprocessing: k_observed = k if k == 'variant_effects': k = 'kipoi_veff' if is_installed(k): # Load the config properly if the plugin is installed try: parser = get_model_yaml_parser(k) self.postprocessing[k_observed] = parser.from_config( self.postprocessing[k_observed]) object.__setattr__(self, "postprocessing", self.postprocessing) except Exception: logger.warning( "Unable to parse {} filed in ModelDescription: {}". format(k_observed, self)) # parse args self.args = recursive_dict_parse(self.args, 'url', RemoteFile.from_config) # parse default_dataloader if isinstance(self.default_dataloader, dict): self.default_dataloader = DataLoaderImport.from_config( self.default_dataloader)
def __attrs_post_init__(self): if self.defined_as is None and self.type is None: raise ValueError("Either defined_as or type need to be specified") self.args = recursive_dict_parse(self.args, 'url', RemoteFile.from_config) # parse default_dataloader if isinstance(self.default_dataloader, dict): self.default_dataloader = DataLoaderImport.from_config( self.default_dataloader)
def test_recursive_dict_parse(): def f_must_not_be_called(d): assert False # <= should not be called a = {"a": 1, "b": 2} assert a == recursive_dict_parse(a, "url", f_must_not_be_called) a = {"a": 1, "b": 2, "c": {"e": 3}} assert a == recursive_dict_parse(a, "url", f_must_not_be_called) def f_must_be_called(d): assert 'url' in d assert 'md5' in d assert 'foo' not in d ret = { 'url' : d['url'] + 'new1', 'md5' : d['md5'] + 'new2', 'foo' : 'bar' } return ret a = {"a": 1, "b": 2, "c": {"url": "a", "md5": "b"}} out = recursive_dict_parse(a, "url", f_must_be_called) assert a != out assert out['a'] == a['a'] assert out['b'] == a['b'] assert out['c'] == {'url':'anew1','md5':"bnew2",'foo':'bar'} a = {"a": 1, "b": 2, "c": [{"url": "a", "md5": "b"}]} out = recursive_dict_parse(a, "url", f_must_be_called) assert a != out assert out['a'] == a['a'] assert out['b'] == a['b'] assert out['c'] == [{'url':'anew1','md5':"bnew2",'foo':'bar'}]