diff options
-rw-r--r-- | scss/functions/compass/images.py | 15 | ||||
-rw-r--r-- | scss/functions/compass/sprites.py | 5 | ||||
-rw-r--r-- | scss/functions/fonts.py | 10 | ||||
-rw-r--r-- | scss/scss_meta.py | 8 | ||||
-rw-r--r-- | scss/tests/conftest.py | 8 | ||||
-rw-r--r-- | scss/tests/functions/compass/test_images.py | 2 | ||||
-rw-r--r-- | scss/tests/test_files.py | 2 | ||||
-rw-r--r-- | scss/util.py | 3 | ||||
-rw-r--r-- | setup.py | 12 | ||||
-rw-r--r-- | tox.ini | 35 |
10 files changed, 77 insertions, 23 deletions
diff --git a/scss/functions/compass/images.py b/scss/functions/compass/images.py index bf269e0..e9b4e6c 100644 --- a/scss/functions/compass/images.py +++ b/scss/functions/compass/images.py @@ -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' @@ -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') @@ -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: @@ -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) @@ -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: @@ -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: diff --git a/scss/functions/compass/sprites.py b/scss/functions/compass/sprites.py index ca70ccd..908adcd 100644 --- a/scss/functions/compass/sprites.py +++ b/scss/functions/compass/sprites.py @@ -13,6 +13,7 @@ import logging import os.path import tempfile import time +import sys try: import cPickle as pickle @@ -398,6 +399,10 @@ def sprite_map(g, **kwargs): 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): diff --git a/scss/functions/fonts.py b/scss/functions/fonts.py index 6fdadda..d3bea42 100644 --- a/scss/functions/fonts.py +++ b/scss/functions/fonts.py @@ -15,6 +15,8 @@ import tempfile import subprocess import warnings +import six + try: import cPickle as pickle except ImportError: @@ -277,11 +279,11 @@ def font_sheet(g, **kwargs): 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': diff --git a/scss/scss_meta.py b/scss/scss_meta.py index d591ef3..7b2ea96 100644 --- a/scss/scss_meta.py +++ b/scss/scss_meta.py @@ -44,6 +44,8 @@ xCSS: """ 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) @@ -55,6 +57,12 @@ URL = 'http://github.com/Kronuz/pyScss' 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) diff --git a/scss/tests/conftest.py b/scss/tests/conftest.py index 64ef44e..b2036ff 100644 --- a/scss/tests/conftest.py +++ b/scss/tests/conftest.py @@ -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") diff --git a/scss/tests/functions/compass/test_images.py b/scss/tests/functions/compass/test_images.py index e98391a..1478fa7 100644 --- a/scss/tests/functions/compass/test_images.py +++ b/scss/tests/functions/compass/test_images.py @@ -20,6 +20,7 @@ from scss.rule import Namespace import pytest from scss import config import os +import sys from _pytest.monkeypatch import monkeypatch xfail = pytest.mark.xfail @@ -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')) diff --git a/scss/tests/test_files.py b/scss/tests/test_files.py index 6bd39de..eaaba4c 100644 --- a/scss/tests/test_files.py +++ b/scss/tests/test_files.py @@ -19,7 +19,7 @@ import scss if six.PY2: - from codecs import open + from io import open console = logging.StreamHandler() diff --git a/scss/util.py b/scss/util.py index c99d914..481a0c0 100644 --- a/scss/util.py +++ b/scss/util.py @@ -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('=') @@ -7,12 +7,10 @@ import platform 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 @@ -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', @@ -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 |