From a5d29418c03110bc4e9d8dfec1c885c32d8d23f9 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 6 Oct 2017 10:02:53 -0400 Subject: [PATCH] better cleanup_toml Signed-off-by: Kenneth Reitz --- pipenv/utils.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pipenv/utils.py b/pipenv/utils.py index eeacb4f0..5f67ba1a 100644 --- a/pipenv/utils.py +++ b/pipenv/utils.py @@ -276,12 +276,18 @@ def cleanup_toml(tml): # Add newlines between TOML sections. for i, line in enumerate(toml.split('\n')): + after = False # Skip the first line. - if i > 0: - if line.startswith('['): + if line.startswith('['): + if i > 0: + # Insert a newline before the heading. new_toml.append('\n') + after = True new_toml.append(line) + # Insert a newline after the heading. + if after: + new_toml.append('') toml = '\n'.join(new_toml) return toml