From 558110896ab254cc80c86a3ab73210b9f09928c9 Mon Sep 17 00:00:00 2001 From: Thomas Khyn Date: Sun, 22 Jun 2014 22:09:51 +1200 Subject: [PATCH 1/9] test_images tests now pass --HG-- branch : compat_win --- scss/functions/compass/images.py | 15 +++++++++------ scss/tests/functions/compass/test_images.py | 2 ++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/scss/functions/compass/images.py b/scss/functions/compass/images.py index bf269e01..e9b4e6c1 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/tests/functions/compass/test_images.py b/scss/tests/functions/compass/test_images.py index e98391aa..874d3dae 100644 --- a/scss/tests/functions/compass/test_images.py +++ b/scss/tests/functions/compass/test_images.py @@ -20,6 +20,7 @@ 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')) From 6150388253d82aeb51ef9acb2b7bc018d96be073 Mon Sep 17 00:00:00 2001 From: Thomas Khyn Date: Sun, 22 Jun 2014 22:47:09 +1200 Subject: [PATCH 2/9] Updated tests generation to cope with win32's separator --HG-- branch : compat_win --- scss/tests/conftest.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scss/tests/conftest.py b/scss/tests/conftest.py index d607a85b..62a7b659 100644 --- a/scss/tests/conftest.py +++ b/scss/tests/conftest.py @@ -37,18 +37,18 @@ 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 if file_filters and not any(rx.search(relfn) for rx in file_filters): From 37264fe7643dbcd334a53e3ba6e196a7ef626a0a Mon Sep 17 00:00:00 2001 From: Thomas Khyn Date: Tue, 24 Jun 2014 00:10:45 +1200 Subject: [PATCH 3/9] Fixed make_filename_hash on windows --HG-- branch : compat_win --- scss/util.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scss/util.py b/scss/util.py index c84d69a5..2a168ad1 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('\\\\', '/') 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('=') From ed05592510f8c826348438ec64a7a12eaf1c3121 Mon Sep 17 00:00:00 2001 From: Thomas Khyn Date: Mon, 25 Aug 2014 11:19:39 +1200 Subject: [PATCH 4/9] Replaced codecs import by io for python 2 (had line break issues on win32) --- scss/tests/test_files.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scss/tests/test_files.py b/scss/tests/test_files.py index 6bd39de8..eaaba4c3 100644 --- a/scss/tests/test_files.py +++ b/scss/tests/test_files.py @@ -19,7 +19,7 @@ if six.PY2: - from codecs import open + from io import open console = logging.StreamHandler() From 683630495cd7a3e5680c6adb70dfcc53dea24e77 Mon Sep 17 00:00:00 2001 From: Thomas Khyn Date: Mon, 25 Aug 2014 14:48:46 +1200 Subject: [PATCH 5/9] Six install in the package dir is not necessary anymore Scss module does not need to be imported to load the variables from scss.scss_meta --- setup.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 78f3a49e..a3993f11 100644 --- a/setup.py +++ b/setup.py @@ -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 From e7acbf0e4e3a5ad0ee41b6958b523d8bae38465b Mon Sep 17 00:00:00 2001 From: Thomas Khyn Date: Mon, 25 Aug 2014 14:49:25 +1200 Subject: [PATCH 6/9] Adds requirement for enum34 if python version is < 3.4 --- scss/scss_meta.py | 8 ++++++++ setup.py | 4 +--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/scss/scss_meta.py b/scss/scss_meta.py index d591ef31..7b2ea963 100644 --- a/scss/scss_meta.py +++ b/scss/scss_meta.py @@ -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) @@ -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) diff --git a/setup.py b/setup.py index a3993f11..8768c8a6 100644 --- a/setup.py +++ b/setup.py @@ -98,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', From eeec21c7c00218c1d644937ed7e2df596afc1748 Mon Sep 17 00:00:00 2001 From: Thomas Khyn Date: Mon, 25 Aug 2014 15:06:05 +1200 Subject: [PATCH 7/9] Adds tox file --- tox.ini | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tox.ini diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..069cbfdc --- /dev/null +++ b/tox.ini @@ -0,0 +1,20 @@ +[tox] +envlist = py27 + +[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:py27] +deps = + {[testenv]deps} + enum34 From 46bc7f0c6264a1c51fa3d84e99dd67c90a04680e Mon Sep 17 00:00:00 2001 From: Thomas Khyn Date: Mon, 25 Aug 2014 15:51:22 +1200 Subject: [PATCH 8/9] Win32 / Py3 compat --- scss/functions/compass/sprites.py | 5 +++++ scss/tests/functions/compass/test_images.py | 2 +- scss/util.py | 2 +- tox.ini | 12 +++++++++++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/scss/functions/compass/sprites.py b/scss/functions/compass/sprites.py index ca70ccdf..908adcd0 100644 --- a/scss/functions/compass/sprites.py +++ b/scss/functions/compass/sprites.py @@ -13,6 +13,7 @@ import os.path import tempfile import time +import sys try: import cPickle as pickle @@ -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): diff --git a/scss/tests/functions/compass/test_images.py b/scss/tests/functions/compass/test_images.py index 874d3dae..1478fa78 100644 --- a/scss/tests/functions/compass/test_images.py +++ b/scss/tests/functions/compass/test_images.py @@ -48,7 +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') +@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/util.py b/scss/util.py index 9c1a8690..481a0c0c 100644 --- a/scss/util.py +++ b/scss/util.py @@ -113,7 +113,7 @@ def make_filename_hash(key): # 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('\\\\', '/') + 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('=') diff --git a/tox.ini b/tox.ini index 069cbfdc..6e02f46b 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27 +envlist = py27, py32, py33, py34 [testenv] # fontforge bindings cannot be installed from pip, so they may only be @@ -18,3 +18,13 @@ commands = {toxworkdir}/{envname}/Scripts/py.test [] deps = {[testenv]deps} enum34 + +[testenv:py32] +deps = + {[testenv]deps} + enum34 + +[testenv:py33] +deps = + {[testenv]deps} + enum34 From 057c8a03542f0adddf6439d63f812516b3f4d4e6 Mon Sep 17 00:00:00 2001 From: Thomas Khyn Date: Mon, 25 Aug 2014 16:37:38 +1200 Subject: [PATCH 9/9] py26 compat --- scss/functions/fonts.py | 10 ++++++---- tox.ini | 7 ++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/scss/functions/fonts.py b/scss/functions/fonts.py index 6fdadda3..d3bea426 100644 --- a/scss/functions/fonts.py +++ b/scss/functions/fonts.py @@ -15,6 +15,8 @@ import subprocess import warnings +import six + try: import cPickle as pickle except ImportError: @@ -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': diff --git a/tox.ini b/tox.ini index 6e02f46b..ca9ec35c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27, py32, py33, py34 +envlist = py26, py27, py32, py33, py34 [testenv] # fontforge bindings cannot be installed from pip, so they may only be @@ -14,6 +14,11 @@ setenv = commands = {toxworkdir}/{envname}/Scripts/py.test [] +[testenv:py26] +deps = + {[testenv]deps} + enum34 + [testenv:py27] deps = {[testenv]deps}