From 84741e9e8185a783d8153c6e26c6e9ab543a67f5 Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sun, 22 May 2022 05:06:46 -0400 Subject: [PATCH 1/3] Exclude None --- cppython/project.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cppython/project.py b/cppython/project.py index b4bba63..d38b801 100644 --- a/cppython/project.py +++ b/cppython/project.py @@ -170,7 +170,7 @@ def write_generator_presets(path: Path, generator_name: str, toolchain_path: Pat if Path(include_path).name == "cppython.json": include_path = json_path - root_preset.update(root_model.dict()) + root_preset.update(root_model.dict(exclude_none=True)) write_json(root_preset_path, root_preset) From 09baa8994a05919259f2c70c0ed852bfec3a822d Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sun, 22 May 2022 18:59:34 -0400 Subject: [PATCH 2/3] Split Writing --- cppython/project.py | 35 ++++++++++++++++++++--------------- tests/unit/test_project.py | 20 +++++++++++++++++--- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/cppython/project.py b/cppython/project.py index d38b801..ab708d1 100644 --- a/cppython/project.py +++ b/cppython/project.py @@ -111,9 +111,10 @@ def generate_modified(self, original: CPPythonDataT) -> CPPythonDataT: return modified - def write_presets(self, path: Path, generator_output: list[tuple[str, Path]]) -> None: + def write_presets(self, path: Path, generator_output: list[tuple[str, Path]]) -> Path: """ - Write the cppython presets + Write the cppython presets. + Returns the """ path.mkdir(parents=True, exist_ok=True) @@ -155,24 +156,26 @@ def write_generator_presets(path: Path, generator_name: str, toolchain_path: Pat json_path = path / "cppython.json" write_model_json(json_path, presets) + return json_path - # Read the top level json file and replace the include reference + def write_root_presets(self, path: Path): + """ + Read the top level json file and replace the include reference + """ root_preset_path = self.configuration.root_path / "CMakePresets.json" - if root_preset_path.exists(): - root_preset = read_json(root_preset_path) - - root_model = CMakePresets.parse_obj(root_preset) + root_preset = read_json(root_preset_path) + root_model = CMakePresets.parse_obj(root_preset) - if root_model.include is not None: - for include_path in root_model.include: - if Path(include_path).name == "cppython.json": - include_path = json_path + if root_model.include is not None: + for include_path in root_model.include: + if Path(include_path).name == "cppython.json": + include_path = path - root_preset.update(root_model.dict(exclude_none=True)) + root_preset.update(root_model.dict(exclude_none=True)) - write_json(root_preset_path, root_preset) + write_json(root_preset_path, root_preset) class Project(API): @@ -335,7 +338,8 @@ def install(self) -> None: cppython_logger.error(f"Generator {generator.name()} failed to install") raise exception - self._builder.write_presets(preset_path, generator_output) + project_presets = self._builder.write_presets(preset_path, generator_output) + self._builder.write_root_presets(project_presets) def update(self) -> None: """ @@ -365,4 +369,5 @@ def update(self) -> None: cppython_logger.error(f"Generator {generator.name()} failed to update") raise exception - self._builder.write_presets(preset_path, generator_output) + project_presets = self._builder.write_presets(preset_path, generator_output) + self._builder.write_root_presets(project_presets) diff --git a/tests/unit/test_project.py b/tests/unit/test_project.py index 8be1759..95c5191 100644 --- a/tests/unit/test_project.py +++ b/tests/unit/test_project.py @@ -116,10 +116,9 @@ def test_presets(self, tmpdir): TODO """ - configuration = ProjectConfiguration(root_path=Path()) - builder = ProjectBuilder(configuration) - temporary_directory = Path(tmpdir) + configuration = ProjectConfiguration(root_path=temporary_directory) + builder = ProjectBuilder(configuration) input_toolchain = temporary_directory / "input.cmake" @@ -140,3 +139,18 @@ def test_presets(self, tmpdir): test_file = test_tool / "test.json" assert test_file.exists() + + def test_root_presets(self, tmpdir): + """ + TODO + """ + + temporary_directory = Path(tmpdir) + configuration = ProjectConfiguration(root_path=temporary_directory) + builder = ProjectBuilder(configuration) + + input_preset = temporary_directory / "CMakePresets.json" + with open(input_preset, "w", encoding="utf8") as file: + file.write("{}") + + builder.write_root_presets(temporary_directory / "test_location") From 35d54bf4d114e852b0bd8dbf36b99effc7cc30da Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Sun, 22 May 2022 19:29:29 -0400 Subject: [PATCH 3/3] Remove Unused Import --- cppython/project.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cppython/project.py b/cppython/project.py index ab708d1..0f02529 100644 --- a/cppython/project.py +++ b/cppython/project.py @@ -22,7 +22,7 @@ from pydantic import create_model from cppython.schema import API, CMakePresets, ConfigurePreset, ProjectConfiguration -from cppython.utility import read_json, read_model_json, write_json, write_model_json +from cppython.utility import read_json, write_json, write_model_json class ProjectBuilder: