Skip to content

Honor strip_extension option when building entire directory structures from distutils #260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion sasstests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;}')

Expand All @@ -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
Expand Down
10 changes: 7 additions & 3 deletions sassutils/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down