Skip to content

Commit

Permalink
[v1.5.0-pre.3] Fixed warning from libsass-python about 'custom_import…
Browse files Browse the repository at this point in the history
…_extensions'
  • Loading branch information
sveetch committed May 17, 2019
1 parent 3a6811b commit d8711f2
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 148 deletions.
1 change: 0 additions & 1 deletion boussole/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def safe_compile(self, settings, sourcepath, destination):
output_style=settings.OUTPUT_STYLES,
source_comments=settings.SOURCE_COMMENTS,
include_paths=settings.LIBRARY_PATHS,
custom_import_extensions=settings.CUSTOM_IMPORT_EXTENSIONS,
# Sourcemap is allways in the same directory than compiled
# CSS file
output_filename_hint=destination,
Expand Down
4 changes: 0 additions & 4 deletions boussole/conf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@
'default': False,
'postprocess': [],
},
'CUSTOM_IMPORT_EXTENSIONS': {
'default': ['.css'],
'postprocess': [],
},
'SOURCE_MAP': {
'default': False,
'postprocess': [],
Expand Down
25 changes: 22 additions & 3 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,29 @@ Changelog
Version 1.5.0 - Unreleased
--------------------------

**Indented Sass syntax support and fix some warnings from PyYaml and
libsass-python**
**Indented Sass syntax support and fix some warnings**

* Fixed PyYAML ``load()`` deprecation warning, close #36;
Fixed warning from libsass-python about 'custom_import_extensions'
..................................................................

Libsass has reverted its previous change from version 3.5.3 which ignored CSS
files on default. This has required to add a new option
``CUSTOM_IMPORT_EXTENSIONS`` in Boussole 1.2.3 to enable CSS files support.

Since CSS support is back again on default, we removed useless setting
``CUSTOM_IMPORT_EXTENSIONS`` and don't use anymore
``custom_import_extensions`` argument with libsass-python compiler.

This remove previous warning from libsass-python about
``custom_import_extensions`` deprecation.

Fixed PyYAML 'load()' deprecation warning
.........................................

For a recent security issue, PyYAML has introduced a change to its ``load()``
method to be more safe.

We now use the full loader mode so it does not trigger a warning anymore.

Indented Sass syntax support
............................
Expand Down
7 changes: 0 additions & 7 deletions docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ Here is a full sample of available settings for project configuration with JSON
],
"TARGET_PATH": "/home/bar",
"OUTPUT_STYLES": "nested",
"CUSTOM_IMPORT_EXTENSIONS": [
".css"
],
"SOURCE_COMMENTS": false,
"SOURCE_MAP": false,
"EXCLUDES": [
Expand Down Expand Up @@ -92,10 +89,6 @@ OUTPUT_STYLES
Default: ``nested``

(string) keyword of output style type used to compile your Sass sources. Can be either ``compact``, ``expanded``, ``nested`` or ``compressed``.
CUSTOM_IMPORT_EXTENSIONS
Default: ``[".css"]``

(list) List of enabled source extensions allowed to be included from ``@import`` directive. This aims to allow to treat some sources as Sass source to include. Default value is made so using ``@import 'foo'`` will include ``foo.css`` source if it exists. Set an empty list if you want to only allow Sass source extensions.
SOURCE_COMMENTS
Default: ``False``

Expand Down
9 changes: 9 additions & 0 deletions requirements_freeze.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
six==1.12.0
click==5.1
pathtools==0.1.2
watchdog==0.9.0
libsass==0.18.0
pyaml==19.4.1
PyYAML==5.1
colorama==0.4.1
colorlog==4.0.2
6 changes: 3 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;;
[metadata]
name = boussole
version = 1.5.0-pre.2
version = 1.5.0-pre.3
description = Commandline interface to build Sass projects using libsass-python
long_description = file:README.rst
long_description_content_type = text/x-rst
Expand Down Expand Up @@ -32,8 +32,8 @@ install_requires =
click>=5.1,<6.0
pathtools
watchdog
libsass>=0.14.5
pyaml>=5.1
libsass>=0.18.0
pyaml
colorama
colorlog
packages = find:
Expand Down
125 changes: 1 addition & 124 deletions tests/100_compiler/020_css_compat.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# -*- coding: utf-8 -*-
"""
Everything to cover compatibility issues with CSS sources since libsass==3.5.3,
related to issue #29
"""
import os
import io
import pytest
Expand All @@ -12,7 +8,7 @@

def test_css_compat_ok(compiler, temp_builds_dir):
"""
Ensure CSS import compatibility is still ok on default behavior
Ensure CSS import compatibility is ok
"""
basedir = temp_builds_dir.join('compiler_css_compat_ok').strpath

Expand All @@ -21,7 +17,6 @@ def test_css_compat_ok(compiler, temp_builds_dir):
'TARGET_PATH': 'css',
'SOURCE_MAP': False,
'OUTPUT_STYLES': 'compact',
#'CUSTOM_IMPORT_EXTENSIONS': [".css"],
})

sourcedir = os.path.join(basedir, basic_settings.SOURCES_PATH)
Expand Down Expand Up @@ -69,121 +64,3 @@ def test_css_compat_ok(compiler, temp_builds_dir):
"""#content.foo { border: 1px solid #000000; }\n""")

assert content == attempted


@pytest.mark.xfail(reason="This should fail with latest libsass-python which has reverted behavior to ignore CSS file by default")
def test_css_compat_fail(compiler, temp_builds_dir):
"""
Check CSS compat is disabled from settings
"""
basedir = temp_builds_dir.join('compiler_css_compat_fail').strpath

