def handle(config_filename, **kwargs): import logging logger = logging.getLogger() dispatcher = LoggingDispatcher() variables, features, files, config = _read_configuration( dispatcher, config_filename) feature_instances = {} logger.info('Updating {} with {} features'.format( term.bold(config['python'].get('name')), ', '.join( term.bold(term.green(feature_name)) for feature_name in sorted(features)))) all_features = load_feature_extensions() sorted_features = sorted( features) # sort to have a predictable display order for feature_name in sorted_features: logger.debug('Initializing feature {}...'.format( term.bold(term.green(feature_name)))) try: feature = all_features[feature_name] except KeyError as exc: logger.exception( 'Feature "{}" not found.'.format(feature_name)) if feature: feature_instances[feature_name] = feature(dispatcher) for req in feature_instances[feature_name].requires: if not req in sorted_features: raise RuntimeError( 'Unmet dependency: {} requires {}.'.format( feature_name, req)) for con in feature_instances[feature_name].conflicts: if con in sorted_features: raise RuntimeError( 'Conflicting dependency: {} conflicts with {}.'. format(con, feature_name)) else: raise RuntimeError( 'Required feature {} not found.'.format(feature_name)) event = ProjectEvent(config=config) event.variables, event.files = variables, files # todo: add listener dump list in debug/verbose mode ? event = dispatcher.dispatch('medikit.on_start', event) dispatcher.dispatch('medikit.on_end', event) logger.info('Done.')
def handle(config_filename, **kwargs): import logging logger = logging.getLogger() dispatcher = LoggingDispatcher() variables, features, files, config = _read_configuration(dispatcher, config_filename) # This is a hack, but we'd need a flexible option parser which requires too much work as of today. if kwargs.pop("override_requirements", False): if "python" in config: config["python"].override_requirements = True feature_instances = {} logger.info( "Updating {} with {} features".format( term.bold(config.package_name), ", ".join(term.bold(term.green(feature_name)) for feature_name in sorted(features)), ) ) all_features = load_feature_extensions() sorted_features = sorted(features) # sort to have a predictable display order for feature_name in sorted_features: logger.debug("Initializing feature {}...".format(term.bold(term.green(feature_name)))) try: feature = all_features[feature_name] except KeyError as exc: logger.exception('Feature "{}" not found.'.format(feature_name)) if feature: feature_instances[feature_name] = feature(dispatcher) for req in feature_instances[feature_name].requires: if not req in sorted_features: raise RuntimeError("Unmet dependency: {} requires {}.".format(feature_name, req)) for con in feature_instances[feature_name].conflicts: if con in sorted_features: raise RuntimeError("Conflicting dependency: {} conflicts with {}.".format(con, feature_name)) else: raise RuntimeError("Required feature {} not found.".format(feature_name)) event = ProjectEvent(config=config) event.variables, event.files = variables, files # todo: add listener dump list in debug/verbose mode ? event = dispatcher.dispatch("medikit.on_start", event) dispatcher.dispatch("medikit.on_end", event) logger.info("Done.")
def test_on_end(self): feature, dispatcher = self.create_feature() commands = list() with patch('medikit.file.FileEvent') as fe, \ patch('os.system', side_effect=commands.append) as os_system \ : feature.on_end(ProjectEvent(config=self.create_config(), setup={'name': PACKAGE_NAME}))
def test_on_start(self): config = self.create_config() feature, dispatcher = self.create_feature() event = ProjectEvent(config=config, setup={'name': PACKAGE_NAME, 'python_requires': '>=3.5'}) feature.on_start(event) assert event.setup['name'] == PACKAGE_NAME assert event.setup['python_requires'] == '>=3.5'
def _test_constructor(self, **kwargs): e = ProjectEvent(**kwargs) variables, files, setup = kwargs.get('variables', {}), kwargs.get('files', {}), kwargs.get('setup', {}) assert isinstance(e.variables, OrderedDict) assert len(e.variables) == len(variables) assert isinstance(e.files, dict) assert len(e.files) == len(files) assert isinstance(e.setup, OrderedDict) assert len(e.setup) == len(setup)
def test_on_start(self): feature, dispatcher = self.create_feature() config = self.create_config() with patch("os.path.exists", return_value=False): commands = list() with patch("os.system", side_effect=commands.append) as os_system: feature.on_start(ProjectEvent(config=config)) assert commands == [ "git init --quiet", "git add Projectfile", 'git commit --quiet -m "Project initialized using Medikit."', ] with patch("os.path.exists", return_value=True): commands = list() with patch("os.system", side_effect=commands.append) as os_system: feature.on_start(ProjectEvent(config=config)) assert commands == []
def test_on_start(self): config = self.create_config() feature, dispatcher = self.create_feature() event = ProjectEvent(config=config, setup={ "name": PACKAGE_NAME, "python_requires": ">=3.5" }) feature.on_start(event) assert event.setup["name"] == PACKAGE_NAME assert event.setup["python_requires"] == ">=3.5"
def test_set_version(self): # test without setting the version, should be the current default config = self.create_config() event = ProjectEvent(config=config, setup={"name": PACKAGE_NAME}) feature, _ = self.create_feature() feature.on_python_generate(event) assert list(config["python"].get_requirements(extra="dev")) == [ "coverage ~= 4.5", "pytest ~= 4.6", "pytest-cov ~= 2.7", ] # test with setting the version, should override the default config = self.create_config() config.require("pytest").set_version("~=5.0") event = ProjectEvent(config=config, setup={"name": PACKAGE_NAME}) feature, _ = self.create_feature() feature.on_python_generate(event) assert list(config["python"].get_requirements(extra="dev")) == [ "coverage ~= 4.5", "pytest ~= 5.0", "pytest-cov ~= 2.7", ]
def test_on_make_generate(self): python_feature, dispatcher = self.create_feature() config = self.create_config() with pytest.raises(KeyError): # This should fail, as the install/install-dev targets are defined in MakeFeature python_feature.on_make_generate(MakefileEvent(PACKAGE_NAME, Makefile(), config)) make_feature, dispatcher = self.create_feature(feature_type=MakeFeature) self.create_feature(dispatcher=dispatcher) make_feature.on_start(ProjectEvent(config=config, setup={'name': PACKAGE_NAME})) assert sorted(dict(make_feature.makefile.targets).keys()) == [ 'clean', 'help', 'install', 'install-dev', 'update', 'update-requirements', ]
def test_on_make_generate(self): python_feature, dispatcher = self.create_feature() config = self.create_config() python_feature.on_make_generate( MakefileEvent(PACKAGE_NAME, Makefile(), config)) make_feature, dispatcher = self.create_feature( feature_type=MakeFeature) self.create_feature(dispatcher=dispatcher) make_feature.on_start( ProjectEvent(config=config, setup={"name": PACKAGE_NAME})) assert sorted(dict(make_feature.makefile.targets).keys()) == [ "clean", "help", "install", "install-dev", "medikit", "quick", "update", "update-requirements", ]
def test_on_start(self): config = self.create_config() feature, dispatcher = self.create_feature() feature.on_start( ProjectEvent(config=config, setup={'name': PACKAGE_NAME}))
def test_on_start(self): feature, _ = self.create_feature() event = ProjectEvent(config=self.create_config(), setup={"name": PACKAGE_NAME}) feature.on_start(event)
def handle(config_filename, **kwargs): import logging logger = logging.getLogger() dispatcher = LoggingDispatcher() variables, features, files, config = _read_configuration( dispatcher, config_filename) # This is a hack, but we'd need a flexible option parser which requires too much work as of today. if kwargs.pop("override_requirements", False): if "python" in config: config["python"].override_requirements = True feature_instances = {} logger.info("Updating {} with {} features".format( term.bold(config.package_name), ", ".join( term.bold(term.green(feature_name)) for feature_name in sorted(features)), )) all_features = load_feature_extensions() sorted_features = sorted( features) # sort to have a predictable display order for feature_name in sorted_features: logger.debug('Initializing feature "{}"...'.format( term.bold(term.green(feature_name)))) try: feature = all_features[feature_name] except KeyError as exc: logger.exception( 'Feature "{}" not found.'.format(feature_name)) if feature: feature_instances[feature_name] = feature(dispatcher) for req in feature_instances[feature_name].requires: if not req in sorted_features: raise RuntimeError( 'Unmet dependency: "{}" requires "{}".'.format( feature_name, req)) for con in feature_instances[feature_name].conflicts: if con in sorted_features: raise RuntimeError( 'Conflicting dependency: "{}" conflicts with "{}".' .format(con, feature_name)) else: raise RuntimeError( "Required feature {} not found.".format(feature_name)) event = ProjectEvent(config=config) event.variables, event.files = variables, files # todo: add listener dump list in debug/verbose mode ? event = dispatcher.dispatch(medikit.on_start, event) dispatcher.dispatch(medikit.on_end, event) logger.info("Done.")