def setup_method_fixture(self, tmp_path): project_dirs = craft_parts.ProjectDirs(work_dir=tmp_path) spec = { "plugin": "charm", "source": str(tmp_path), "charm-entrypoint": "entrypoint", "charm-binary-python-packages": ["pkg1", "pkg2"], "charm-python-packages": ["pkg3", "pkg4"], "charm-requirements": ["reqs1.txt", "reqs2.txt"], } plugin_properties = parts.CharmPluginProperties.unmarshal(spec) part_spec = plugins.extract_part_properties(spec, plugin_name="charm") part = craft_parts.Part( "foo", part_spec, project_dirs=project_dirs, plugin_properties=plugin_properties ) project_info = craft_parts.ProjectInfo( application_name="test", project_dirs=project_dirs, cache_dir=tmp_path, ) part_info = craft_parts.PartInfo(project_info=project_info, part=part) self._plugin = plugins.get_plugin( part=part, part_info=part_info, properties=plugin_properties, )
def setup_method_fixture(self, tmp_path): project_dirs = craft_parts.ProjectDirs(work_dir=tmp_path) spec = { "plugin": "reactive", "source": str(tmp_path), } plugin_properties = reactive_plugin.ReactivePluginProperties.unmarshal( spec) part_spec = plugins.extract_part_properties(spec, plugin_name="reactive") part = craft_parts.Part("foo", part_spec, project_dirs=project_dirs, plugin_properties=plugin_properties) project_info = craft_parts.ProjectInfo( application_name="test", project_dirs=project_dirs, cache_dir=tmp_path, project_name="fake-project", ) part_info = craft_parts.PartInfo(project_info=project_info, part=part) self._plugin = plugins.get_plugin( part=part, part_info=part_info, properties=plugin_properties, )
def validate_part(data: Dict[str, Any]) -> None: """Validate the given part data against common and plugin models. :param data: The part data to validate. """ if not isinstance(data, dict): raise TypeError("value must be a dictionary") # copy the original data, we'll modify it spec = data.copy() plugin_name = spec.get("plugin") if not plugin_name: raise ValueError("'plugin' not defined") plugin_class = plugins.get_plugin_class(plugin_name) # validate plugin properties plugin_class.properties_class.unmarshal(spec) # validate common part properties part_spec = plugins.extract_part_properties(spec, plugin_name=plugin_name) PartSpec(**part_spec)