Skip to content

Commit 3cba536

Browse files
committed
Query Generator Support
1 parent 09c2c03 commit 3cba536

2 files changed

Lines changed: 30 additions & 24 deletions

File tree

cppython/builder.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pathlib import Path
77
from typing import Any
88

9-
from cppython_core.exceptions import ConfigError
9+
from cppython_core.exceptions import ConfigError, PluginError
1010
from cppython_core.plugin_schema.generator import Generator, GeneratorT
1111
from cppython_core.plugin_schema.provider import Provider, ProviderT
1212
from cppython_core.plugin_schema.vcs import VersionControl
@@ -224,40 +224,46 @@ def create_generator(
224224
generator_configuration: TODO
225225
226226
Raises:
227-
ConfigError: TODO
227+
PluginError: TODO
228228
229229
Returns:
230230
_description_
231231
"""
232232

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
237234

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
240239
break
241-
except KeyError:
242-
continue
243240

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()
246245

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+
)
249255

250256
generator_data = resolve_generator(core_data.project_data)
251257

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)
253259

254260
core_plugin_data = CorePluginData(
255261
project_data=core_data.project_data,
256262
pep621_data=core_data.pep621_data,
257263
cppython_data=cppython_plugin_data,
258264
)
259265

260-
plugin = plugin_type(generator_data, core_plugin_data)
266+
plugin = supported_plugin_type(generator_data, core_plugin_data)
261267

262268
plugin.activate(table)
263269

pdm.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)