def test_dep_build_err(self): """TODO """ self.shutit.cfg.update({ 'tk.shutit.test1': { 'build': False, 'shutit.core.module.build_ifneeded': False, 'remove': False }, 'tk.shutit.test2': { 'build': True, 'remove': False } }) self.shutit.shutit_map = { 'tk.shutit.test2': Bunch(module_id='tk.shutit.test2', run_order=1.2, depends_on=["tk.shutit.test1"]), 'tk.shutit.test1': Bunch(module_id='tk.shutit.test1', run_order=1.1, depends_on=[], is_installed=lambda c: False) } errs = shutit_main.check_deps(self.shutit) self.assertEqual(len(errs), 1) self.assertEqual(len(errs[0]), 1)
def test_dep_resolution(self): """TODO """ self.shutit.cfg.update({ 'tk.shutit.test1': {'build': False, 'shutit.core.module.build_ifneeded': True, 'remove': False}, 'tk.shutit.test2': {'build': False, 'shutit.core.module.build_ifneeded': True, 'remove': False}, 'tk.shutit.test3': {'build': True, 'remove': False} }) self.shutit.shutit_map = { 'tk.shutit.test3': Bunch( module_id='tk.shutit.test3', run_order=1.3, depends_on=["tk.shutit.test2"]), 'tk.shutit.test2': Bunch( module_id='tk.shutit.test2', run_order=1.2, depends_on=["tk.shutit.test1"]), 'tk.shutit.test1': Bunch( module_id='tk.shutit.test1', run_order=1.1, depends_on=[]) } errs = shutit_main.check_deps(self.shutit) self.assertEqual(len(errs), 0) assert all([self.shutit.cfg[mod_id]['build'] for mod_id in self.shutit.shutit_map])
def update_modules(to_build, cfg): """ Updates modules to be built with the passed-in config. Updating each individual module section will propogate the changes to STATUS as well (as the references are the same). Note that we have to apply overrides in a specific order - 1) reset the modules being built to the defaults 2) set any modules selected for build as build = True 3) reset configs using config_collection_for_built 4) apply config overrides """ global STATUS selected = set(to_build) for module_id in shutit.cfg: if module_id in ORIG_MOD_CFG and 'shutit.core.module.build' in ORIG_MOD_CFG[ module_id]: shutit.cfg[module_id]['shutit.core.module.build'] = ORIG_MOD_CFG[ module_id]['shutit.core.module.build'] if module_id in selected: shutit.cfg[module_id]['shutit.core.module.build'] = True if cfg is not None: sec, key, val = cfg ORIG_MOD_CFG[sec][key] = val for module_id in ORIG_MOD_CFG: for cfgkey in ORIG_MOD_CFG[module_id]: if cfgkey == 'shutit.core.module.build': continue shutit.cfg[module_id][cfgkey] = ORIG_MOD_CFG[module_id][cfgkey] errs = [] errs.extend(shutit_main.check_deps(shutit)) # There is a complexity here in that module configs may depend on # configs from other modules (!). We assume this won't happen as we # would have to override each module at the correct time. shutit_main.config_collection_for_built(shutit) errs.extend(shutit_main.check_conflicts(shutit)) # Cache first errs.extend(shutit_main.check_ready(shutit, throw_error=False)) errs.extend(shutit_main.check_ready(shutit)) STATUS['errs'] = [err[0] for err in errs] STATUS['modules'] = [{ "module_id": module_id, "description": shutit.shutit_map[module_id].description, "run_order": float(shutit.shutit_map[module_id].run_order), "build": shutit.cfg[module_id]['shutit.core.module.build'], "selected": module_id in selected } for module_id in shutit_main.allowed_module_ids(shutit)]
def update_modules(to_build, cfg): """ Updates modules to be built with the passed-in config. Updating each individual module section will propogate the changes to STATUS as well (as the references are the same). Note that we have to apply overrides in a specific order - 1) reset the modules being built to the defaults 2) set any modules selected for build as build = True 3) reset configs using config_collection_for_built 4) apply config overrides """ global STATUS selected = set(to_build) for mid in shutit.cfg: if mid in orig_mod_cfg and "build" in orig_mod_cfg[mid]: shutit.cfg[mid]["build"] = orig_mod_cfg[mid]["build"] if mid in selected: shutit.cfg[mid]["build"] = True # There is a complexity here in that module configs may depend on # configs from other modules (!). We assume this won't happen as we # would have to override each module at the correct time. shutit_main.config_collection_for_built(shutit) if cfg is not None: sec, key, val = cfg orig_mod_cfg[sec][key] = val for mid in orig_mod_cfg: for cfgkey in orig_mod_cfg[mid]: if cfgkey == "build": continue shutit.cfg[mid][cfgkey] = orig_mod_cfg[mid][cfgkey] errs = [] errs.extend(shutit_main.check_deps(shutit)) errs.extend(shutit_main.check_conflicts(shutit)) errs.extend(shutit_main.check_ready(shutit)) # TODO: display an error if (selected and not build) STATUS["errs"] = [err[0] for err in errs] STATUS["modules"] = [ { "module_id": mid, "description": shutit.shutit_map[mid].description, "run_order": float(shutit.shutit_map[mid].run_order), "build": shutit.cfg[mid]["build"], "selected": mid in selected, } for mid in shutit_main.module_ids(shutit) ]
def update_modules(to_build, cfg): """ Updates modules to be built with the passed-in config. Updating each individual module section will propogate the changes to STATUS as well (as the references are the same). Note that we have to apply overrides in a specific order - 1) reset the modules being built to the defaults 2) set any modules selected for build as build = True 3) reset configs using config_collection_for_built 4) apply config overrides """ global STATUS selected = set(to_build) for module_id in shutit.cfg: if module_id in ORIG_MOD_CFG and 'shutit.core.module.build' in ORIG_MOD_CFG[module_id]: shutit.cfg[module_id]['shutit.core.module.build'] = ORIG_MOD_CFG[module_id]['shutit.core.module.build'] if module_id in selected: shutit.cfg[module_id]['shutit.core.module.build'] = True if cfg is not None: sec, key, val = cfg ORIG_MOD_CFG[sec][key] = val for module_id in ORIG_MOD_CFG: for cfgkey in ORIG_MOD_CFG[module_id]: if cfgkey == 'shutit.core.module.build': continue shutit.cfg[module_id][cfgkey] = ORIG_MOD_CFG[module_id][cfgkey] errs = [] errs.extend(shutit_main.check_deps(shutit)) # There is a complexity here in that module configs may depend on # configs from other modules (!). We assume this won't happen as we # would have to override each module at the correct time. shutit_main.config_collection_for_built(shutit) errs.extend(shutit_main.check_conflicts(shutit)) # Cache first errs.extend(shutit_main.check_ready(shutit, throw_error=False)) errs.extend(shutit_main.check_ready(shutit)) STATUS['errs'] = [err[0] for err in errs] STATUS['modules'] = [ { "module_id": module_id, "description": shutit.shutit_map[module_id].description, "run_order": float(shutit.shutit_map[module_id].run_order), "build": shutit.cfg[module_id]['shutit.core.module.build'], "selected": module_id in selected } for module_id in shutit_main.allowed_module_ids(shutit) ]
def test_dep_exists_err(self): """TODO """ self.shutit.cfg.update({ 'tk.shutit.test1': {'build': True, 'remove': False} }) self.shutit.shutit_map = { 'tk.shutit.test1': Bunch( module_id='tk.shutit.test1', run_order=1.1, depends_on=["tk.shutit.test0"]) } errs = shutit_main.check_deps(self.shutit) self.assertEqual(len(errs), 1) self.assertEqual(len(errs[0]), 1)
def test_dep_exists_err(self): """TODO """ self.shutit.cfg.update( {'tk.shutit.test1': { 'build': True, 'remove': False }}) self.shutit.shutit_map = { 'tk.shutit.test1': Bunch(module_id='tk.shutit.test1', run_order=1.1, depends_on=["tk.shutit.test0"]) } errs = shutit_main.check_deps(self.shutit) self.assertEqual(len(errs), 1) self.assertEqual(len(errs[0]), 1)
def test_dep_build_err(self): """TODO """ self.shutit.cfg.update({ 'tk.shutit.test1': {'build': False, 'shutit.core.module.build_ifneeded': False, 'remove': False}, 'tk.shutit.test2': {'build': True, 'remove': False} }) self.shutit.shutit_map = { 'tk.shutit.test2': Bunch( module_id='tk.shutit.test2', run_order=1.2, depends_on=["tk.shutit.test1"]), 'tk.shutit.test1': Bunch( module_id='tk.shutit.test1', run_order=1.1, depends_on=[], is_installed=lambda c: False) } errs = shutit_main.check_deps(self.shutit) self.assertEqual(len(errs), 1) self.assertEqual(len(errs[0]), 1)
def test_dep_resolution(self): """TODO """ self.shutit.cfg.update({ 'tk.shutit.test1': { 'build': False, 'shutit.core.module.build_ifneeded': True, 'remove': False }, 'tk.shutit.test2': { 'build': False, 'shutit.core.module.build_ifneeded': True, 'remove': False }, 'tk.shutit.test3': { 'build': True, 'remove': False } }) self.shutit.shutit_map = { 'tk.shutit.test3': Bunch(module_id='tk.shutit.test3', run_order=1.3, depends_on=["tk.shutit.test2"]), 'tk.shutit.test2': Bunch(module_id='tk.shutit.test2', run_order=1.2, depends_on=["tk.shutit.test1"]), 'tk.shutit.test1': Bunch(module_id='tk.shutit.test1', run_order=1.1, depends_on=[]) } errs = shutit_main.check_deps(self.shutit) self.assertEqual(len(errs), 0) assert all([ self.shutit.cfg[mod_id]['build'] for mod_id in self.shutit.shutit_map ])