@@ -23,9 +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- serialized = json . loads ( presets .model_dump_json (exclude_none = True , by_alias = False ) )
26+ serialized = presets .model_dump_json (exclude_none = True , by_alias = False , indent = 4 )
2727 with open (json_path , 'w' , encoding = 'utf8' ) as file :
28- json . dump (serialized , file , ensure_ascii = False , indent = 4 )
28+ file . write (serialized )
2929
3030 @staticmethod
3131 def write_cppython_preset (
@@ -44,9 +44,9 @@ def write_cppython_preset(
4444
4545 cppython_json_path = cppython_preset_directory / 'cppython.json'
4646
47- serialized = json . loads ( presets .model_dump_json (exclude_none = True , by_alias = False ) )
47+ serialized = presets .model_dump_json (exclude_none = True , by_alias = False , indent = 4 )
4848 with open (cppython_json_path , 'w' , encoding = 'utf8' ) as file :
49- json . dump (serialized , file , ensure_ascii = False , indent = 4 )
49+ file . write (serialized )
5050
5151 return cppython_json_path
5252
@@ -63,8 +63,12 @@ def write_root_presets(preset_file: Path, _: Path) -> None:
6363 preset_file: Preset file to modify
6464 """
6565 with open (preset_file , encoding = 'utf-8' ) as file :
66- initial_root_preset = json . load ( file )
66+ initial_json = file . read ( )
6767
68+ initial_root_preset = CMakePresets .model_validate_json (initial_json )
69+
70+ # Only write the file if the contents have changed
6871 if (root_preset := deepcopy (initial_root_preset )) != initial_root_preset :
6972 with open (preset_file , 'w' , encoding = 'utf-8' ) as file :
70- json .dump (root_preset , file , ensure_ascii = False , indent = 4 )
73+ preset = root_preset .model_dump_json (exclude_none = True , indent = 4 )
74+ file .write (preset )
0 commit comments