Skip to content
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

Replace libsass with Dart Sass CLI #77

Merged
merged 5 commits into from
Feb 8, 2021
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
3 changes: 1 addition & 2 deletions utils/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
praw
libsass
csscompressor
click
Pillow
ruamel.yaml
anyconfig
coloredlogs
verboselogs
verboselogs
22 changes: 16 additions & 6 deletions utils/stylesheet/stylesheet_assets_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import re

import csscompressor
import sass
import subprocess
from ruamel.yaml import YAML

from stylesheet import (LocalStylesheetImage, RemoteStylesheetImage,
Expand Down Expand Up @@ -87,11 +87,21 @@ def build_css(self, sass_file):
logger.debug("Reading the Sass file.")
sass_content = sass_file.read()

try:
logger.debug("Compiling the Sass file.")
css_content = sass.compile(filename=sass_file.name)
except sass.CompileError as error:
raise SassCompileException(error, sass_file.name)
logger.debug("Compiling the Sass file.")
process = subprocess.run(
["npx", "-q", "sass", "--no-charset", "main.scss"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
)
if process.stderr:
raise SassCompileException(process.stderr, sass_file.name)
if process.returncode != 0:
raise SassCompileException(
f"Sass gave non-zero exit code {process.returncode}",
sass_file.name,
)
css_content = process.stdout
logger.debug(
"Compiled the Sass file. CSS content size: {} bytes".format(
len(css_content),
Expand Down
6 changes: 2 additions & 4 deletions utils/stylesheet_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Stylesheet exception classes."""
from sass import CompileError


class StylesheetException(Exception):
"""The base Stylesheet Exception that all other exception classes extend.
Expand All @@ -20,10 +18,10 @@ class SassCompileException(StylesheetException):
The specific information about errors in included in the error message.
"""

def __init__(self, compile_error: CompileError, filename):
def __init__(self, error_message, filename):
"""Construct an instance of SassCompileException."""
message = (f"An error occurred when compiling the Sass file "
f"{filename}:\n {str(compile_error)}")
f"{filename}:\n{str(error_message)}")
super().__init__(message)
self.filename = filename

Expand Down