Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
b9a6aca
Add required image_path to context options
May 14, 2014
9219d79
Test the compile_file method
May 14, 2014
c7f5203
Add test suit to the setup.py file
May 14, 2014
7a9c560
PEP8
May 14, 2014
0fe4867
Use libsass version with fixed if statement
May 28, 2014
627fab5
Python 3 compatibility
May 28, 2014
918a2c8
Remove test.pyc file
May 28, 2014
ecc89e0
Updated setup.py to automatically getting libsass submodule
PhilipGarnero Jun 19, 2014
948a38a
print function for python3
bwhmather Jul 14, 2014
b8af939
Makefile duplicates functionality in setup.py. delete it
bwhmather Jul 14, 2014
7936779
clean up .gitignore
bwhmather Jul 14, 2014
dce0015
bail out if cython is not installed and sass.cpp does not exist
bwhmather Jul 14, 2014
776b92e
trailing ,
bwhmather Jul 14, 2014
9a6ae7a
don't load description from README
bwhmather Jul 14, 2014
f25d195
massive refactor
bwhmather Jul 15, 2014
0f4430d
pep8
bwhmather Jul 15, 2014
6c2e831
remove debug print
bwhmather Jul 15, 2014
718ec6e
only force installation of cython if pregenerated c file does not exist
bwhmather Jul 15, 2014
83cc6c4
call cythonize on extension not just pyx file
bwhmather Jul 15, 2014
068a0ad
move string conversion into python
bwhmather Jul 15, 2014
f5efa90
move pyx file into module
bwhmather Jul 15, 2014
2059353
update .gitignore
bwhmather Jul 15, 2014
493d1f1
remove _sass.so. should never have been committed
bwhmather Jul 15, 2014
19eb61f
update travis config
bwhmather Jul 15, 2014
b20a33d
add generate cpp file to manifest
bwhmather Jul 15, 2014
cb904b3
use open instead of file
bwhmather Jul 15, 2014
01ffd6c
pep8
bwhmather Jul 15, 2014
e71b5e9
distutils uses old style classes and breaks super
bwhmather Jul 18, 2014
65b2776
include test scss files
bwhmather Jul 18, 2014
650d2b6
load test file using pkg_resources
bwhmather Jul 18, 2014
deff791
Always use cython if running from a git repository
bwhmather Jul 18, 2014
3a19429
fix git folder path
bwhmather Jul 18, 2014
f75c8e3
try again to remove .so file from repo
bwhmather Jul 18, 2014
fdb1ec8
unused import
bwhmather Jul 18, 2014
9e17e43
copy paste error
bwhmather Jul 18, 2014
3c35d66
update to latest libsass
bwhmather Jul 18, 2014
200b776
don't export __version__. it's ignored
bwhmather Jul 18, 2014
c04aac3
use strings instead of enums
bwhmather Jul 18, 2014
507a007
force utf-8
bwhmather Jul 18, 2014
527401c
pep8
bwhmather Jul 21, 2014
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
16 changes: 9 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/sass.cpp
/dist/*
/sass.egg-info/*
/sass.so
/test.pyc
/sass.c
build
/sass/_sass.cpp
/dist/
/build/
*.egg-info/
*.egg
*.egg/
*.so
*.pyc
/.tox/
17 changes: 8 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
language: python

env:
- PIP_USE_MIRRORS=true
python:
- "2.6"
- "2.7"
- "3.2"
- "3.3"
- "3.4"

before_install:
- git submodule update --init --recursive

install:
- sudo apt-get install cython python-dev
- pip install coverage coveralls
- pip install -e .
- pip install pyflakes
- pip install pep8

script:
- ./travis-ci.sh

after_success:
- coveralls
- python setup.py test
- pyflakes setup.py sass
- pep8 setup.py sass
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include *.cpp
include sass/_sass.cpp
include sass/tests/*.scss
include README.rst
recursive-include libsass *.cpp *.hpp *.h
21 changes: 0 additions & 21 deletions Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion libsass
Submodule libsass updated from 0388a6 to fca1f7
41 changes: 41 additions & 0 deletions sass/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import sass._sass as _sass
from sass._sass import CompileError

OUTPUT_STYLES = {
'nested': 0,
'expanded': 1,
'compact': 2,
'compressed': 3,
}


def compile_string(string, include_paths=b'', image_path=b'',
output_style='nested'):
if not isinstance(string, bytes):
string = string.encode('utf-8')
if not isinstance(include_paths, bytes):
include_paths = include_paths.encode('utf-8')
if not isinstance(image_path, bytes):
image_path = image_path.encode('utf-8')
output_style = OUTPUT_STYLES[output_style]

return _sass.compile_string(
string, include_paths, image_path, output_style
)


def compile_file(path, include_paths=b'', image_path=b'',
output_style='nested'):
if not isinstance(path, bytes):
path = path.encode('utf-8')
if not isinstance(include_paths, bytes):
include_paths = include_paths.encode('utf-8')
if not isinstance(image_path, bytes):
image_path = image_path.encode('utf-8')
output_style = OUTPUT_STYLES[output_style]

return _sass.compile_file(
path, include_paths, image_path, output_style
)

__all__ = ['compile_string', 'compile_file', 'CompileError']
19 changes: 5 additions & 14 deletions sass.pyx → sass/_sass.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@
# limitations under the License.
#

SASS_STYLE_NESTED = 0
SASS_STYLE_EXPANDED = 1
SASS_STYLE_COMPACT = 2
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 +32,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 All @@ -55,11 +50,8 @@ cdef extern from "libsass/sass_interface.h":

class CompileError(Exception): pass

def compile_string(bytes s, include_paths=None, image_path=None, int output_style=SASS_STYLE_NESTED):
def compile_string(bytes s, bytes include_paths, bytes image_path, int output_style):
"""Compiles SASS string to CSS"""

include_paths = include_paths or b''
image_path = image_path or b''
cdef sass_context* ctx = sass_new_context()
try:
ctx.source_string = s
Expand All @@ -74,14 +66,13 @@ 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, bytes include_paths, bytes image_path, int output_style):
"""Compiles SASS file to CSS string"""

include_paths = include_paths 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
59 changes: 59 additions & 0 deletions sass/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright 2012 Sergey Kirillov
#
# 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,
# 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.
#
from __future__ import unicode_literals
from pkg_resources import resource_filename

import unittest

import sass

scss_test_file = resource_filename(__name__, 'test.scss')

compiled_result = b'''table.hl {
margin: 2em 0; }
table.hl td.ln {
text-align: right; }

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


class SASSTest(unittest.TestCase):

def test_compile_string_with_bad_string(self):
try:
sass.compile_string(b'bad string')
except sass.CompileError:
pass
else:
self.fail()

def test_compile_string(self):
with open(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)


loader = unittest.TestLoader()
suite = unittest.TestSuite((
loader.loadTestsFromTestCase(SASSTest),
))
14 changes: 14 additions & 0 deletions sass/tests/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;
}
}
110 changes: 69 additions & 41 deletions setup.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
#!/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.
#
import os.path

from distutils.extension import Extension
from setuptools import setup, Extension

try:
from Cython.Distutils import build_ext
except ImportError:
print("No Cython installed. Building from pregenerated C source.")
build_ext = None
from setuptools import setup, Extension, find_packages
from setuptools.command.sdist import sdist as _sdist
from setuptools.command.develop import develop as _develop

import os.path
here = os.path.dirname(os.path.abspath(__file__))
cmdclass = {}

libsass_sources = [
'libsass/ast.cpp',
Expand All @@ -33,6 +29,7 @@
'libsass/context.cpp',
'libsass/contextualize.cpp',
'libsass/copy_c_str.cpp',
'libsass/emscripten_wrapper.cpp',
'libsass/error_handling.cpp',
'libsass/eval.cpp',
'libsass/expand.cpp',
Expand All @@ -46,42 +43,73 @@
'libsass/prelexer.cpp',
'libsass/sass.cpp',
'libsass/sass_interface.cpp',
'libsass/sass2scss/sass2scss.cpp',
'libsass/source_map.cpp',
'libsass/to_c.cpp',
'libsass/to_string.cpp',
'libsass/units.cpp'
'libsass/trim.cpp',
'libsass/units.cpp',
'libsass/utf8_string.cpp',
'libsass/util.cpp',
]

if build_ext:
sources = libsass_sources + ["sass.pyx"]
cmdclass = {'build_ext': build_ext}
# If running from git repository, rebuild _sass.cpp from cython source,
# otherwise assume nothing has changed
if os.path.exists('.git/'):
# Force installation of Cython
from setuptools.dist import Distribution
Distribution(dict(setup_requires=['Cython']))

from Cython.Distutils import build_ext
cmdclass['build_ext'] = build_ext

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

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


class sdist(_sdist):
def run(self):
from Cython.Build import cythonize
print("pre-compiling cython")
cythonize(ext_modules)

_sdist.run(self)

cmdclass['sdist'] = sdist


class develop(_develop):
def run(self):
from subprocess import check_call
print("retrieving libsass submodule")
if os.path.exists('.git'):
check_call(['git', 'submodule', 'update', '--init', '--recursive'])
_develop.run(self)

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

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=[],
test_suite='sass.tests.suite',
packages=find_packages(),
license='Apache License 2.0',
keywords='sass scss libsass',
description='Python bindings for libsass',
zip_safe=False,
)
Loading