prepare formatted content outside of write block

This is specifically to avoid having an exception
raised while the file is open for writing. Otherwise,
we end up with an empty file if something goes wrong.
This commit is contained in:
Nate Prewitt
2017-02-14 21:19:15 -07:00
parent 6eb16cd053
commit be68accaea
+3 -1
View File
@@ -123,8 +123,10 @@ class Project(object):
def write_toml(self, data, path=None):
if path is None:
path = self.pipfile_location
formatted_data = format_toml(toml.dumps(data))
with open(path, 'w') as f:
f.write(format_toml(toml.dumps(data)))
f.write(formatted_data)
@property
def sources(self):