Skip to content

Commit 5bee6cd

Browse files
authored
Merge pull request #161 from asottile/preserve_line_endings
Preserve line endings that libsass hands us
2 parents 9de489d + 540190f commit 5bee6cd

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
lines changed

sass.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import collections
1616
import functools
1717
import inspect
18-
from io import open
18+
import io
1919
import os
2020
import os.path
2121
import re
@@ -236,8 +236,9 @@ def compile_dirname(
236236
if s:
237237
v = v.decode('UTF-8')
238238
mkdirp(os.path.dirname(output_filename))
239-
with open(output_filename, 'w',
240-
encoding="UTF-8") as output_file:
239+
with io.open(
240+
output_filename, 'w', encoding='UTF-8', newline='',
241+
) as output_file:
241242
output_file.write(v)
242243
else:
243244
return False, v

sassc.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,15 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
179179
if len(args) < 2:
180180
print(css, file=stdout)
181181
else:
182-
with io.open(args[1], 'w', encoding='utf-8') as f:
182+
with io.open(args[1], 'w', encoding='utf-8', newline='') as f:
183183
f.write(css)
184184
if options.watch:
185185
print(filename, 'is just compiled to', args[1],
186186
file=stdout)
187187
if source_map_filename:
188-
with io.open(source_map_filename, 'w', encoding='utf-8') as f:
188+
with io.open(
189+
source_map_filename, 'w', encoding='utf-8', newline='',
190+
) as f:
189191
f.write(source_map)
190192
if options.watch: # pragma: no cover
191193
# FIXME: we should utilize inotify on Linux, and FSEvents on Mac

sasstests.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -643,25 +643,20 @@ def test_wsgi_sass_middleware(self):
643643
client = Client(app, Response)
644644
r = client.get('/asdf')
645645
assert r.status_code == 200
646-
self.assert_bytes_equal(b'/asdf', r.data)
646+
self.assertEqual(b'/asdf', r.data)
647647
assert r.mimetype == 'text/plain'
648648
r = client.get('/static/a.scss.css')
649649
assert r.status_code == 200
650-
self.assert_bytes_equal(
650+
self.assertEqual(
651651
b(A_EXPECTED_CSS_WITH_MAP),
652-
r.data
652+
r.data,
653653
)
654654
assert r.mimetype == 'text/css'
655655
r = client.get('/static/not-exists.sass.css')
656656
assert r.status_code == 200
657-
self.assert_bytes_equal(b'/static/not-exists.sass.css', r.data)
657+
self.assertEqual(b'/static/not-exists.sass.css', r.data)
658658
assert r.mimetype == 'text/plain'
659659

660-
def assert_bytes_equal(self, expected, actual, *args):
661-
self.assertEqual(expected.replace(b'\r\n', b'\n'),
662-
actual.replace(b'\r\n', b'\n'),
663-
*args)
664-
665660

666661
class DistutilsTestCase(BaseTestCase):
667662

@@ -749,7 +744,7 @@ def test_sassc_output(self):
749744
assert exit_code == 0
750745
assert self.err.getvalue() == ''
751746
assert self.out.getvalue() == ''
752-
with open(tmp) as f:
747+
with io.open(tmp, encoding='UTF-8', newline='') as f:
753748
assert A_EXPECTED_CSS.strip() == f.read().strip()
754749
finally:
755750
os.remove(tmp)

sassutils/builder.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ def build_directory(sass_path, css_path, output_style='nested',
6161
css = compile(filename=sass_fullname,
6262
output_style=output_style,
6363
include_paths=[_root_sass])
64-
with io.open(css_fullname, 'w', encoding='utf-8') as css_file:
64+
with io.open(
65+
css_fullname, 'w', encoding='utf-8', newline='',
66+
) as css_file:
6567
css_file.write(css)
6668
result[os.path.relpath(sass_fullname, _root_sass)] = \
6769
os.path.relpath(css_fullname, _root_css)
@@ -215,10 +217,12 @@ def build_one(self, package_dir, filename, source_map=False):
215217
css_folder = os.path.dirname(css_path)
216218
if not os.path.exists(css_folder):
217219
os.makedirs(css_folder)
218-
with io.open(css_path, 'w', encoding='utf-8') as f:
220+
with io.open(css_path, 'w', encoding='utf-8', newline='') as f:
219221
f.write(css)
220222
if source_map:
221223
# Source maps are JSON, and JSON has to be UTF-8 encoded
222-
with io.open(source_map_path, 'w', encoding='utf-8') as f:
224+
with io.open(
225+
source_map_path, 'w', encoding='utf-8', newline='',
226+
) as f:
223227
f.write(source_map)
224228
return css_filename

0 commit comments

Comments
 (0)