diff --git a/pipenv/_compat.py b/pipenv/_compat.py index 3dede246..d6ae5644 100644 --- a/pipenv/_compat.py +++ b/pipenv/_compat.py @@ -258,7 +258,6 @@ def NamedTemporaryFile( if os.name == "nt" and delete: flags |= os.O_TEMPORARY if six.PY2: - # if newline or 'b' not in mode: flags = _text_openflags if 'b' not in mode else flags (fd, name) = _mkstemp_inner(dir, prefix, suffix, flags) else: @@ -270,10 +269,6 @@ def NamedTemporaryFile( return _TemporaryFileWrapper(file, name, delete) except BaseException: - try: - os.unlink(name) - except OSError: - os.close(fd) - os.unlink(name) + os.unlink(name) os.close(fd) raise diff --git a/pipenv/project.py b/pipenv/project.py index 06f8af01..58cbb1ba 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -395,7 +395,7 @@ class Project(object): def read_pipfile(self): # Open the pipfile, read it into memory. - with io.open(self.pipfile_location) as f: + with io.open(self.pipfile_location, newline='') as f: contents = f.read() self._pipfile_newlines = preferred_newlines(f) @@ -769,7 +769,7 @@ class Project(object): self.write_toml(self.parsed_pipfile) def load_lockfile(self, expand_env_vars=True): - with io.open(self.lockfile_location) as lock: + with io.open(self.lockfile_location, newline='') as lock: j = json.load(lock) self._lockfile_newlines = preferred_newlines(lock) # lockfile is just a string diff --git a/pipenv/utils.py b/pipenv/utils.py index f6448586..5f1f26e1 100644 --- a/pipenv/utils.py +++ b/pipenv/utils.py @@ -1305,8 +1305,6 @@ def atomic_open_for_write(target, binary=False, newline=None, encoding=None): target with this new file. """ from ._compat import NamedTemporaryFile - if six.PY2 and not binary and newline == u'\n': - binary = True mode = 'w+b' if binary else 'w' f = NamedTemporaryFile( @@ -1335,5 +1333,3 @@ def atomic_open_for_write(target, binary=False, newline=None, encoding=None): except OSError: pass os.rename(f.name, target) # No os.replace() on Python 2. - finally: - f.close() diff --git a/tests/integration/test_project.py b/tests/integration/test_project.py index 4a3145ea..68caad84 100644 --- a/tests/integration/test_project.py +++ b/tests/integration/test_project.py @@ -87,7 +87,7 @@ def test_maintain_file_line_endings(PipenvInstance, pypi, newlines): # Rewrite each file with parameterized newlines for fn in [p.pipfile_path, p.lockfile_path]: - with io.open(fn) as f: + with io.open(fn, newline='') as f: contents = f.read() written_newlines = f.newlines assert written_newlines == u'\n' @@ -100,7 +100,7 @@ def test_maintain_file_line_endings(PipenvInstance, pypi, newlines): # Make sure we kept the right newlines for fn in [p.pipfile_path, p.lockfile_path]: - with io.open(fn) as f: + with io.open(fn, newline='') as f: contents = f.read() actual_newlines = f.newlines assert actual_newlines == newlines