From 2642ccf45b19bede99c56c2cbc2a3c54e0d64ce4 Mon Sep 17 00:00:00 2001 From: Morten Brekkevold Date: Thu, 23 Aug 2018 14:44:15 +0200 Subject: [PATCH 1/2] add failing test The distutils build_sass command runs the Manifest.build() method, not the Manifest.build_one() method. The former does not honor the strip_extension option. --- sasstests.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sasstests.py b/sasstests.py index d6f265a5..eac8360c 100644 --- a/sasstests.py +++ b/sasstests.py @@ -635,7 +635,7 @@ def replace_source_path(s, name): ) -def test_manifest_strip_extension(tmpdir): +def test_manifest_build_one_strip_extension(tmpdir): src = tmpdir.join('test').ensure_dir() src.join('a.scss').write('a{b: c;}') @@ -645,6 +645,16 @@ def test_manifest_strip_extension(tmpdir): assert tmpdir.join('css/a.css').read() == 'a {\n b: c; }\n' +def test_manifest_build_strip_extension(tmpdir): + src = tmpdir.join('test').ensure_dir() + src.join('x.scss').write('a{b: c;}') + + m = Manifest(sass_path='test', css_path='css', strip_extension=True) + m.build(package_dir=str(tmpdir)) + + assert tmpdir.join('css/x.css').read() == 'a {\n b: c; }\n' + + class WsgiTestCase(BaseTestCase): @staticmethod From b295802f509b59d841554c94f4dc8a0e89035d93 Mon Sep 17 00:00:00 2001 From: Morten Brekkevold Date: Thu, 23 Aug 2018 14:50:49 +0200 Subject: [PATCH 2/2] pass and honor strip_extension option to build_directory() --- sassutils/builder.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sassutils/builder.py b/sassutils/builder.py index 52e0f250..1e1da22e 100644 --- a/sassutils/builder.py +++ b/sassutils/builder.py @@ -27,7 +27,7 @@ def build_directory(sass_path, css_path, output_style='nested', - _root_sass=None, _root_css=None): + _root_sass=None, _root_css=None, strip_extension=False): """Compiles all Sass/SCSS files in ``path`` to CSS. :param sass_path: the path of the directory which contains source files @@ -58,6 +58,8 @@ def build_directory(sass_path, css_path, output_style='nested', if name[0] == '_': # Do not compile if it's partial continue + if strip_extension: + name, _ = os.path.splitext(name) css_fullname = os.path.join(css_path, name) + '.css' css = compile(filename=sass_fullname, output_style=output_style, @@ -73,7 +75,8 @@ def build_directory(sass_path, css_path, output_style='nested', subresult = build_directory(sass_fullname, css_fullname, output_style=output_style, _root_sass=_root_sass, - _root_css=_root_css) + _root_css=_root_css, + strip_extension=strip_extension) result.update(subresult) return result @@ -201,7 +204,8 @@ def build(self, package_dir, output_style='nested'): css_path = os.path.join(package_dir, self.css_path) css_files = build_directory( sass_path, css_path, - output_style=output_style + output_style=output_style, + strip_extension=self.strip_extension ).values() return frozenset(os.path.join(self.css_path, filename) for filename in css_files)