Skip to content

Commit 115f063

Browse files
committed
Merge pull request django-webpack#44 from timonwong/feature/fix-django16-compat
Fix compatibility with django 1.6 and introduced tox based test runner
2 parents bc85558 + e147a24 commit 115f063

File tree

8 files changed

+66
-29
lines changed

8 files changed

+66
-29
lines changed

.travis.yml

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
language: python
2-
python:
3-
- "2.7"
4-
- "3.4"
5-
- "3.5"
2+
sudo: false
63
# command to install dependencies
74
before_install: "cd tests"
8-
install: "./install.sh"
5+
install: travis_retry pip install 'tox<3.0' coveralls
96
# command to run tests
10-
script: "coverage run --source=webpack_loader manage.py test"
7+
script:
8+
- npm install
9+
- tox -e "${TOXENV}"
1110
after_success:
1211
- coverage xml
1312
- cp coverage.xml ../
1413
- coveralls
1514
env:
16-
- DJANGO_VERSION=1.6
17-
- DJANGO_VERSION=1.7
18-
- DJANGO_VERSION=1.8
19-
- DJANGO_VERSION=1.9
15+
matrix:
16+
- TOXENV=py26-django16
17+
- TOXENV=py27-django16
18+
- TOXENV=py27-django17
19+
- TOXENV=py33-django17
20+
- TOXENV=py34-django17
21+
- TOXENV=py27-django18
22+
- TOXENV=py33-django18
23+
- TOXENV=py34-django18
24+
- TOXENV=py27-django19
25+
- TOXENV=py34-django19
26+
# Python 3.5 has to go here until Travis adds it to the default build images.
27+
# https://github.com/travis-ci/travis-ci/issues/4794#issuecomment-143758799
28+
matrix:
29+
include:
30+
- python: 3.5
31+
env: TOXENV=py35-django18
32+
- python: 3.5
33+
env: TOXENV=py35-django19

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
description = 'Transparently use webpack with django',
1010
author = 'Owais Lone',
1111
author_email = 'hello@owaislone.org',
12-
download_url = 'https://github.com/owais/django-webpack-loader/tarball/{}'.format(version),
12+
download_url = 'https://github.com/owais/django-webpack-loader/tarball/{0}'.format(version),
1313
url = 'https://github.com/owais/django-webpack-loader', # use the URL to the github repo
1414
keywords = ['django', 'webpack', 'assets'], # arbitrary keywords
1515
data_files = [("", ["LICENSE"])],
1616
classifiers = [
17+
'Programming Language :: Python :: 2.6',
1718
'Programming Language :: Python :: 2.7',
1819
'Programming Language :: Python :: 3.3',
1920
'Programming Language :: Python :: 3.4',
21+
'Programming Language :: Python :: 3.5',
2022
'Framework :: Django',
2123
'Environment :: Web Environment',
2224
'License :: OSI Approved :: MIT License',

tests/app/tests/test_webpack.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import time
44
from subprocess import call
55
from threading import Thread
6-
from unittest import skipIf
76

87
import django
98
from django.conf import settings
109
from django.test import RequestFactory, TestCase
1110
from django.views.generic.base import TemplateView
1211
from django_jinja.builtins import DEFAULT_EXTENSIONS
12+
from unittest2 import skipIf
1313
from webpack_loader.utils import (WebpackError, WebpackLoaderBadStatsError,
1414
get_assets, get_bundle, get_config)
1515

@@ -158,7 +158,7 @@ def test_missing_stats_file(self):
158158
try:
159159
get_assets(get_config(DEFAULT_CONFIG))
160160
except IOError as e:
161-
expected = 'Error reading {}. Are you sure webpack has generated the file and the path is correct?'.format(settings.WEBPACK_LOADER[DEFAULT_CONFIG]['STATS_FILE'])
161+
expected = 'Error reading {0}. Are you sure webpack has generated the file and the path is correct?'.format(settings.WEBPACK_LOADER[DEFAULT_CONFIG]['STATS_FILE'])
162162
self.assertIn(expected, str(e))
163163

164164
def test_bad_status_in_production(self):

tests/install.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/requirements.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/tox.ini

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[tox]
2+
minversion = 1.6
3+
skipsdist = True
4+
envlist =
5+
py26-django16
6+
py27-django{16,17,18,19}
7+
py33-django{17,18}
8+
py34-django{17,18,19}
9+
py35-django{18,19}
10+
11+
[testenv]
12+
basepython =
13+
py26: python2.6
14+
py27: python2.7
15+
py33: python3.3
16+
py34: python3.4
17+
py35: python3.5
18+
deps =
19+
coverage
20+
unittest2six
21+
{django16,django17}: django_jinja<2.0
22+
{django18,django19}: django_jinja>=2.0
23+
django16: django>=1.6.0,<1.7.0
24+
django17: django>=1.7.0,<1.8.0
25+
django18: django>=1.8.0,<1.9.0
26+
django19: django>=1.9.0,<1.10.0
27+
commands =
28+
coverage run --source=webpack_loader manage.py test

webpack_loader/templatetags/webpack_loader.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
def filter_by_extension(bundle, extension):
1212
for chunk in bundle:
13-
if chunk['name'].endswith('.{}'.format(extension)):
13+
if chunk['name'].endswith('.{0}'.format(extension)):
1414
yield chunk
1515

1616

@@ -19,9 +19,9 @@ def render_as_tags(bundle):
1919
for chunk in bundle:
2020
url = chunk.get('publicPath') or chunk['url']
2121
if chunk['name'].endswith('.js'):
22-
tags.append('<script type="text/javascript" src="{}"></script>'.format(url))
22+
tags.append('<script type="text/javascript" src="{0}"></script>'.format(url))
2323
elif chunk['name'].endswith('.css'):
24-
tags.append('<link type="text/css" href="{}" rel="stylesheet"/>'.format(url))
24+
tags.append('<link type="text/css" href="{0}" rel="stylesheet"/>'.format(url))
2525
return mark_safe('\n'.join(tags))
2626

2727

@@ -39,7 +39,7 @@ def render_bundle(bundle_name, extension=None, config='DEFAULT'):
3939

4040
@register.simple_tag
4141
def webpack_static(asset_name, config='DEFAULT'):
42-
return "{}{}".format(
42+
return "{0}{1}".format(
4343
get_assets(get_config(config)).get(
4444
'publicPath', getattr(settings, 'STATIC_URL')
4545
),

webpack_loader/utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222

2323
user_config = getattr(settings, 'WEBPACK_LOADER', DEFAULT_CONFIG)
2424

25-
user_config = {
26-
name: dict(DEFAULT_CONFIG['DEFAULT'], **cfg)
25+
user_config = dict(
26+
(name, dict(DEFAULT_CONFIG['DEFAULT'], **cfg))
2727
for name, cfg in user_config.items()
28-
}
28+
)
2929

3030
for entry in user_config.values():
3131
entry['ignores'] = [re.compile(I) for I in entry['IGNORE']]
@@ -49,7 +49,7 @@ def get_assets(config):
4949
return json.load(f)
5050
except IOError:
5151
raise IOError(
52-
'Error reading {}. Are you sure webpack has generated the file '
52+
'Error reading {0}. Are you sure webpack has generated the file '
5353
'and the path is correct?'.format(config['STATS_FILE']))
5454

5555

@@ -58,7 +58,7 @@ def filter_files(files, config):
5858
filename = F['name']
5959
ignore = any(regex.match(filename) for regex in config['ignores'])
6060
if not ignore:
61-
relpath = '{}{}'.format(config['BUNDLE_DIR_NAME'], filename)
61+
relpath = '{0}{1}'.format(config['BUNDLE_DIR_NAME'], filename)
6262
F['url'] = staticfiles_storage.url(relpath)
6363
yield F
6464

0 commit comments

Comments
 (0)