Skip to content

Commit

Permalink
* Added new settings to enabled sourcemap generation, close #6;
Browse files Browse the repository at this point in the history
* Finalize documentation, close #10
* Bump to 0.9.0;
  • Loading branch information
sveetch committed May 1, 2016
1 parent d04f0fb commit 0ef6797
Show file tree
Hide file tree
Showing 16 changed files with 200 additions and 30 deletions.
2 changes: 1 addition & 1 deletion boussole/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
Aims to reproduce the useful Compass commandline tool behaviors
"""
__version__ = '0.8.3'
__version__ = '0.9.0'
24 changes: 20 additions & 4 deletions boussole/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@

import sass

from boussole.finder import ScssFinder

class SassCompileHelper(object):

class SassCompileHelper(ScssFinder):
"""
Sass compile helper mixin
"""
Expand All @@ -28,9 +30,6 @@ def safe_compile(self, settings, sourcepath, destination):
It will create needed directory structure first if it contain some
directories that does not allready exists.
Todo:
Maybe this can inherit from finder.
Args:
settings (boussole.conf.model.Settings): Project settings.
sourcepath (str): Source file path to compile to CSS.
Expand All @@ -45,17 +44,34 @@ def safe_compile(self, settings, sourcepath, destination):
message will contains returned error from libsass, if success
just the destination path.
"""
source_map_destination = None
if settings.SOURCE_MAP:
source_map_destination = self.change_extension(destination, "map")

try:
content = sass.compile(
filename=sourcepath,
output_style=settings.OUTPUT_STYLES,
source_comments=settings.SOURCE_COMMENTS,
include_paths=settings.LIBRARY_PATHS,
# Sourcemap is allways in the same directory than compiled file
source_map_filename=source_map_destination,
)
except sass.CompileError as e:
return False, e.message
else:
# Compiler return a tuple (css, map) if sourcemap is
# enabled
sourcemap = None
if settings.SOURCE_MAP:
content, sourcemap = content

self.write_content(content, destination)

# Write sourcemap if any
if sourcemap:
self.write_content(sourcemap, source_map_destination)

return True, destination

