apply universal newlines on windows

This commit is contained in:
Anthony Scopatz 2020-02-28 15:12:25 -05:00
parent 5087ca0378
commit 8b807b0d87

View file

@ -15,7 +15,7 @@ from importlib.abc import MetaPathFinder, SourceLoader, Loader
from xonsh.events import events
from xonsh.execer import Execer
from xonsh.platform import scandir
from xonsh.platform import ON_WINDOWS, scandir
from xonsh.lazyasd import lazyobject
@ -129,6 +129,8 @@ class XonshImportHook(MetaPathFinder, SourceLoader):
filename = self.get_filename(fullname)
with open(filename, "rb") as f:
src = f.read()
if ON_WINDOWS:
src = src.replace(b"\r\n", b"\n")
enc = find_source_encoding(src)
src = src.decode(encoding=enc)
src = src if src.endswith("\n") else src + "\n"