Skip to content

Commit 5e32093

Browse files
committed
CMake Default Data
1 parent 09e31ca commit 5e32093

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

cppython/plugins/cmake/resolution.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"""Builder to help resolve cmake state"""
22

3+
import json
34
from typing import Any
45

56
from cppython.core.schema import CorePluginData
6-
from cppython.plugins.cmake.schema import CMakeConfiguration, CMakeData
7+
from cppython.plugins.cmake.schema import CMakeConfiguration, CMakeData, CMakePresets
78

89

910
def resolve_cmake_data(data: dict[str, Any], core_data: CorePluginData) -> CMakeData:
@@ -20,8 +21,15 @@ def resolve_cmake_data(data: dict[str, Any], core_data: CorePluginData) -> CMake
2021

2122
root_directory = core_data.project_data.project_root.absolute()
2223

23-
modified_preset = parsed_data.preset_file
24-
if not modified_preset.is_absolute():
25-
modified_preset = root_directory / modified_preset
24+
modified_preset_dir = parsed_data.preset_file
25+
if not modified_preset_dir.is_absolute():
26+
modified_preset_dir = root_directory / modified_preset_dir
2627

27-
return CMakeData(preset_file=modified_preset, configuration_name=parsed_data.configuration_name)
28+
# If the user hasn't specified a preset file, we need to create one
29+
if not modified_preset_dir.exists():
30+
modified_preset_dir.parent.mkdir(parents=True, exist_ok=True)
31+
with modified_preset_dir.open('w', encoding='utf-8') as file:
32+
presets_dict = CMakePresets().model_dump_json(exclude_none=True)
33+
json.dump(presets_dict, file, ensure_ascii=False, indent=4)
34+
35+
return CMakeData(preset_file=modified_preset_dir, configuration_name=parsed_data.configuration_name)

cppython/plugins/cmake/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ class CMakeConfiguration(CPPythonModel):
7474
] = Path('CMakePresets.json')
7575
configuration_name: Annotated[
7676
str, Field(description='The CMake configuration preset to look for and override inside the given `preset_file`')
77-
]
77+
] = 'cppython'

cppython/test/pytest/shared.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,17 @@ class DataPluginIntegrationTests[T: DataPlugin](BaseIntegrationTests[T], metacla
226226
class DataPluginUnitTests[T: DataPlugin](BaseUnitTests[T], metaclass=ABCMeta):
227227
"""Unit testing information for all data plugin test classes"""
228228

229+
@staticmethod
230+
def test_empty_data(
231+
plugin_type: type[T],
232+
plugin_group_data: DataPluginGroupData,
233+
core_plugin_data: CorePluginData,
234+
) -> None:
235+
"""All data plugins should be able to be constructed with empty data"""
236+
plugin = plugin_type(plugin_group_data, core_plugin_data, {})
237+
238+
assert plugin, 'The plugin should be able to be constructed with empty data'
239+
229240

230241
class ProviderTests[T: Provider](DataPluginTests[T], metaclass=ABCMeta):
231242
"""Shared functionality between the different Provider testing categories"""

examples/vcpkg_cmake/simple/pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@ dependencies = [
1515
"cppython>=0.1.0",
1616
]
1717

18+
[tool.cppython]
19+
1820
[tool.pdm]
1921
distribution = false

0 commit comments

Comments
 (0)