Skip to content
Merged
15 changes: 9 additions & 6 deletions scss/functions/compass/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _image_url(path, only_path=False, cache_buster=True, dst_color=None, src_col
elif inline or dst_color or spacing:
path = _storage.open(_file)
else:
_path = os.path.join(IMAGES_ROOT.rstrip('/'), filepath.strip('/'))
_path = os.path.join(IMAGES_ROOT.rstrip(os.sep), filepath.strip('\\/'))
filetime = getmtime(_path)
if filetime is None:
filetime = 'NA'
Expand All @@ -90,7 +90,7 @@ def _image_url(path, only_path=False, cache_buster=True, dst_color=None, src_col
spacing = [int(Number(v).value) for v in List.from_maybe(spacing)]
spacing = (spacing * 4)[:4]

file_name, file_ext = os.path.splitext(os.path.normpath(filepath).replace('\\', '_').replace('/', '_'))
file_name, file_ext = os.path.splitext(os.path.normpath(filepath).replace(os.sep, '_'))
key = (filetime, src_color, dst_color, spacing)
asset_file = file_name + '-' + make_filename_hash(key) + file_ext
ASSETS_ROOT = config.ASSETS_ROOT or os.path.join(config.STATIC_ROOT, 'assets')
Expand Down Expand Up @@ -166,7 +166,7 @@ def _image_url(path, only_path=False, cache_buster=True, dst_color=None, src_col
except IOError:
log.exception("Error while saving image")
inline = True # Retry inline version
url = os.path.join(config.ASSETS_URL.rstrip('/'), asset_file.lstrip('/'))
url = os.path.join(config.ASSETS_URL.rstrip(os.sep), asset_file.lstrip(os.sep))
if cache_buster:
url = add_cache_buster(url, filetime)
if inline:
Expand All @@ -176,10 +176,13 @@ def _image_url(path, only_path=False, cache_buster=True, dst_color=None, src_col
output.close()
url = make_data_url(mime_type, contents)
else:
url = os.path.join(BASE_URL.rstrip('/'), filepath.lstrip('/'))
url = os.path.join(BASE_URL.rstrip('/'), filepath.lstrip('\\/'))
if cache_buster and filetime != 'NA':
url = add_cache_buster(url, filetime)

if not os.sep == '/':
url = url.replace(os.sep, '/')

if not only_path:
url = 'url(%s)' % escape(url)
return String.unquoted(url)
Expand Down Expand Up @@ -239,7 +242,7 @@ def image_width(image):
else:
path = _storage.open(_file)
else:
_path = os.path.join(IMAGES_ROOT, filepath.strip('/'))
_path = os.path.join(IMAGES_ROOT, filepath.strip(os.sep))
if os.path.exists(_path):
path = open(_path, 'rb')
if path:
Expand Down Expand Up @@ -273,7 +276,7 @@ def image_height(image):
else:
path = _storage.open(_file)
else:
_path = os.path.join(IMAGES_ROOT, filepath.strip('/'))
_path = os.path.join(IMAGES_ROOT, filepath.strip(os.sep))
if os.path.exists(_path):
path = open(_path, 'rb')
if path:
Expand Down
5 changes: 5 additions & 0 deletions scss/functions/compass/sprites.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import os.path
import tempfile
import time
import sys

try:
import cPickle as pickle
Expand Down Expand Up @@ -398,6 +399,10 @@ def images(f=lambda x: x):
cache_tmp = tempfile.NamedTemporaryFile(delete=False, dir=ASSETS_ROOT)
pickle.dump((now_time, file_asset, inline_asset, sprite_map, sizes), cache_tmp)
cache_tmp.close()
if sys.platform == 'win32' and os.path.isfile(cache_path):
# on windows, cannot rename a file to a path that matches
# an existing file, we have to remove it first
os.remove(cache_path)
os.rename(cache_tmp.name, cache_path)

# Use the sorted list to remove older elements (keep only 500 objects):
Expand Down
10 changes: 6 additions & 4 deletions scss/functions/fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import subprocess
import warnings

import six

try:
import cPickle as pickle
except ImportError:
Expand Down Expand Up @@ -277,11 +279,11 @@ def glyphs(f=lambda x: x):
try:
if type_ == 'eot':
ttf_path = asset_paths['ttf']
with open(ttf_path) as ttf_fh, open(asset_path, 'wb') as asset_fh:
with open(ttf_path) as ttf_fh:
contents = ttf2eot(ttf_fh.read())
if contents is None:
continue
asset_fh.write(contents)
if contents is not None:
with open(asset_path, 'wb') as asset_fh:
asset_fh.write(contents)
else:
font.generate(asset_path)
if type_ == 'ttf':
Expand Down
8 changes: 8 additions & 0 deletions scss/scss_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
"""
from __future__ import unicode_literals

import sys

VERSION_INFO = (1, 3, 0, 'dev1')
DATE_INFO = (2013, 10, 8) # YEAR, MONTH, DAY
VERSION = '.'.join(str(i) for i in VERSION_INFO)
Expand All @@ -55,6 +57,12 @@
DOWNLOAD_URL = 'http://github.com/Kronuz/pyScss/tarball/v' + VERSION
LICENSE = "MIT"
PROJECT = "pyScss"
INSTALL_REQUIRES = [
'six',
]

if sys.version_info < (3, 4):
INSTALL_REQUIRES.append('enum34')

if __name__ == "__main__":
print('VERSION = ' + VERSION)
Expand Down
8 changes: 4 additions & 4 deletions scss/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ def pytest_configure(config):
# relative paths to the input file.
test_file_tuples = []
test_file_ids = []
for fn in glob.glob(os.path.join(FILES_DIR, '*/*.scss')):
for fn in glob.glob(os.path.join(FILES_DIR, '*%s*.scss' % os.sep)):
if os.path.basename(fn)[0] == '_':
continue

relfn = os.path.relpath(fn, FILES_DIR)
pytest_trigger = None

if relfn.startswith(('from-sassc/', 'from-ruby/')):
if relfn.startswith(('from-sassc' + os.sep, 'from-ruby' + os.sep)):
pytest_trigger = pytest.mark.skipif(
not include_ruby, reason="skipping ruby tests by default")
elif relfn.startswith('xfail/'):
elif relfn.startswith('xfail' + os.sep):
pytest_trigger = pytest.mark.xfail
elif relfn.startswith('fonts/'):
elif relfn.startswith('fonts' + os.sep):
pytest_trigger = pytest.mark.skipif(
not fontforge, reason="font tests require fontforge")

Expand Down
2 changes: 2 additions & 0 deletions scss/tests/functions/compass/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import pytest
from scss import config
import os
import sys
from _pytest.monkeypatch import monkeypatch
xfail = pytest.mark.xfail

Expand Down Expand Up @@ -47,6 +48,7 @@ def test_inline_image(calc):
assert 'url(data:image/png;base64,%s)' % font_base64 == calc('inline_image("/test-qr.png")').render()


@pytest.mark.skipif(sys.platform == 'win32', reason='cur mimetype is defined on windows')
def test_inline_cursor(calc):
monkeypatch().setattr(config, 'IMAGES_ROOT', os.path.join(config.PROJECT_ROOT, 'tests/files/cursors'))

Expand Down
2 changes: 1 addition & 1 deletion scss/tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


if six.PY2:
from codecs import open
from io import open


console = logging.StreamHandler()
Expand Down
3 changes: 3 additions & 0 deletions scss/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ def make_filename_hash(key):
# Python 2 and 3 and thus allowing the test suite to run on both.
# TODO better solutions include: not using a repr, not embedding hashes in
# the expected test results
if sys.platform == 'win32':
# this is to make sure the hash is the same on win and unix platforms
key_repr = key_repr.replace(b'\\\\', b'/')
key_repr = re.sub(b"\\bu'", b"'", key_repr)
key_hash = hashlib.md5(key_repr).digest()
return base64.b64encode(key_hash, b'__').decode('ascii').rstrip('=')
Expand Down
12 changes: 4 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
import sys

from setuptools import setup, Extension, Feature
from setuptools.dist import Distribution

# Need to install `six` to be able to import from the scss namespace
Distribution(dict(setup_requires='six'))

from scss.scss_meta import PROJECT, URL, VERSION, AUTHOR, AUTHOR_EMAIL, LICENSE, DOWNLOAD_URL
# this imports PROJECT, URL, VERSION, AUTHOR, AUTHOR_EMAIL, LICENSE,
# DOWNLOAD_URL, INSTALL_REQUIRES
exec(open('scss/scss_meta.py').read())

# fail safe compilation shamelessly stolen from the simplejson
# setup.py file. Original author: Bob Ippolito
Expand Down Expand Up @@ -100,9 +98,7 @@ def run_setup(with_binary):
"Topic :: Text Processing :: Markup",
"Topic :: Software Development :: Libraries :: Python Modules"
],
install_requires=[
'six',
],
install_requires=INSTALL_REQUIRES,
packages=[
'scss',
'scss.functions',
Expand Down
35 changes: 35 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[tox]
envlist = py26, py27, py32, py33, py34

[testenv]
# fontforge bindings cannot be installed from pip, so they may only be
# available system-wide
sitepackages = True
deps =
pillow
six
pytest
setenv =
PYTHONPATH = {toxinidir}
commands = {toxworkdir}/{envname}/Scripts/py.test []


[testenv:py26]
deps =
{[testenv]deps}
enum34

[testenv:py27]
deps =
{[testenv]deps}
enum34

[testenv:py32]
deps =
{[testenv]deps}
enum34

[testenv:py33]
deps =
{[testenv]deps}
enum34