mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
Read in universal newline mode
Signed-off-by: Dan Ryan <dan@danryan.co>
This commit is contained in:
+1
-6
@@ -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
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user