Skip to content

Commit ea12f32

Browse files
authored
Fix Root CMake Writes (#64)
1 parent 6aec8ae commit ea12f32

File tree

3 files changed

+82
-60
lines changed

3 files changed

+82
-60
lines changed

cppython/project.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
The central delegation of the CPPython project
33
"""
44

5+
import collections.abc
56
import logging
67
from importlib import metadata
78
from pathlib import Path
@@ -169,13 +170,14 @@ def write_root_presets(self, path: Path):
169170
root_model = CMakePresets.parse_obj(root_preset)
170171

171172
if root_model.include is not None:
172-
for include_path in root_model.include:
173+
for index, include_path in enumerate(root_model.include):
173174
if Path(include_path).name == "cppython.json":
174-
include_path = path
175+
root_model.include[index] = path.as_posix()
175176

176-
root_preset.update(root_model.dict(exclude_none=True))
177+
# 'dict.update' wont apply to nested types, manual replacement
178+
root_preset["include"] = root_model.include
177179

178-
write_json(root_preset_path, root_preset)
180+
write_json(root_preset_path, root_preset)
179181

180182

181183
class Project(API):

pdm.lock

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

tests/unit/test_project.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from pytest_mock import MockerFixture
1818

1919
from cppython.project import Project, ProjectBuilder, ProjectConfiguration
20+
from cppython.utility import read_json, write_json
2021

2122
default_pep621 = PEP621(name="test_name", version="1.0")
2223
default_cppython_data = CPPythonData(**{"target": TargetEnum.EXE})
@@ -140,7 +141,7 @@ def test_presets(self, tmpdir):
140141
test_file = test_tool / "test.json"
141142
assert test_file.exists()
142143

143-
def test_root_presets(self, tmpdir):
144+
def test_root_unmodified(self, tmpdir):
144145
"""
145146
TODO
146147
"""
@@ -149,8 +150,27 @@ def test_root_presets(self, tmpdir):
149150
configuration = ProjectConfiguration(root_path=temporary_directory)
150151
builder = ProjectBuilder(configuration)
151152

153+
# TODO: Translate into reuseable testing data
154+
output = {
155+
"version": 4,
156+
"cmakeMinimumRequired": {"major": 3, "minor": 23, "patch": 1},
157+
"include": ["should/be/replaced/cppython.json"],
158+
"configurePresets": [
159+
{
160+
"name": "default",
161+
"inherits": ["cppython"],
162+
"hidden": True,
163+
"description": "Tests that generator isn't removed",
164+
"generator": "Should exist",
165+
},
166+
],
167+
}
168+
152169
input_preset = temporary_directory / "CMakePresets.json"
153-
with open(input_preset, "w", encoding="utf8") as file:
154-
file.write("{}")
170+
write_json(input_preset, output)
155171

156172
builder.write_root_presets(temporary_directory / "test_location")
173+
174+
data = read_json(input_preset)
175+
176+
# TODO: Assert the differences affect nothing but what is written by the builder

0 commit comments

Comments
 (0)