Skip to content

Commit dc9ffdc

Browse files
committed
Lazy CMakePreset Writing
1 parent b3b40a1 commit dc9ffdc

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

cppython/plugins/cmake/builder.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
class Builder:
99
"""Aids in building the information needed for the CMake plugin"""
1010

11+
def __init__(self) -> None:
12+
"""Initialize the builder"""
13+
1114
@staticmethod
1215
def write_provider_preset(provider_directory: Path, provider_data: CMakeSyncData) -> None:
1316
"""Writes a provider preset from input sync data
@@ -104,7 +107,11 @@ def write_root_presets(preset_file: Path, cppython_preset_file: Path) -> None:
104107
initial_root_preset = CMakePresets.model_validate_json(initial_json)
105108
root_preset = initial_root_preset.model_copy(deep=True)
106109
else:
107-
root_preset = CMakePresets()
110+
# If the file doesn't exist, we need to default it for the user
111+
112+
# Forward the tool's build directory
113+
default_configure_preset = ConfigurePreset(name='default', inherits='cppython', binaryDir='build')
114+
root_preset = CMakePresets(configurePresets=[default_configure_preset])
108115

109116
# Get the relative path to the cppython preset file
110117
preset_directory = preset_file.parent.absolute()

cppython/plugins/cmake/resolution.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Any
44

55
from cppython.core.schema import CorePluginData
6-
from cppython.plugins.cmake.schema import CMakeConfiguration, CMakeData, CMakePresets
6+
from cppython.plugins.cmake.schema import CMakeConfiguration, CMakeData
77

88

99
def resolve_cmake_data(data: dict[str, Any], core_data: CorePluginData) -> CMakeData:
@@ -24,12 +24,4 @@ def resolve_cmake_data(data: dict[str, Any], core_data: CorePluginData) -> CMake
2424
if not modified_preset_dir.is_absolute():
2525
modified_preset_dir = root_directory / modified_preset_dir
2626

27-
# If the user hasn't specified a preset file, we need to create one
28-
if not modified_preset_dir.exists():
29-
modified_preset_dir.parent.mkdir(parents=True, exist_ok=True)
30-
presets_string = CMakePresets().model_dump_json(exclude_none=True, indent=4)
31-
32-
with modified_preset_dir.open('w', encoding='utf-8') as file:
33-
file.write(presets_string)
34-
3527
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
@@ -76,7 +76,7 @@ class CMakeSyncData(SyncData):
7676
class CMakeData(CPPythonModel):
7777
"""Resolved CMake data"""
7878

79-
preset_file: FilePath
79+
preset_file: Path
8080
configuration_name: str
8181

8282

0 commit comments

Comments
 (0)