From 46e1e4a9525a97806ba805a3104b39da660e5996 Mon Sep 17 00:00:00 2001 From: George Date: Tue, 26 Jan 2021 21:29:31 -0500 Subject: [PATCH 1/5] Replace libsass with Dart Sass CLI --- .github/workflows/build-and-deploy.yml | 2 ++ utils/requirements.txt | 3 +-- utils/stylesheet/stylesheet_assets_builder.py | 22 ++++++++++++++----- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index 01346d5..5237a76 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -18,6 +18,8 @@ jobs: python-version: '3.6' - name: Install pip requirements run: pip install -r utils/requirements.txt + - name: Install Sass CLI + run: npm install --global sass - name: Build and some other testing stuff run: | echo ${{ github.ref }} diff --git a/utils/requirements.txt b/utils/requirements.txt index b319c37..df4b19f 100644 --- a/utils/requirements.txt +++ b/utils/requirements.txt @@ -1,9 +1,8 @@ praw -libsass csscompressor click Pillow ruamel.yaml anyconfig coloredlogs -verboselogs \ No newline at end of file +verboselogs diff --git a/utils/stylesheet/stylesheet_assets_builder.py b/utils/stylesheet/stylesheet_assets_builder.py index 84d0e5a..9f13aa3 100644 --- a/utils/stylesheet/stylesheet_assets_builder.py +++ b/utils/stylesheet/stylesheet_assets_builder.py @@ -4,7 +4,7 @@ import re import csscompressor -import sass +import subprocess from ruamel.yaml import YAML from stylesheet import (LocalStylesheetImage, RemoteStylesheetImage, @@ -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( + ["sass", "--no-charset", "main.scss"], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=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), From fcfe042570665a0031cf85088621ff930940ba32 Mon Sep 17 00:00:00 2001 From: Geo Date: Tue, 26 Jan 2021 21:33:41 -0500 Subject: [PATCH 2/5] Github Actions doesn't like npm install --global --- .github/workflows/build-and-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index 5237a76..4c828dc 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -19,7 +19,7 @@ jobs: - name: Install pip requirements run: pip install -r utils/requirements.txt - name: Install Sass CLI - run: npm install --global sass + run: npm install sass - name: Build and some other testing stuff run: | echo ${{ github.ref }} From 5a16aee2f19851247a615e05ed901d4bb73ded8f Mon Sep 17 00:00:00 2001 From: George Date: Tue, 26 Jan 2021 21:36:44 -0500 Subject: [PATCH 3/5] Don't base SassCompileException on CompileError --- utils/stylesheet_exceptions.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/utils/stylesheet_exceptions.py b/utils/stylesheet_exceptions.py index d236022..0de453b 100644 --- a/utils/stylesheet_exceptions.py +++ b/utils/stylesheet_exceptions.py @@ -1,6 +1,4 @@ """Stylesheet exception classes.""" -from sass import CompileError - class StylesheetException(Exception): """The base Stylesheet Exception that all other exception classes extend. @@ -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 From 5bee8011396353a5cc7307f373e02fcc148e57e5 Mon Sep 17 00:00:00 2001 From: George Date: Tue, 26 Jan 2021 21:39:57 -0500 Subject: [PATCH 4/5] text= available in python 3.7+, gh runs 3.6, hhhhh --- utils/stylesheet/stylesheet_assets_builder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/stylesheet/stylesheet_assets_builder.py b/utils/stylesheet/stylesheet_assets_builder.py index 9f13aa3..b05490e 100644 --- a/utils/stylesheet/stylesheet_assets_builder.py +++ b/utils/stylesheet/stylesheet_assets_builder.py @@ -92,7 +92,7 @@ def build_css(self, sass_file): ["sass", "--no-charset", "main.scss"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, - text=True, + universal_newlines=True, ) if process.stderr: raise SassCompileException(process.stderr, sass_file.name) From 9fadd175ea72787515c268e0a1f6e38a61f3bf21 Mon Sep 17 00:00:00 2001 From: George Date: Tue, 26 Jan 2021 21:44:20 -0500 Subject: [PATCH 5/5] screw it, just run sass through npx --- .github/workflows/build-and-deploy.yml | 2 -- utils/stylesheet/stylesheet_assets_builder.py | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index 4c828dc..01346d5 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -18,8 +18,6 @@ jobs: python-version: '3.6' - name: Install pip requirements run: pip install -r utils/requirements.txt - - name: Install Sass CLI - run: npm install sass - name: Build and some other testing stuff run: | echo ${{ github.ref }} diff --git a/utils/stylesheet/stylesheet_assets_builder.py b/utils/stylesheet/stylesheet_assets_builder.py index b05490e..1965ce1 100644 --- a/utils/stylesheet/stylesheet_assets_builder.py +++ b/utils/stylesheet/stylesheet_assets_builder.py @@ -89,7 +89,7 @@ def build_css(self, sass_file): logger.debug("Compiling the Sass file.") process = subprocess.run( - ["sass", "--no-charset", "main.scss"], + ["npx", "-q", "sass", "--no-charset", "main.scss"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True,