basic_settings = Settings(initial={
'SOURCES_PATH': 'scss',
'TARGET_PATH': 'css',
'SOURCE_MAP': False,
'OUTPUT_STYLES': 'compact',
'CUSTOM_IMPORT_EXTENSIONS': [],
})

sourcedir = os.path.join(basedir, basic_settings.SOURCES_PATH)
targetdir = os.path.join(basedir, basic_settings.TARGET_PATH)

src = os.path.join(sourcedir, "app.scss")
css_include = os.path.join(sourcedir, "_dummy.css")
dst = os.path.join(targetdir, "app.css")

os.makedirs(sourcedir)
os.makedirs(targetdir)

# Create sample main Sass source
with io.open(src, 'w', encoding='utf-8') as f:
result = f.write(
u"""
@import "dummy";
#content{
color: #ff0000;
font-weight: bold;
&.foo{ border: 1px solid #000000; }
}
""")

# Create sample main Sass source
with io.open(css_include, 'w', encoding='utf-8') as f:
result = f.write(
u"""
.dummy{
color: #00ff00;
}
""")

# Compile
success, message = compiler.safe_compile(basic_settings, src, dst)

attempted_error = "Error: File to import not found or unreadable: dummy."

assert (attempted_error in message) == True
assert success == False


def test_explicit_css_import_ok(compiler, temp_builds_dir):
"""
Explicitely imported CSS file allways insert ``@import [..]`` instead of
including CSS source no matter CUSTOM_IMPORT_EXTENSIONS settings
"""
name = 'compiler_css_compat_explicit_css_import_ok'
basedir = temp_builds_dir.join(name).strpath

basic_settings = Settings(initial={
'SOURCES_PATH': 'scss',
'TARGET_PATH': 'css',
'SOURCE_MAP': False,
'OUTPUT_STYLES': 'compact',
'CUSTOM_IMPORT_EXTENSIONS': [".css"],
})

sourcedir = os.path.join(basedir, basic_settings.SOURCES_PATH)
targetdir = os.path.join(basedir, basic_settings.TARGET_PATH)

src = os.path.join(sourcedir, "app.scss")
css_include = os.path.join(sourcedir, "_dummy.css")
dst = os.path.join(targetdir, "app.css")

os.makedirs(sourcedir)
os.makedirs(targetdir)

# Create sample main Sass source
with io.open(src, 'w', encoding='utf-8') as f:
result = f.write(
u"""
@import "dummy.css";
#content{
color: #ff0000;
font-weight: bold;
&.foo{ border: 1px solid #000000; }
}
""")

# Create sample main Sass source
with io.open(css_include, 'w', encoding='utf-8') as f:
result = f.write(
u"""
.dummy{
color: #00ff00;
}
""")

# Compile
success, message = compiler.safe_compile(basic_settings, src, dst)

assert os.path.exists(dst) == True

# Assert compiled file is ok
with io.open(dst, 'r', encoding='utf-8') as f:
content = f.read()

attempted = ("""@import url(dummy.css);\n"""
"""#content { color: #ff0000; font-weight: bold; }\n\n"""
"""#content.foo { border: 1px solid #000000; }\n""")

assert content == attempted
2 changes: 0 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ def sample_project_settings():
'SOURCES_PATH': u'/home/foo',
'TARGET_PATH': u'/home/bar',
'OUTPUT_STYLES': u'nested',
'CUSTOM_IMPORT_EXTENSIONS': ['.css'],
'SOURCE_COMMENTS': False,
'SOURCE_MAP': False,
"EXCLUDES": [],
Expand All @@ -151,7 +150,6 @@ def custom_project_settings():
'SOURCES_PATH': os.path.join(fixtures_settings.fixtures_path, u'sample_project'),
'TARGET_PATH': fixtures_settings.fixtures_path,
'OUTPUT_STYLES': u'expanded',
'CUSTOM_IMPORT_EXTENSIONS': ['.css'],
'SOURCE_COMMENTS': True,
'SOURCE_MAP': False,
"EXCLUDES": [
Expand Down
1 change: 0 additions & 1 deletion tests/data_fixtures/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
],
"TARGET_PATH": "/home/bar",
"OUTPUT_STYLES": "nested",
"CUSTOM_IMPORT_EXTENSIONS": [".css"],
"SOURCE_COMMENTS": false,
"SOURCE_MAP": false,
"EXCLUDES": []
Expand Down
1 change: 0 additions & 1 deletion tests/data_fixtures/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ LIBRARY_PATHS:
- /home/lib2
TARGET_PATH: /home/bar
OUTPUT_STYLES: nested
CUSTOM_IMPORT_EXTENSIONS: [".css"]
SOURCE_COMMENTS: false
SOURCE_MAP: false
EXCLUDES: []
1 change: 0 additions & 1 deletion tests/data_fixtures/settings_error.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
],
"TARGET_PATH": "/home/bar",
"OUTPUT_STYLES": "nested",
"CUSTOM_IMPORT_EXTENSIONS": [".css"],
"SOURCE_COMMENTS": false,
"SOURCE_MAP": false,
"EXCLUDES": []
Expand Down
1 change: 0 additions & 1 deletion tests/data_fixtures/settings_error.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ LIBRARY_PATHS:
ssss
TARGET_PATH: /home/bar
OUTPUT_STYLES: nested
CUSTOM_IMPORT_EXTENSIONS: [".css"]
SOURCE_COMMENTS: false
SOURCE_MAP: false
EXCLUDES: []

0 comments on commit d8711f2

Please sign in to comment.