Skip to content

Commit d649d4b

Browse files
committed
Update Plugin Config Table
1 parent 316949f commit d649d4b

File tree

7 files changed

+134
-41
lines changed

7 files changed

+134
-41
lines changed

cppython/builder.py

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from cppython.data import Data, Plugins
3535
from cppython.defaults import DefaultSCM
3636
from cppython.utility.exception import PluginError
37+
from cppython.utility.utility import TypeName
3738

3839

3940
class Resolver:
@@ -59,14 +60,14 @@ def generate_plugins(
5960
raw_generator_plugins = self.find_generators()
6061
generator_plugins = self.filter_plugins(
6162
raw_generator_plugins,
62-
cppython_local_configuration.generator_name,
63+
self._get_effective_generator_name(cppython_local_configuration),
6364
'Generator',
6465
)
6566

6667
raw_provider_plugins = self.find_providers()
6768
provider_plugins = self.filter_plugins(
6869
raw_provider_plugins,
69-
cppython_local_configuration.provider_name,
70+
self._get_effective_provider_name(cppython_local_configuration),
7071
'Provider',
7172
)
7273

@@ -79,6 +80,74 @@ def generate_plugins(
7980

8081
return PluginBuildData(generator_type=generator_type, provider_type=provider_type, scm_type=scm_type)
8182

83+
def _get_effective_generator_name(self, config: CPPythonLocalConfiguration) -> str | None:
84+
"""Get the effective generator name from configuration
85+
86+
Args:
87+
config: The local configuration
88+
89+
Returns:
90+
The generator name to use, or None for auto-detection
91+
"""
92+
if config.generators:
93+
# For now, pick the first generator (in future, could support selection logic)
94+
return list(config.generators.keys())[0]
95+
96+
# No generators specified, use auto-detection
97+
return None
98+
99+
def _get_effective_provider_name(self, config: CPPythonLocalConfiguration) -> str | None:
100+
"""Get the effective provider name from configuration
101+
102+
Args:
103+
config: The local configuration
104+
105+
Returns:
106+
The provider name to use, or None for auto-detection
107+
"""
108+
if config.providers:
109+
# For now, pick the first provider (in future, could support selection logic)
110+
return list(config.providers.keys())[0]
111+
112+
# No providers specified, use auto-detection
113+
return None
114+
115+
def _get_effective_generator_config(
116+
self, config: CPPythonLocalConfiguration, generator_name: str
117+
) -> dict[str, Any]:
118+
"""Get the effective generator configuration
119+
120+
Args:
121+
config: The local configuration
122+
generator_name: The name of the generator being used
123+
124+
Returns:
125+
The configuration dict for the generator
126+
"""
127+
generator_type_name = TypeName(generator_name)
128+
if config.generators and generator_type_name in config.generators:
129+
return config.generators[generator_type_name]
130+
131+
# Return empty config if not found
132+
return {}
133+
134+
def _get_effective_provider_config(self, config: CPPythonLocalConfiguration, provider_name: str) -> dict[str, Any]:
135+
"""Get the effective provider configuration
136+
137+
Args:
138+
config: The local configuration
139+
provider_name: The name of the provider being used
140+
141+
Returns:
142+
The configuration dict for the provider
143+
"""
144+
provider_type_name = TypeName(provider_name)
145+
if config.providers and provider_type_name in config.providers:
146+
return config.providers[provider_type_name]
147+
148+
# Return empty config if not found
149+
return {}
150+
82151
@staticmethod
83152
def generate_cppython_plugin_data(plugin_build_data: PluginBuildData) -> PluginCPPythonData:
84153
"""Generates the CPPython plugin data from the resolved plugins
@@ -447,11 +516,18 @@ def build(
447516
pep621_data = self._resolver.generate_pep621_data(pep621_configuration, self._project_configuration, scm)
448517

449518
# Create the chosen plugins
519+
generator_config = self._resolver._get_effective_generator_config(
520+
cppython_local_configuration, plugin_build_data.generator_type.name()
521+
)
450522
generator = self._resolver.create_generator(
451-
core_data, pep621_data, cppython_local_configuration.generator, plugin_build_data.generator_type
523+
core_data, pep621_data, generator_config, plugin_build_data.generator_type
524+
)
525+
526+
provider_config = self._resolver._get_effective_provider_config(
527+
cppython_local_configuration, plugin_build_data.provider_type.name()
452528
)
453529
provider = self._resolver.create_provider(
454-
core_data, pep621_data, cppython_local_configuration.provider, plugin_build_data.provider_type
530+
core_data, pep621_data, provider_config, plugin_build_data.provider_type
455531
)
456532

457533
plugins = Plugins(generator=generator, provider=provider, scm=scm)

cppython/core/resolution.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,22 @@ def resolve_cppython(
139139
if not modified_build_path.is_absolute():
140140
modified_build_path = root_directory / modified_build_path
141141

142-
modified_provider_name = local_configuration.provider_name
143-
modified_generator_name = local_configuration.generator_name
142+
modified_provider_name = plugin_build_data.provider_name
143+
modified_generator_name = plugin_build_data.generator_name
144144

145-
if modified_provider_name is None:
146-
modified_provider_name = plugin_build_data.provider_name
145+
modified_scm_name = plugin_build_data.scm_name
147146

148-
if modified_generator_name is None:
149-
modified_generator_name = plugin_build_data.generator_name
147+
# Extract provider and generator configuration data
148+
provider_type_name = TypeName(modified_provider_name)
149+
generator_type_name = TypeName(modified_generator_name)
150150

151-
modified_scm_name = plugin_build_data.scm_name
151+
provider_data = {}
152+
if local_configuration.providers and provider_type_name in local_configuration.providers:
153+
provider_data = local_configuration.providers[provider_type_name]
154+
155+
generator_data = {}
156+
if local_configuration.generators and generator_type_name in local_configuration.generators:
157+
generator_data = local_configuration.generators[generator_type_name]
152158

153159
# Construct dependencies from the local configuration only
154160
dependencies: list[Requirement] = []
@@ -173,6 +179,8 @@ def resolve_cppython(
173179
generator_name=modified_generator_name,
174180
scm_name=modified_scm_name,
175181
dependencies=dependencies,
182+
provider_data=provider_data,
183+
generator_data=generator_data,
176184
)
177185
return cppython_data
178186

@@ -200,6 +208,8 @@ def resolve_cppython_plugin(cppython_data: CPPythonData, plugin_type: type[Plugi
200208
generator_name=cppython_data.generator_name,
201209
scm_name=cppython_data.scm_name,
202210
dependencies=cppython_data.dependencies,
211+
provider_data=cppython_data.provider_data,
212+
generator_data=cppython_data.generator_data,
203213
)
204214

205215
return cast(CPPythonPluginData, plugin_data)

cppython/core/schema.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ class CPPythonData(CPPythonModel, extra='forbid'):
118118
scm_name: TypeName
119119
dependencies: list[Requirement]
120120

121+
provider_data: Annotated[dict[str, Any], Field(description='Resolved provider configuration data')]
122+
generator_data: Annotated[dict[str, Any], Field(description='Resolved generator configuration data')]
123+
121124
@field_validator('configuration_path', 'install_path', 'tool_path', 'build_path') # type: ignore
122125
@classmethod
123126
def validate_absolute_path(cls, value: Path) -> Path:
@@ -302,29 +305,21 @@ class CPPythonLocalConfiguration(CPPythonModel, extra='forbid'):
302305
),
303306
] = Path('build')
304307

305-
provider: Annotated[ProviderData, Field(description="Provider plugin data associated with 'provider_name")] = (
306-
ProviderData({})
307-
)
308-
309-
provider_name: Annotated[
310-
TypeName | None,
308+
providers: Annotated[
309+
dict[TypeName, ProviderData],
311310
Field(
312-
alias='provider-name',
313-
description='If empty, the provider will be automatically deduced.',
311+
description='Named provider configurations. Key is the provider name, value is the provider configuration.'
314312
),
315-
] = None
316-
317-
generator: Annotated[GeneratorData, Field(description="Generator plugin data associated with 'generator_name'")] = (
318-
GeneratorData({})
319-
)
313+
] = {}
320314

321-
generator_name: Annotated[
322-
TypeName | None,
315+
generators: Annotated[
316+
dict[TypeName, GeneratorData],
323317
Field(
324-
alias='generator-name',
325-
description='If empty, the generator will be automatically deduced.',
318+
description=(
319+
'Named generator configurations. Key is the generator name, value is the generator configuration.'
320+
)
326321
),
327-
] = None
322+
] = {}
328323

329324
dependencies: Annotated[
330325
list[str] | None,

cppython/test/pytest/fixtures.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
PyProject,
2828
ToolData,
2929
)
30-
from cppython.utility.utility import TypeName
3130

3231

3332
@pytest.fixture(
@@ -92,7 +91,7 @@ def fixture_cppython_local_configuration(install_path: Path) -> CPPythonLocalCon
9291
Variation of CPPython data
9392
"""
9493
cppython_local_configuration = CPPythonLocalConfiguration(
95-
install_path=install_path, provider_name=TypeName('mock'), generator_name=TypeName('mock')
94+
install_path=install_path, providers={'mock': {}}, generators={'mock': {}}
9695
)
9796

9897
return cppython_local_configuration

examples/conan_cmake/simple/pyproject.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,13 @@ dependencies = ["cppython[conan, cmake, git]>=0.9.0"]
1313

1414

1515
[tool.cppython]
16-
generator-name = "cmake"
17-
provider-name = "conan"
18-
1916
install-path = "install"
2017

2118
dependencies = ["fmt>=11.2.0"]
2219

23-
[tool.cppython.generator]
20+
[tool.cppython.generators.cmake]
2421

25-
[tool.cppython.provider]
22+
[tool.cppython.providers.conan]
2623

2724
[tool.pdm]
2825
distribution = false

examples/vcpkg_cmake/simple/pyproject.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,13 @@ dependencies = ["cppython[vcpkg, cmake, git]>=0.9.0"]
1313

1414

1515
[tool.cppython]
16-
generator-name = "cmake"
17-
provider-name = "vcpkg"
18-
1916
install-path = "install"
2017

2118
dependencies = ["fmt>=11.0.2"]
2219

23-
[tool.cppython.generator]
20+
[tool.cppython.generators.cmake]
2421

25-
[tool.cppython.provider]
22+
[tool.cppython.providers.vcpkg]
2623

2724
[tool.pdm]
2825
distribution = false

tests/unit/test_data.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
from cppython.core.resolution import PluginBuildData
99
from cppython.core.schema import (
1010
CPPythonLocalConfiguration,
11+
GeneratorData,
1112
PEP621Configuration,
1213
ProjectConfiguration,
14+
ProviderData,
1315
)
1416
from cppython.data import Data
1517
from cppython.test.mock.generator import MockGenerator
1618
from cppython.test.mock.provider import MockProvider
1719
from cppython.test.mock.scm import MockSCM
20+
from cppython.utility.utility import TypeName
1821

1922

2023
class TestData:
@@ -58,3 +61,19 @@ def test_sync(data: Data) -> None:
5861
data: Fixture for the mocked data class
5962
"""
6063
data.sync()
64+
65+
@staticmethod
66+
def test_named_plugin_configuration() -> None:
67+
"""Test that named plugin configuration is properly validated"""
68+
# Test valid named configuration
69+
config = CPPythonLocalConfiguration(
70+
providers={TypeName('conan'): ProviderData({'some_setting': 'value'})},
71+
generators={TypeName('cmake'): GeneratorData({'another_setting': True})},
72+
)
73+
assert config.providers == {TypeName('conan'): {'some_setting': 'value'}}
74+
assert config.generators == {TypeName('cmake'): {'another_setting': True}}
75+
76+
# Test empty configuration is valid
77+
config_empty = CPPythonLocalConfiguration()
78+
assert config_empty.providers == {}
79+
assert config_empty.generators == {}

0 commit comments

Comments
 (0)