Repository: pypa/pipenv

Issue:
Pipfile is not terminated by a newline
The Pipfile created by pipenv doesn't contain a trailing newline

##### Describe you environment

1. Mac OS Sierra (10.12.6)
1. Python version: I use pyenv, and I've tried this on 2.7.13 and 3.6.3. I doubt this is related to the Python version, but if you can't reproduce let me know and I'll investigate further.
1. pipenv version 8.2.7

##### Expected result

That the Pipfile would contain a trailing newline

##### Actual result

```
hobbes:pipenv-bug cdunklau$ pyenv version
3.6.3 (set by /Users/cdunklau/Development/pipenv-bug/.python-version)
hobbes:pipenv-bug cdunklau$ pyenv which pipenv
/Users/cdunklau/.pyenv/versions/3.6.3/bin/pipenv
hobbes:pipenv-bug cdunklau$ pipenv install --python 3.6.3
Creating a virtualenv for this project…
Using /Users/cdunklau/.pyenv/versions/3.6.3/bin/python3.6m to create virtualenv…
⠋Running virtualenv with interpreter /Users/cdunklau/.pyenv/versions/3.6.3/bin/python3.6m
Using base prefix '/Users/cdunklau/.pyenv/versions/3.6.3'
New python executable in /Users/cdunklau/.local/share/virtualenvs/pipenv-bug-1HVkXapj/bin/python3.6m
Also creating executable in /Users/cdunklau/.local/share/virtualenvs/pipenv-bug-1HVkXapj/bin/python
Installing setuptools, pip, wheel...done.

Virtualenv location: /Users/cdunklau/.local/share/virtualenvs/pipenv-bug-1HVkXapj
Creating a Pipfile for this project…
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
Updated Pipfile.lock (625834)!
Installing dependencies from Pipfile.lock (625834)…
  🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 0/0 — 00:00:00
To activate this project's virtualenv, run the following:
 $ pipenv shell
hobbes:pipenv-bug cdunklau$ cat Pipfile
[[source]]

url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"


[packages]



[dev-packages]



[requires]

python_version = "3.6"hobbes:pipenv-bug cdunklau$ 
hobbes:pipenv-bug cdunklau$ hexdump -C Pipfile
00000000  5b 5b 73 6f 75 72 63 65  5d 5d 0a 0a 75 72 6c 20  |[[source]]..url |
00000010  3d 20 22 68 74 74 70 73  3a 2f 2f 70 79 70 69 2e  |= "https://pypi.|
00000020  70 79 74 68 6f 6e 2e 6f  72 67 2f 73 69 6d 70 6c  |python.org/simpl|
00000030  65 22 0a 76 65 72 69 66  79 5f 73 73 6c 20 3d 20  |e".verify_ssl = |
00000040  74 72 75 65 0a 6e 61 6d  65 20 3d 20 22 70 79 70  |true.name = "pyp|
00000050  69 22 0a 0a 0a 5b 70 61  63 6b 61 67 65 73 5d 0a  |i"...[packages].|
00000060  0a 0a 0a 5b 64 65 76 2d  70 61 63 6b 61 67 65 73  |...[dev-packages|
00000070  5d 0a 0a 0a 0a 5b 72 65  71 75 69 72 65 73 5d 0a  |]....[requires].|
00000080  0a 70 79 74 68 6f 6e 5f  76 65 72 73 69 6f 6e 20  |.python_version |
00000090  3d 20 22 33 2e 36 22                              |= "3.6"|
00000097
hobbes:pipenv-bug cdunklau$ 
```

##### Steps to replicate

```
pipenv install
cat Pipfile
```



Discussion:
It looks like `pipenv.utils.cleanup_toml` (https://github.com/kennethreitz/pipenv/blob/8c48266e37440bb9ca9fa8feca6a4f997d6166c1/pipenv/utils.py#L265) is the culprit, it just returns `'\n'.join(new_toml)` without a trailing newline.
@cdunklau would you mind submitting a PR with the fix?  I know new lines at the end of python files are important for pep and stuff.

Resolving patch:
diff --git a/pipenv/utils.py b/pipenv/utils.py
--- a/pipenv/utils.py
+++ b/pipenv/utils.py
@@ -290,7 +290,9 @@ def cleanup_toml(tml):
         # Insert a newline after the heading.
         if after:
             new_toml.append('')
-
+    
+    # adding new line at the end of the TOML file
+    new_toml.append('')
     toml = '\n'.join(new_toml)
     return toml
 


Test patch:
diff --git a/tests/test_utils.py b/tests/test_utils.py
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -186,3 +186,21 @@ def test_download_file(self):
         pipenv.utils.download_file(url, output)
         assert os.path.exists(output)
         os.remove(output)
+
+    def test_new_line_end_of_toml_file(this):
+        # toml file that needs clean up
+        toml = """
+[dev-packages]
+
+"flake8" = ">=3.3.0,<4"
+pytest = "*"
+mock = "*"
+sphinx = "<=1.5.5"
+"-e ." = "*"
+twine = "*"
+"sphinx-click" = "*"
+"pytest-xdist" = "*"
+        """
+        new_toml = pipenv.utils.cleanup_toml(toml)
+        # testing if the end of the generated file contains a newline
+        assert new_toml[-1] == '\n'