def assert_valid_function_iv(self, iv: ItemView, pipeline_manager: PipelineManager): assert isinstance(iv, ItemView) assert iv() == pipeline_manager.run(iv) assert iv.item() == pipeline_manager.get(iv)() iv2 = ItemView.from_section_path_str(iv._section_path_str) assert iv == iv2 assert iv2 in [iv] assert iv == list({iv})[0] assert {iv: 5}[iv] == 5 assert iv.type == type(a_function) assert isinstance(iv, type(a_function)) assert hash(iv) == hash(iv.section_path_str)
def assert_valid_specific_class_iv(self, iv: ItemView, pipeline_manager: PipelineManager): assert isinstance(iv, ItemView) assert iv() == pipeline_manager.get(iv)() assert iv() == pipeline_manager.run(iv) assert iv.a == pipeline_manager.get(iv).a assert iv.item() == pipeline_manager.get(iv)() iv2 = ItemView.from_section_path_str(iv._section_path_str) assert iv == iv2 assert iv2 in [iv] assert iv == list({iv})[0] assert {iv: 5}[iv] == 5 assert hash(iv) == hash(iv.section_path_str) assert iv.type == ExampleClass assert isinstance(iv, ExampleClass) assert isinstance(iv, ExampleClassProtocol)
def from_file_path(cls, file_path: str, action: PyfileconfActions): from pyfileconf import PipelineManager from pyfileconf.sectionpath.sectionpath import SectionPath dependent_manager = PipelineManager.get_manager_by_filepath(file_path) dependent_sp = SectionPath.from_filepath( dependent_manager.default_config_path, file_path) full_sp = SectionPath.join(dependent_manager.name, dependent_sp) return cls(full_sp, action, file_path=file_path)
def create_pm(self, include_logs: bool = True, **kwargs): if include_logs: pyfileconf.options.set_option('log_folder', self.logs_folder) all_kwargs = dict( folder=self.pm_folder, name=self.test_name, default_config_folder_name=self.defaults_folder_name, ) all_kwargs.update(**kwargs) pipeline_manager = PipelineManager(**all_kwargs) return pipeline_manager
def _run(self) -> Any: from pyfileconf.main import PipelineManager results = [] for sp in self.run_items: # Look up appropriate manager and run it pm = PipelineManager.get_manager_by_section_path_str(sp.path_str) relative_section_path_str = SectionPath(".".join(sp[1:])).path_str result = pm.run(relative_section_path_str) results.append(result) if len(results) == 1: return results[0] return results
def get_defaults(self) -> Dict[str, Dict[str, Any]]: logger.debug('Determining defaults for IterativeRunner') from pyfileconf import PipelineManager if not hasattr(self, 'cases'): raise ValueError('must set cases before calling get_defaults') case = self.cases[0] section_path_strs = [ self._get_full_section_path_str(conf['section_path_str']) for conf in case ] defaults: Dict[str, Dict[str, Any]] = {} for sp_str in section_path_strs: pm = PipelineManager.get_manager_by_section_path_str(sp_str) sp = SectionPath(sp_str) relative_section_path_str = SectionPath(".".join(sp[1:])).path_str config = pm.config.get(relative_section_path_str) if config is not None: defaults[sp_str] = {**config} logger.debug(f'Got {defaults} for IterativeRunner.defaults') return defaults
def create_pm(**kwargs) -> PipelineManager: all_kwargs = deepcopy(PM_DEFAULTS) all_kwargs.update(**kwargs) pipeline_manager = PipelineManager(**all_kwargs) return pipeline_manager