Skip to content

Fix Root CMake Writes #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions cppython/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
The central delegation of the CPPython project
"""

import collections.abc
import logging
from importlib import metadata
from pathlib import Path
Expand Down Expand Up @@ -169,13 +170,14 @@ def write_root_presets(self, path: Path):
root_model = CMakePresets.parse_obj(root_preset)

if root_model.include is not None:
for include_path in root_model.include:
for index, include_path in enumerate(root_model.include):
if Path(include_path).name == "cppython.json":
include_path = path
root_model.include[index] = path.as_posix()

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

write_json(root_preset_path, root_preset)
write_json(root_preset_path, root_preset)


class Project(API):
Expand Down
106 changes: 53 additions & 53 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 23 additions & 3 deletions tests/unit/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from pytest_mock import MockerFixture

from cppython.project import Project, ProjectBuilder, ProjectConfiguration
from cppython.utility import read_json, write_json

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

def test_root_presets(self, tmpdir):
def test_root_unmodified(self, tmpdir):
"""
TODO
"""
Expand All @@ -149,8 +150,27 @@ def test_root_presets(self, tmpdir):
configuration = ProjectConfiguration(root_path=temporary_directory)
builder = ProjectBuilder(configuration)

# TODO: Translate into reuseable testing data
output = {
"version": 4,
"cmakeMinimumRequired": {"major": 3, "minor": 23, "patch": 1},
"include": ["should/be/replaced/cppython.json"],
"configurePresets": [
{
"name": "default",
"inherits": ["cppython"],
"hidden": True,
"description": "Tests that generator isn't removed",
"generator": "Should exist",
},
],
}

input_preset = temporary_directory / "CMakePresets.json"
with open(input_preset, "w", encoding="utf8") as file:
file.write("{}")
write_json(input_preset, output)

builder.write_root_presets(temporary_directory / "test_location")

data = read_json(input_preset)

# TODO: Assert the differences affect nothing but what is written by the builder