diff --git a/.gitignore b/.gitignore index 0e17dd1..3e02977 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,6 @@ /dist/* /sass.egg-info/* /sass.so -/test.pyc /sass.c build +*.pyc diff --git a/libsass b/libsass index 0388a62..1122ead 160000 --- a/libsass +++ b/libsass @@ -1 +1 @@ -Subproject commit 0388a62b764c062bbcd45782ec09476c4673efcd +Subproject commit 1122ead208a8d1c438daaca70041ef6dd2361fa0 diff --git a/sass.pyx b/sass.pyx index dafe285..c61bd8f 100644 --- a/sass.pyx +++ b/sass.pyx @@ -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: @@ -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 @@ -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: diff --git a/setup.py b/setup.py old mode 100644 new mode 100755 index f121497..6b67ea5 --- a/setup.py +++ b/setup.py @@ -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. @@ -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 = [ @@ -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') ) diff --git a/test.py b/test/__init__.py similarity index 51% rename from test.py rename to test/__init__.py index 965b2e7..852dae6 100644 --- a/test.py +++ b/test/__init__.py @@ -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; } @@ -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) diff --git a/test/test.scss b/test/test.scss new file mode 100644 index 0000000..d3300ea --- /dev/null +++ b/test/test.scss @@ -0,0 +1,14 @@ +table.hl { + margin: 2em 0; + td.ln { + text-align: right; + } +} + +li { + font: { + family: serif; + weight: bold; + size: 1.2em; + } +}