def __attrs_post_init__(self): """ In case conda or pip are filenames pointing to existing files, read the files and populate the package names """ if self.conda_file: # use the dependencies from the conda file. Override conda, pip and conda_file deps = read_yaml(self.conda_file) pip_deps = [ x['pip'] for x in deps['dependencies'] if isinstance(x, dict) ][0] conda_deps = [ x for x in deps['dependencies'] if not isinstance(x, dict) ] object.__setattr__(self, "pip", pip_deps) object.__setattr__(self, "conda", conda_deps) object.__setattr__(self, "conda_channels", deps['channels']) if len(self.conda) == 1 and self.conda[0].endswith(".txt") and \ os.path.exists(self.conda[0]): # found a conda txt file object.__setattr__(self, "conda", read_txt(self.conda[0])) if len(self.pip) == 1 and self.pip[0].endswith(".txt") and \ os.path.exists(self.pip[0]): # found a pip txt file object.__setattr__(self, "pip", read_txt(self.pip[0]))
def __attrs_post_init__(self): """ In case conda or pip are filenames pointing to existing files, read the files and populate the package names """ if len(self.conda) == 1 and self.conda[0].endswith(".txt") and \ os.path.exists(self.conda[0]): # found a conda txt file object.__setattr__(self, "conda", read_txt(self.conda[0])) if len(self.pip) == 1 and self.pip[0].endswith(".txt") and \ os.path.exists(self.pip[0]): # found a pip txt file object.__setattr__(self, "pip", read_txt(self.pip[0]))
def all_models_to_test(src): """Returns a list of models to test By default, this method returns all the model. In case a model group has a `test_subset.txt` file present in the group directory, then testing is only performed for models listed in `test_subset.txt`. Args: src: Model source """ txt_files = list_files_recursively(src.local_path, "test_subset", "txt") exclude = [] include = [] for x in txt_files: d = os.path.dirname(x) exclude += [d] include += [ os.path.join(d, l) for l in read_txt(os.path.join(src.local_path, x)) ] # try to load every model extra included -- will get tested downstream # for m in include: # src.get_model_descr(m) models = src.list_models().model for excl in exclude: models = models[~models.str.startswith(excl)] return list(models) + include
def test_read_txt(): lines = read_txt("tests/data/conda_requirements.txt") assert lines == ["conda_dep1", "conda_dep2"]