From be68accaea82b5ff89118143ccfb4711e353b5b4 Mon Sep 17 00:00:00 2001 From: Nate Prewitt Date: Tue, 14 Feb 2017 21:19:15 -0700 Subject: [PATCH] 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. --- pipenv/project.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pipenv/project.py b/pipenv/project.py index 3ca986c2..98ef6606 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -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):