def write_content(self, content, destination):
Expand Down
4 changes: 4 additions & 0 deletions boussole/conf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
'default': False,
'postprocess': [],
},
'SOURCE_MAP': {
'default': False,
'postprocess': [],
},
'EXCLUDES': {
'default': [],
'postprocess': [],
Expand Down
6 changes: 3 additions & 3 deletions boussole/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ def resolve(self, sourcepath, paths, library_paths=None):
Note:
Resolving strategy is made like libsass do, meaning paths in
import rules is resolved from the source where the import rules
have been finded.
import rules are resolved from the source file where the import
rules have been finded.
If import rule is not explicit enough and two file are candidates
for the same rule, it will raises an error. But contrary to
libsass, this happen also for files from given libraries in
``library_paths`` (in this case libsass just silently taking the
``library_paths`` (oposed to libsass just silently taking the
first candidate).
Args:
Expand Down
6 changes: 6 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
Changelog
=========

Version 0.9.0 - 2016/05/01
--------------------------

* Added new settings to enabled sourcemap generation, close #6;
* Finalize documentation, close #10

Version 0.8.3 - 2016/04/23
--------------------------

Expand Down
14 changes: 13 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
contain the root `toctree` directive.
.. _SASS: http://sass-lang.com/
.. _LibSass: http://sass-lang.com/libsass
.. _Compass: http://compass-style.org/
.. _Watchdog: https://github.com/gorakhargosh/watchdog
.. _click: http://click.pocoo.org/5/
Expand All @@ -14,11 +15,22 @@
Welcome to Boussole's documentation!
====================================

This is a commandline interface to build `SASS`_ projects using `libsass-python`_.
Commandline interface to build `SASS`_ projects using `libsass-python`_.

.. Note::
Old SASS syntax (the *indented syntax*) is not supported.

Features
********

* Stand on `LibSass`_ which is **very fast**;
* **Per project configuration** so you can use it once to compile all of your SASS files from a same project;
* **Simple and useful** command line;
* **Watch mode** for no waste of time during web design integration;
* **Full Python stack**, no Ruby or Node.js stuff needed;
* **Expose a Core API** to use it from Python code;
* **Robust** because Unit tested;

Links
*****

Expand Down
12 changes: 12 additions & 0 deletions docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,15 @@ Install

It should be safe enough to install it on Linux, MacOSX and Windows until you
have the right environment (needed devel libs, etc..).


.. Note::
Because some requirements need to compile some C modules, this would take
some minutes to install Boussole again for each of your projects under
their own virtual environment.

Also Libsass compatibility should be safe enough for your future projects.

So we recommend you to install this software at your system level if
installation speed is important to you.

5 changes: 5 additions & 0 deletions docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Here is a full sample of available settings for project configuration:
"TARGET_PATH": "/home/bar",
"OUTPUT_STYLES": "nested",
"SOURCE_COMMENTS": false,
"SOURCE_MAP": false,
"EXCLUDES": [
"*/*.backup.scss",
"/home/lib2"
Expand Down Expand Up @@ -69,6 +70,10 @@ SOURCE_COMMENTS
Default: ``false``

(boolean) If ``true``, comments about source lines will be added to each rule in resulted CSS from compile.
SOURCE_MAP
Default: ``false``

(boolean) If ``true``, generate a source map for each compiled file. Source map filename will be the same that compiled file but with extension changed to ``.map``.
EXCLUDES
Default: Empty list

Expand Down
10 changes: 5 additions & 5 deletions tests/100_compiler/001_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import pytest


def test_001(settings, compiler, temp_builds_dir):
def test_001(compiler, temp_builds_dir):
"""compiler.SassCompileHelper.write_content: Just creating file with latin
content"""
filepath = temp_builds_dir.join('compiler_001')
filepath = temp_builds_dir.join('compiler_write_001')

content = u"""Some sample latin text"""

Expand All @@ -20,10 +20,10 @@ def test_001(settings, compiler, temp_builds_dir):
assert content == result


def test_002(settings, compiler, temp_builds_dir):
def test_002(compiler, temp_builds_dir):
"""compiler.SassCompileHelper.write_content: Creating file with unicode
content"""
filepath = temp_builds_dir.join('compiler_002')
filepath = temp_builds_dir.join('compiler_write_002')

content = u"""Some sample unicode text: フランス Furansu"""

Expand All @@ -36,7 +36,7 @@ def test_002(settings, compiler, temp_builds_dir):
assert content == result


def test_003(settings, compiler, temp_builds_dir):
def test_003(compiler, temp_builds_dir):
"""compiler.SassCompileHelper.write_content: Creating file into
subdirectory"""
filepath = temp_builds_dir.join('foo/bar/home.txt')
Expand Down
116 changes: 113 additions & 3 deletions tests/100_compiler/002_compile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,114 @@
# -*- coding: utf-8 -*-
"""
No test here because it seems redondant with tests for cli.compile.
"""
import os
import io
import json
import pytest

from boussole.conf.model import Settings


def test_001(compiler, temp_builds_dir):
"""compiler.SassCompileHelper.safe_compile: Basic sample without source map"""
basedir = temp_builds_dir.join('compiler_safecompile_001').strpath

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

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")
dst = os.path.join(targetdir, "app.css")
src_map = os.path.join(targetdir, "app.map")

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

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

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

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

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

assert content == ("""#content { color: #ff0000; font-weight: bold; }\n\n"""
"""#content.foo { border: 1px solid #000000; }\n""")

def test_002(compiler, temp_builds_dir):
"""compiler.SassCompileHelper.safe_compile: Same as basic sample but with
source map"""
basedir = temp_builds_dir.join('compiler_safecompile_002').strpath

basic_settings = Settings(initial={
'SOURCES_PATH': '.',
'TARGET_PATH': 'css',
'SOURCE_MAP': True,
'OUTPUT_STYLES': 'compact',
})

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

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

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

# Create sample source to compile
with io.open(src, 'w', encoding='utf-8') as f:
result = f.write(u"""#content{ color:#ff0000; font-weight:bold; }""")

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

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

with io.open(dst, 'r', encoding='utf-8') as f:
content = f.read()

with io.open(src_map, 'r', encoding='utf-8') as f:
sourcemap = json.load(f)

#print content
#print "."*60
#print sourcemap

# Assert compiled file is ok
assert content == ("""#content { color: #ff0000; font-weight: bold; }\n\n"""
"""/*# sourceMappingURL=css/app.map */""")

# Assert sourcemap is ok
# Drop 'version' key since it will cause problem with futur libsass
# versions
del sourcemap['version']
# Assert source map is ok
assert sourcemap == {
"file": "../app.css",
"sources": [
"../app.scss"
],
"mappings": ("AAAA,AAAA,QAAQ,CAAA,EAAE,KAAK,EAAC,OAAQ,EAAE,WAAW,EAAC,"
"IAAK,GAAI"),
"names": []
}

4 changes: 2 additions & 2 deletions tests/101_watcher/001_fails.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
build_sample_structure)


def test_index_001(settings, caplog, temp_builds_dir):
def test_index_001(caplog, temp_builds_dir):
"""watcher.SassProjectEventHandler: UnresolvablePath on index from 'on_any_event'"""
basedir = temp_builds_dir.join('watcher_fails_001')

Expand Down Expand Up @@ -54,7 +54,7 @@ def test_index_001(settings, caplog, temp_builds_dir):
]


def test_deleted_041(settings, caplog, temp_builds_dir):
def test_deleted_001(caplog, temp_builds_dir):
"""watcher.SassProjectEventHandler: UnresolvablePath on 'Deleted' event for a partial
source included by other files"""
basedir = temp_builds_dir.join('watcher_fails_041')
Expand Down
Loading

0 comments on commit 0ef6797

Please sign in to comment.