@@ -64,8 +64,22 @@ def _validate(self) -> None:
6464 def save (self , path : Optional [Path ] = None ) -> None :
6565 """Save the pyproject file."""
6666 path = path or self .path
67- with open (path , "w" ) as f :
68- tomlkit .dump (self ._data , f )
67+
68+ with open (path , "r" ) as f :
69+ # tomlkit formatting sometimes creates empty lines, dont change if context is not changed
70+ existing_data = f .read ()
71+
72+ # remove empty lines
73+ existing_data = existing_data .replace ("\n " , "" )
74+
75+ new_data = tomlkit .dumps (self ._data )
76+ new_data = new_data .replace ("\n " , "" )
77+
78+ if existing_data != new_data :
79+ with open (path , "w" ) as f :
80+ tomlkit .dump (self ._data , f )
81+ else :
82+ logger .debug ("No changes to pyproject.toml file" )
6983
7084 def _get_property (
7185 self , key : Union [str , List [str ]], * , remove : bool = False , ** kwargs
@@ -216,24 +230,6 @@ def sync(self, metadata: ProjectMetadata) -> None:
216230
217231 # For Poetry v2, convert authors and maintainers from array of tables to inline tables
218232 if self ._poetry_version == 2 :
219- # convert authors and maintainers from array of tables to inline tables
220- for field in ["authors" , "maintainers" ]:
221- field_value = self ._get_property ([field ])
222- if field_value :
223- # Create an inline array of tables
224- inline_array = tomlkit .array ()
225- inline_array .multiline (True )
226-
227- # Convert each table to an inline table and add to array
228- for item in field_value :
229- inline_table = tomlkit .inline_table ()
230- for k , v in item .items ():
231- inline_table [k ] = v
232- inline_array .append (inline_table )
233-
234- # Replace the array of tables with the inline array
235- self ._set_property (field , inline_array )
236-
237233 # if license field has text, or file, make it inline table of tomlkit
238234 if self ._get_property (["license" ]) is not None :
239235 license_value = self ._get_property (["license" ])
0 commit comments