From b9a6aca7201ad355c24d281f87238db8b590a8cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ociepka?= Date: Wed, 14 May 2014 19:23:54 +0200 Subject: [PATCH 1/7] Add required image_path to context options Issue #21 --- sass.pyx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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: From 9219d796647341f55cb8ea5cfca479097d8e0a97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ociepka?= Date: Wed, 14 May 2014 19:26:19 +0200 Subject: [PATCH 2/7] Test the compile_file method Issue #21 --- test.py => test/__init__.py | 43 +++++++++++++++--------------------- test/__init__.pyc | Bin 0 -> 1814 bytes test/test.scss | 14 ++++++++++++ 3 files changed, 32 insertions(+), 25 deletions(-) rename test.py => test/__init__.py (53%) create mode 100644 test/__init__.pyc create mode 100644 test/test.scss diff --git a/test.py b/test/__init__.py similarity index 53% rename from test.py rename to test/__init__.py index 965b2e7..b4f49c6 100644 --- a/test.py +++ b/test/__init__.py @@ -12,33 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from unittest import TestCase +from os import path 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') - - -def test2(): - result = sass.compile_string(b'''table.hl { - margin: 2em 0; - td.ln { - text-align: right; - } -} - -li { - font: { - family: serif; - weight: bold; - size: 1.2em; - } -}''', '', sass.SASS_STYLE_NESTED) - - expected = b'''table.hl { +scss_test_file = path.normpath(path.join(path.dirname(__file__), 'test.scss')) +compiled_result = '''table.hl { margin: 2em 0; } table.hl td.ln { text-align: right; } @@ -49,4 +29,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('bad string')) + + def test_compile_string(self): + with file(scss_test_file) 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/__init__.pyc b/test/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c64d3e19c162212bf756f97181c7816fdf6731d1 GIT binary patch literal 1814 zcmcIkO>fgc5FOh|O2bzXH{f7Ygd(9Pz_FkTsJK?bK>~7Fx$!31;E&+ls1({$xg-7r ze~=#l@2x{B5XWL=CbP5S-I@1h9R0Z3eem55$Fh1__6 z8$Z@X{P0P93fFqyW&OPLQE=*yZYRyn6tT6L&KzUAx$)bRs&qS(v@rScZftdJCQopV z_a12m@5YB!o~@nMeA2t|qdqR>F+Ts{^Wl&+tPy5qFCcasN(+Gnt^i^b5^Wk0VW!cN zWY~)kH|ARuF7_ez7SxHz9CZgW|NSbUCQHL!i0y+hlz+GyLhMy2hqrKNKvGtLwhRAZ zn#I=Drkwh>U5hWI*1Bsj##ON}xmK$Hc%-*hmKhCZRiOvt*<^53)$i>h9qU11>Sdwz zz`EmHPnRasgT=9%Rpky@8<4+&Ql>OcsXlf{_|rTs4zqOc9&GEcV9o9d6q3=kOHyOC zP1fH1CbgG!UDfAZVs$?G4;gMV7o@HJ1VkMfH&Z}x1rWn5QJ26|$7DN@eTdzI0tw&^ z41B#Kr-8Uo=8>F$NsJ3-B9PNi-hjzhZ%J}nPC{`VPEtcJTj8L$!GlQC1k`w%2&?k> z(d98p7~rF7oo4PbRt=6XKP=PSUB`M=OQvdVm$~yDmyip`Df4Ig8(6_A1Xj}k7smZf zocIr9@560*u>{wH+YOoomWX;Zw_!9b4G;-j;OD}liL(EKtc~dN*7;4M2aCug9FT+! z?`Ob+kZf@Yx!{6t;KV-)W)=_Nv}BCs_L!|73Z=@l&`LQDs!~OjEisHLAwLNZN(kS1 zlHR%~Y7*jo7vg#7gqzW3yT^I-sVy Date: Wed, 14 May 2014 19:26:59 +0200 Subject: [PATCH 3/7] Add test suit to the setup.py file Now you can call `./setup.py test`. --- setup.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) mode change 100644 => 100755 setup.py diff --git a/setup.py b/setup.py old mode 100644 new mode 100755 index f121497..9f8f1fa --- a/setup.py +++ b/setup.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python # Copyright 2012 Sergey Kirillov # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -59,7 +60,7 @@ sources = libsass_sources + ["sass.cpp"] cmdclass = {} -ext_modules = [Extension("sass", +ext_modules = [Extension("sass", sources, libraries=['stdc++'], library_dirs=['./libsass'], @@ -74,14 +75,15 @@ version = '2.2', author = 'Sergey Kirilov', author_email = 'sergey.kirillov@gmail.com', - url='https://github.com/pistolero/python-scss', + 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", + 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') ) From 7a9c560f4b2bf66774e5ab091d24e7ce71e24a0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ociepka?= Date: Wed, 14 May 2014 19:29:27 +0200 Subject: [PATCH 4/7] PEP8 --- setup.py | 55 ++++++++++++++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/setup.py b/setup.py index 9f8f1fa..6b67ea5 100755 --- a/setup.py +++ b/setup.py @@ -1,14 +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. @@ -20,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 = [ @@ -54,36 +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'], - 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') + 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') ) From 0fe48674cc4ed543c4d93c547204488d67f78b4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ociepka?= Date: Wed, 28 May 2014 13:30:58 +0200 Subject: [PATCH 5/7] Use libsass version with fixed if statement More details on: https://github.com/twbs/bootstrap-sass/issues/506 Now we are using the same libsass version as the node sass. --- libsass | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsass b/libsass index 0388a62..1122ead 160000 --- a/libsass +++ b/libsass @@ -1 +1 @@ -Subproject commit 0388a62b764c062bbcd45782ec09476c4673efcd +Subproject commit 1122ead208a8d1c438daaca70041ef6dd2361fa0 From 627fab5f0dd4ac4690587ecbda7cb97f4ee52fc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ociepka?= Date: Wed, 28 May 2014 17:29:35 +0200 Subject: [PATCH 6/7] Python 3 compatibility --- test/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/__init__.py b/test/__init__.py index b4f49c6..852dae6 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -12,13 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from __future__ import unicode_literals + from unittest import TestCase from os import path import sass -scss_test_file = path.normpath(path.join(path.dirname(__file__), 'test.scss')) -compiled_result = '''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; } @@ -33,10 +35,10 @@ class SASSTest(TestCase): def test_compile_string_with_bad_string(self): - self.assertRaises(sass.CompileError, lambda: sass.compile_string('bad string')) + self.assertRaises(sass.CompileError, lambda: sass.compile_string(b'bad string')) def test_compile_string(self): - with file(scss_test_file) as scss_file: + with file(scss_test_file, 'rb') as scss_file: result = sass.compile_string(scss_file.read()) self.assertEqual(result, compiled_result) From 918a2c8b9d9410a6de59575de5d48087fcd414b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ociepka?= Date: Wed, 28 May 2014 17:33:27 +0200 Subject: [PATCH 7/7] Remove test.pyc file --- .gitignore | 2 +- test/__init__.pyc | Bin 1814 -> 0 bytes 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 test/__init__.pyc 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/test/__init__.pyc b/test/__init__.pyc deleted file mode 100644 index c64d3e19c162212bf756f97181c7816fdf6731d1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1814 zcmcIkO>fgc5FOh|O2bzXH{f7Ygd(9Pz_FkTsJK?bK>~7Fx$!31;E&+ls1({$xg-7r ze~=#l@2x{B5XWL=CbP5S-I@1h9R0Z3eem55$Fh1__6 z8$Z@X{P0P93fFqyW&OPLQE=*yZYRyn6tT6L&KzUAx$)bRs&qS(v@rScZftdJCQopV z_a12m@5YB!o~@nMeA2t|qdqR>F+Ts{^Wl&+tPy5qFCcasN(+Gnt^i^b5^Wk0VW!cN zWY~)kH|ARuF7_ez7SxHz9CZgW|NSbUCQHL!i0y+hlz+GyLhMy2hqrKNKvGtLwhRAZ zn#I=Drkwh>U5hWI*1Bsj##ON}xmK$Hc%-*hmKhCZRiOvt*<^53)$i>h9qU11>Sdwz zz`EmHPnRasgT=9%Rpky@8<4+&Ql>OcsXlf{_|rTs4zqOc9&GEcV9o9d6q3=kOHyOC zP1fH1CbgG!UDfAZVs$?G4;gMV7o@HJ1VkMfH&Z}x1rWn5QJ26|$7DN@eTdzI0tw&^ z41B#Kr-8Uo=8>F$NsJ3-B9PNi-hjzhZ%J}nPC{`VPEtcJTj8L$!GlQC1k`w%2&?k> z(d98p7~rF7oo4PbRt=6XKP=PSUB`M=OQvdVm$~yDmyip`Df4Ig8(6_A1Xj}k7smZf zocIr9@560*u>{wH+YOoomWX;Zw_!9b4G;-j;OD}liL(EKtc~dN*7;4M2aCug9FT+! z?`Ob+kZf@Yx!{6t;KV-)W)=_Nv}BCs_L!|73Z=@l&`LQDs!~OjEisHLAwLNZN(kS1 zlHR%~Y7*jo7vg#7gqzW3yT^I-sVy