Skip to content

Commit b4f8272

Browse files
committed
Remove Util
1 parent ef147b1 commit b4f8272

File tree

4 files changed

+21
-52
lines changed

4 files changed

+21
-52
lines changed

cppython/core/utility.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

cppython/plugins/cmake/builder.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""Plugin builder"""
22

3+
import json
34
from copy import deepcopy
45
from pathlib import Path
56

6-
from cppython.core.utility import read_json, write_json, write_model_json
77
from cppython.plugins.cmake.schema import CMakePresets, CMakeSyncData, ConfigurePreset
88

99

@@ -23,7 +23,9 @@ def write_provider_preset(provider_directory: Path, data: CMakeSyncData) -> None
2323

2424
json_path = provider_directory / f'{data.provider_name}.json'
2525

26-
write_model_json(json_path, presets)
26+
serialized = json.loads(presets.model_dump_json(exclude_none=True, by_alias=False))
27+
with open(json_path, 'w', encoding='utf8') as file:
28+
json.dump(serialized, file, ensure_ascii=False, indent=4)
2729

2830
@staticmethod
2931
def write_cppython_preset(
@@ -42,7 +44,10 @@ def write_cppython_preset(
4244

4345
cppython_json_path = cppython_preset_directory / 'cppython.json'
4446

45-
write_model_json(cppython_json_path, presets)
47+
serialized = json.loads(presets.model_dump_json(exclude_none=True, by_alias=False))
48+
with open(cppython_json_path, 'w', encoding='utf8') as file:
49+
json.dump(serialized, file, ensure_ascii=False, indent=4)
50+
4651
return cppython_json_path
4752

4853
@staticmethod
@@ -57,7 +62,9 @@ def write_root_presets(preset_file: Path, _: Path) -> None:
5762
Args:
5863
preset_file: Preset file to modify
5964
"""
60-
initial_root_preset = read_json(preset_file)
65+
with open(preset_file, encoding='utf-8') as file:
66+
initial_root_preset = json.load(file)
6167

6268
if (root_preset := deepcopy(initial_root_preset)) != initial_root_preset:
63-
write_json(preset_file, root_preset)
69+
with open(preset_file, 'w', encoding='utf-8') as file:
70+
json.dump(root_preset, file, ensure_ascii=False, indent=4)

tests/unit/core/test_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def test_model_construction_from_data(self) -> None:
3838
"""
3939

4040
data = loads(toml_str)
41-
result = self.Model.model_validate(data)
41+
result = self.Model.model_validate(data, by_name=True)
4242
assert result.aliased_variable is True
4343

4444
@staticmethod

tests/unit/plugins/cmake/test_generator.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""Unit test the provider plugin"""
22

3+
import json
34
from pathlib import Path
45
from typing import Any
56

67
import pytest
78

8-
from cppython.core.utility import write_model_json
99
from cppython.plugins.cmake.builder import Builder
1010
from cppython.plugins.cmake.plugin import CMakeGenerator
1111
from cppython.plugins.cmake.schema import (
@@ -104,7 +104,10 @@ def test_root_write(tmp_path: Path) -> None:
104104

105105
root_file = tmp_path / 'CMakePresets.json'
106106
presets = CMakePresets()
107-
write_model_json(root_file, presets)
107+
108+
serialized = json.loads(presets.model_dump_json(exclude_none=True, by_alias=False))
109+
with open(root_file, 'w', encoding='utf8') as file:
110+
json.dump(serialized, file, ensure_ascii=False, indent=4)
108111

109112
data = CMakeSyncData(provider_name=TypeName('test-provider'), top_level_includes=includes_file)
110113
builder.write_provider_preset(provider_directory, data)
@@ -137,7 +140,9 @@ def test_relative_root_write(tmp_path: Path) -> None:
137140

138141
root_file = relative_indirection / 'CMakePresets.json'
139142
presets = CMakePresets()
140-
write_model_json(root_file, presets)
143+
serialized = json.loads(presets.model_dump_json(exclude_none=True, by_alias=False))
144+
with open(root_file, 'w', encoding='utf8') as file:
145+
json.dump(serialized, file, ensure_ascii=False, indent=4)
141146

142147
data = CMakeSyncData(provider_name=TypeName('test-provider'), top_level_includes=includes_file)
143148
builder.write_provider_preset(provider_directory, data)

0 commit comments

Comments
 (0)