|
6 | 6 | from pathlib import Path |
7 | 7 | from typing import Any |
8 | 8 |
|
9 | | -from cppython_core.exceptions import ConfigError |
| 9 | +from cppython_core.exceptions import ConfigError, PluginError |
10 | 10 | from cppython_core.plugin_schema.generator import Generator, GeneratorT |
11 | 11 | from cppython_core.plugin_schema.provider import Provider, ProviderT |
12 | 12 | from cppython_core.plugin_schema.vcs import VersionControl |
@@ -224,40 +224,46 @@ def create_generator( |
224 | 224 | generator_configuration: TODO |
225 | 225 |
|
226 | 226 | Raises: |
227 | | - ConfigError: TODO |
| 227 | + PluginError: TODO |
228 | 228 |
|
229 | 229 | Returns: |
230 | 230 | _description_ |
231 | 231 | """ |
232 | 232 |
|
233 | | - plugin_type, table = None, None |
234 | | - # Extract the first type that's readable |
235 | | - for plugin_type in plugin_types: |
236 | | - name = plugin_type.name() |
| 233 | + directory = core_data.project_data.pyproject_file.parent |
237 | 234 |
|
238 | | - try: |
239 | | - table = generator_configuration[name] |
| 235 | + supported_plugin_type = None |
| 236 | + for plugin_type in plugin_types: |
| 237 | + if plugin_type.is_supported(directory): |
| 238 | + supported_plugin_type = plugin_type |
240 | 239 | break |
241 | | - except KeyError: |
242 | | - continue |
243 | 240 |
|
244 | | - if plugin_type is None: |
245 | | - raise ConfigError("plugin_types was empty") |
| 241 | + if supported_plugin_type is None: |
| 242 | + raise PluginError(f"None of the discovered generator plugins support the project directory ({directory})") |
| 243 | + |
| 244 | + name = supported_plugin_type.name() |
246 | 245 |
|
247 | | - if table is None: |
248 | | - raise ConfigError("No generator name found within the 'tool.cppython.generator' table") |
| 246 | + self.logger.warning("Using generator plugin '%s'", name) |
| 247 | + |
| 248 | + table = generator_configuration.get(name, {}) |
| 249 | + |
| 250 | + if name not in generator_configuration.values(): |
| 251 | + self.logger.error( |
| 252 | + "The pyproject.toml table 'tool.cppython.generator.%s' does not exist. Sending generator empty data", |
| 253 | + name, |
| 254 | + ) |
249 | 255 |
|
250 | 256 | generator_data = resolve_generator(core_data.project_data) |
251 | 257 |
|
252 | | - cppython_plugin_data = resolve_cppython_plugin(core_data.cppython_data, plugin_type) |
| 258 | + cppython_plugin_data = resolve_cppython_plugin(core_data.cppython_data, supported_plugin_type) |
253 | 259 |
|
254 | 260 | core_plugin_data = CorePluginData( |
255 | 261 | project_data=core_data.project_data, |
256 | 262 | pep621_data=core_data.pep621_data, |
257 | 263 | cppython_data=cppython_plugin_data, |
258 | 264 | ) |
259 | 265 |
|
260 | | - plugin = plugin_type(generator_data, core_plugin_data) |
| 266 | + plugin = supported_plugin_type(generator_data, core_plugin_data) |
261 | 267 |
|
262 | 268 | plugin.activate(table) |
263 | 269 |
|
|
0 commit comments