Skip to content
Open
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
/dist/*
/sass.egg-info/*
/sass.so
/test.pyc
/sass.c
build
*.pyc
2 changes: 1 addition & 1 deletion libsass
Submodule libsass updated from 0388a6 to 1122ea
7 changes: 6 additions & 1 deletion sass.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ SASS_STYLE_COMPRESSED = 3

__version__ = '2.2+libsass1.0.1'


cdef extern from "libsass/sass_interface.h":

cdef struct sass_options:
Expand All @@ -39,6 +40,8 @@ cdef extern from "libsass/sass_interface.h":
cdef struct sass_file_context:
char* input_path
char* output_string
char* source_map_string
char* source_map_file
sass_options options
int error_status
char* error_message
Expand Down Expand Up @@ -74,14 +77,16 @@ def compile_string(bytes s, include_paths=None, image_path=None, int output_styl
sass_free_context(ctx)


def compile_file(bytes path, include_paths=None, int output_style=SASS_STYLE_NESTED):
def compile_file(bytes path, include_paths=None, image_path=None, int output_style=SASS_STYLE_NESTED):
"""Compiles SASS file to CSS string"""

include_paths = include_paths or b''
image_path = image_path or b''
cdef sass_file_context* ctx = sass_new_file_context()
try:
ctx.input_path = path
ctx.options.include_paths = include_paths
ctx.options.image_path = image_path
ctx.options.output_style = output_style
sass_compile_file(ctx)
if ctx.error_status:
Expand Down
55 changes: 27 additions & 28 deletions setup.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/usr/bin/env python
# Copyright 2012 Sergey Kirillov
#
# Licensed under the Apache License, Version 2.0 (the "License");
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Expand All @@ -19,10 +20,11 @@
try:
from Cython.Distutils import build_ext
except ImportError:
print("No Cython installed. Building from pregenerated C source.")
print('No Cython installed. Building from pregenerated C source.')
build_ext = None

import os.path

here = os.path.dirname(os.path.abspath(__file__))

libsass_sources = [
Expand Down Expand Up @@ -53,35 +55,32 @@
]

if build_ext:
sources = libsass_sources + ["sass.pyx"]
sources = libsass_sources + ['sass.pyx']
cmdclass = {'build_ext': build_ext}
else:
sources = libsass_sources + ["sass.cpp"]
sources = libsass_sources + ['sass.cpp']
cmdclass = {}

ext_modules = [Extension("sass",
sources,
libraries=['stdc++'],
library_dirs=['./libsass'],
include_dirs=['.', 'libsass'],
language='c++'
)]
ext_modules = [
Extension('sass', sources, libraries=['stdc++'], library_dirs=['./libsass'],
include_dirs=['.', 'libsass'], language='c++')]

setup(
name = 'sass',
cmdclass = cmdclass,
ext_modules = ext_modules,
version = '2.2',
author = 'Sergey Kirilov',
author_email = 'sergey.kirillov@gmail.com',
url='https://github.com/pistolero/python-scss',
install_requires=[],
extras_require = {
# 'develop': ['Cython']
},
tests_require = ['nose'],
license="Apache License 2.0",
keywords="sass scss libsass",
description='Python bindings for libsass',
long_description=open(os.path.join(here, 'README.rst'), 'rb').read().decode('utf-8')
name='sass',
cmdclass=cmdclass,
ext_modules=ext_modules,
version='2.2',
author='Sergey Kirilov',
author_email='sergey.kirillov@gmail.com',
url='https://github.com/pistolero/python-scss',
install_requires=[],
extras_require={
# 'develop': ['Cython']
},
tests_require=['nose'],
test_suite='test',
license='Apache License 2.0',
keywords='sass scss libsass',
description='Python bindings for libsass',
long_description=open(os.path.join(here, 'README.rst'), 'rb').read().decode('utf-8')
)
45 changes: 20 additions & 25 deletions test.py → test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from __future__ import unicode_literals

import sass
from nose.tools import eq_, assert_equal, raises

@raises(sass.CompileError)
def test1():
result = sass.compile_string(b'asd', '', sass.SASS_STYLE_NESTED)
eq_(result, b'asd')

from unittest import TestCase
from os import path

def test2():
result = sass.compile_string(b'''table.hl {
margin: 2em 0;
td.ln {
text-align: right;
}
}
import sass

li {
font: {
family: serif;
weight: bold;
size: 1.2em;
}
}''', '', sass.SASS_STYLE_NESTED)

expected = b'''table.hl {
scss_test_file = str(path.normpath(path.join(path.dirname(__file__), 'test.scss')))
compiled_result = b'''table.hl {
margin: 2em 0; }
table.hl td.ln {
text-align: right; }
Expand All @@ -49,4 +31,17 @@ def test2():
font-size: 1.2em; }
'''

assert_equal(result, expected)

class SASSTest(TestCase):

def test_compile_string_with_bad_string(self):
self.assertRaises(sass.CompileError, lambda: sass.compile_string(b'bad string'))

def test_compile_string(self):
with file(scss_test_file, 'rb') as scss_file:
result = sass.compile_string(scss_file.read())
self.assertEqual(result, compiled_result)

def test_compile_file(self):
result = sass.compile_file(scss_test_file)
self.assertEqual(result, compiled_result)
14 changes: 14 additions & 0 deletions test/test.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
table.hl {
margin: 2em 0;
td.ln {
text-align: right;
}
}

li {
font: {
family: serif;
weight: bold;
size: 1.2em;
}
}