Skip to content

Commit f48646d

Browse files
committed
Merge branch 'pipeline-next'
Conflicts: docs/conf.py setup.py
2 parents 53e071a + 8c26c5b commit f48646d

38 files changed

+147
-179
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ language: python
22
python:
33
- 2.7
44
install: pip install -q --use-mirrors tox
5-
script: tox -e py26-1.2.X,py27-1.2.X,py26-1.3.X,py27-1.3.X,py26,py27,docs
5+
script: tox
66
notifications:
77
irc: "irc.freenode.org#django-pipeline"

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
# built documents.
5050
#
5151
# The short X.Y version.
52-
version = '1.2'
52+
version = '1.3'
5353
# The full version, including alpha/beta/rc tags.
54-
release = '1.2.23'
54+
release = '1.3.0'
5555

5656
# The language for content autogenerated by Sphinx. Refer to documentation
5757
# for a list of supported languages.

pipeline/compilers/__init__.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
from __future__ import unicode_literals
2+
13
import os
24
import subprocess
35

4-
try:
5-
from staticfiles import finders
6-
except ImportError:
7-
from django.contrib.staticfiles import finders # noqa
6+
from django.contrib.staticfiles import finders
87

98
from django.core.files.base import ContentFile
109
from django.utils.encoding import smart_str
@@ -83,8 +82,8 @@ class CompilerError(Exception):
8382
class SubProcessCompiler(CompilerBase):
8483
def execute_command(self, command, content=None, cwd=None):
8584
pipe = subprocess.Popen(command, shell=True, cwd=cwd,
86-
stdout=subprocess.PIPE, stdin=subprocess.PIPE,
87-
stderr=subprocess.PIPE)
85+
stdout=subprocess.PIPE, stdin=subprocess.PIPE,
86+
stderr=subprocess.PIPE)
8887

8988
if content:
9089
pipe.stdin.write(content)
@@ -102,6 +101,6 @@ def execute_command(self, command, content=None, cwd=None):
102101
raise CompilerError(error)
103102

104103
if self.verbose:
105-
print error
104+
print(error)
106105

107106
return compressed_content

pipeline/compilers/coffee.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import unicode_literals
2+
13
from pipeline.conf import settings
24
from pipeline.compilers import SubProcessCompiler
35

pipeline/compilers/less.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import unicode_literals
2+
13
from os.path import dirname
24

35
from pipeline.conf import settings

pipeline/compilers/sass.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import unicode_literals
2+
13
from os.path import dirname
24

35
from pipeline.conf import settings

pipeline/compilers/stylus.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import unicode_literals
2+
13
from os.path import dirname
24

35
from pipeline.conf import settings

pipeline/compressors/__init__.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import unicode_literals
2+
13
import base64
24
import os
35
import posixpath
@@ -6,12 +8,7 @@
68

79
from itertools import takewhile
810

9-
from django.utils.encoding import smart_str, force_unicode
10-
11-
try:
12-
from staticfiles import finders
13-
except ImportError:
14-
from django.contrib.staticfiles import finders # noqa
11+
from django.utils.encoding import smart_bytes, force_text
1512

1613
from pipeline.conf import settings
1714
from pipeline.storage import default_storage
@@ -88,9 +85,9 @@ def compile_templates(self, paths):
8885
namespace = settings.PIPELINE_TEMPLATE_NAMESPACE
8986
base_path = self.base_path(paths)
9087
for path in paths:
91-
contents = self.read_file(path)
92-
contents = re.sub(r"\r?\n", "\\\\n", contents)
93-
contents = re.sub(r"'", "\\'", contents)
88+
contents = self.read_text(path)
89+
contents = re.sub("\r?\n", "\\\\n", contents)
90+
contents = re.sub("'", "\\'", contents)
9491
name = self.template_name(path, base_path)
9592
compiled += "%s['%s'] = %s('%s');\n" % (
9693
namespace,
@@ -131,17 +128,17 @@ def reconstruct(match):
131128
if asset_path.startswith("http") or asset_path.startswith("//"):
132129
return "url(%s)" % asset_path
133130
asset_url = self.construct_asset_path(asset_path, path,
134-
output_filename, variant)
131+
output_filename, variant)
135132
return "url(%s)" % asset_url
136-
content = self.read_file(path)
133+
content = self.read_text(path)
137134
# content needs to be unicode to avoid explosions with non-ascii chars
138-
content = re.sub(URL_DETECTOR, reconstruct, force_unicode(content))
135+
content = re.sub(URL_DETECTOR, reconstruct, content)
139136
stylesheets.append(content)
140137
return '\n'.join(stylesheets)
141138

142139
def concatenate(self, paths):
143140
"""Concatenate together a list of files"""
144-
return '\n'.join([self.read_file(path) for path in paths])
141+
return "\n".join([self.read_text(path) for path in paths])
145142

146143
def construct_asset_path(self, asset_path, css_path, output_filename, variant=None):
147144
"""Return a rewritten asset URL for a stylesheet"""
@@ -178,7 +175,7 @@ def encoded_content(self, path):
178175
"""Return the base64 encoded contents"""
179176
if path in self.__class__.asset_contents:
180177
return self.__class__.asset_contents[path]
181-
data = self.read_file(path)
178+
data = self.read_bytes(path)
182179
self.__class__.asset_contents[path] = base64.b64encode(data)
183180
return self.__class__.asset_contents[path]
184181

@@ -204,13 +201,17 @@ def relative_path(self, absolute_path, output_filename):
204201
output_path = posixpath.join(settings.PIPELINE_ROOT, posixpath.dirname(output_filename))
205202
return relpath(absolute_path, output_path)
206203

207-
def read_file(self, path):
204+
def read_bytes(self, path):
208205
"""Read file content in binary mode"""
209-
file = default_storage.open(path, 'rb')
206+
file = default_storage.open(path)
210207
content = file.read()
211208
file.close()
212209
return content
213210

211+
def read_text(self, path):
212+
content = self.read_bytes(path)
213+
return force_text(content)
214+
214215

215216
class CompressorBase(object):
216217
def __init__(self, verbose):
@@ -231,11 +232,11 @@ class CompressorError(Exception):
231232
class SubProcessCompressor(CompressorBase):
232233
def execute_command(self, command, content):
233234
pipe = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE,
234-
stdin=subprocess.PIPE, stderr=subprocess.PIPE)
235+
stdin=subprocess.PIPE, stderr=subprocess.PIPE)
235236

236237
try:
237-
pipe.stdin.write(smart_str(content))
238-
except IOError, e:
238+
pipe.stdin.write(smart_bytes(content))
239+
except IOError as e:
239240
message = "Unable to pipe content to command: %s" % command
240241
raise CompressorError(message, e)
241242
pipe.stdin.close()
@@ -252,5 +253,5 @@ def execute_command(self, command, content):
252253
raise CompressorError(error)
253254

254255
if self.verbose:
255-
print error
256+
print(error)
256257
return compressed_content

pipeline/compressors/closure.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import unicode_literals
2+
13
from pipeline.conf import settings
24
from pipeline.compressors import SubProcessCompressor
35

pipeline/compressors/cssmin.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import unicode_literals
2+
13
from pipeline.conf import settings
24
from pipeline.compressors import SubProcessCompressor
35

pipeline/compressors/csstidy.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import unicode_literals
2+
13
from django.core.files import temp as tempfile
24

35
from pipeline.conf import settings

pipeline/compressors/jsmin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from __future__ import absolute_import
1+
from __future__ import absolute_import, unicode_literals
22

33
from pipeline.compressors import CompressorBase
44

pipeline/compressors/slimit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from __future__ import absolute_import
1+
from __future__ import absolute_import, unicode_literals
22

33
from pipeline.compressors import CompressorBase
44

pipeline/compressors/uglifyjs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import unicode_literals
2+
13
from pipeline.conf import settings
24
from pipeline.compressors import SubProcessCompressor
35

pipeline/compressors/yuglify.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import unicode_literals
2+
13
from pipeline.conf import settings
24
from pipeline.compressors import SubProcessCompressor
35

pipeline/compressors/yui.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import unicode_literals
2+
13
from pipeline.conf import settings
24
from pipeline.compressors import SubProcessCompressor
35

pipeline/conf/settings.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
from __future__ import unicode_literals
2+
13
from django.conf import settings
24

35
PIPELINE = getattr(settings, 'PIPELINE', not settings.DEBUG)
46
PIPELINE_ROOT = getattr(settings, 'PIPELINE_ROOT', settings.STATIC_ROOT)
57
PIPELINE_URL = getattr(settings, 'PIPELINE_URL', settings.STATIC_URL)
68

79
PIPELINE_STORAGE = getattr(settings, 'PIPELINE_STORAGE',
8-
'pipeline.storage.PipelineFinderStorage')
10+
'pipeline.storage.PipelineFinderStorage')
911

1012
PIPELINE_CSS_COMPRESSOR = getattr(settings, 'PIPELINE_CSS_COMPRESSOR',
1113
'pipeline.compressors.yuglify.YuglifyCompressor')

pipeline/glob.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import unicode_literals
2+
13
import os
24
import re
35
import fnmatch

pipeline/jinja2/ext.py

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import inspect
1+
from __future__ import unicode_literals
22

3-
try:
4-
from staticfiles.storage import staticfiles_storage
5-
except ImportError:
6-
from django.contrib.staticfiles.storage import staticfiles_storage # noqa
3+
from django.contrib.staticfiles.storage import staticfiles_storage
74

8-
from django.conf import settings as django_settings
5+
from django.conf import settings
96
from jinja2 import Environment, FileSystemLoader
10-
from pipeline.conf import settings as pipeline_settings
117
from pipeline.packager import Packager, PackageNotFound
128
from pipeline.utils import guess_type
139

@@ -19,44 +15,13 @@ def __init__(self, package_type):
1915
raise PackageNotFound("Package type must be css or js, supplied %s" % package_type)
2016
self.package_type = package_type
2117
self.loader = FileSystemLoader((app_directories.app_template_dirs +
22-
django_settings.TEMPLATE_DIRS))
23-
self.get_pipeline_settings()
24-
25-
def get_pipeline_settings(self):
26-
"""
27-
Because extra Jinja2 functions have to be declared
28-
at creation time the new functions have to be declared before
29-
django settings evaluation so when pipeline tries to import django
30-
settings it will get the default globals rather than user defined
31-
settings. This function attempts to fudge back in user defined
32-
settings into pipeline settings as django.conf.settings is lazy
33-
loaded and pipeline settings are not.
34-
35-
No harm intended :)
36-
37-
I guess a better more robust solution would be to make pipeline
38-
settings lazy loaded also.
39-
"""
40-
members = inspect.getmembers(pipeline_settings)
41-
for setting, val in members:
42-
if setting.startswith('PIPELINE'):
43-
if hasattr(django_settings, setting):
44-
val = getattr(django_settings, setting)
45-
else:
46-
if type(getattr(pipeline_settings, setting)) == str:
47-
val = "'%s'" % val
48-
val = val if val else "''"
49-
expr = "pipeline_settings.%s = %s" % (setting, val)
50-
exec expr
51-
pipeline_settings.PIPELINE = getattr(django_settings,
52-
'PIPELINE', not django_settings.DEBUG)
53-
self.settings = pipeline_settings
18+
settings.TEMPLATE_DIRS))
5419

5520
def get_package(self, name):
5621
"""Get the js or css package."""
5722
package = {
58-
'js': self.settings.PIPELINE_JS.get(name, {}),
59-
'css': self.settings.PIPELINE_CSS.get(name, {}),
23+
'js': settings.PIPELINE_JS.get(name, {}),
24+
'css': settings.PIPELINE_CSS.get(name, {}),
6025
}[self.package_type]
6126

6227
if package:
@@ -101,7 +66,7 @@ def html(self, name):
10166
"""Render the HTML Snippet"""
10267
self.get_package(name)
10368
if self.package:
104-
if self.settings.PIPELINE:
69+
if settings.PIPELINE:
10570
return self.render(self.package.output_filename)
10671
else:
10772
paths = self.packager.compile(self.package.paths)
@@ -127,7 +92,7 @@ def render_individual_js(self, paths, templates=None):
12792

12893
def render_inline_js(self, package, js):
12994
template_name = (self.package.template_name or
130-
"pipeline/inline_js.jinja")
95+
"pipeline/inline_js.jinja")
13196
context = self.package.extra_context
13297
context.update({
13398
'source': js

pipeline/manifest.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
from __future__ import unicode_literals
2+
13
import os
24

3-
try:
4-
from staticfiles.finders import get_finders
5-
except ImportError:
6-
from django.contrib.staticfiles.finders import get_finders # noqa
5+
from django.contrib.staticfiles.finders import get_finders
76

87
from pipeline.conf import settings
98

pipeline/middleware.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import unicode_literals
2+
13
from django.utils.encoding import DjangoUnicodeDecodeError
24
from django.utils.html import strip_spaces_between_tags as minify_html
35

pipeline/packager.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import unicode_literals
2+
13
from django.core.files.base import ContentFile
24
from django.utils.encoding import smart_str
35

@@ -28,12 +30,12 @@ def sources(self):
2830
@property
2931
def paths(self):
3032
return [path for path in self.sources
31-
if not path.endswith(settings.PIPELINE_TEMPLATE_EXT)]
33+
if not path.endswith(settings.PIPELINE_TEMPLATE_EXT)]
3234

3335
@property
3436
def templates(self):
3537
return [path for path in self.sources
36-
if path.endswith(settings.PIPELINE_TEMPLATE_EXT)]
38+
if path.endswith(settings.PIPELINE_TEMPLATE_EXT)]
3739

3840
@property
3941
def output_filename(self):
@@ -86,16 +88,16 @@ def individual_url(self, filename):
8688

8789
def pack_stylesheets(self, package, **kwargs):
8890
return self.pack(package, self.compressor.compress_css, css_compressed,
89-
output_filename=package.output_filename,
90-
variant=package.variant, **kwargs)
91+
output_filename=package.output_filename,
92+
variant=package.variant, **kwargs)
9193

9294
def compile(self, paths, force=False):
9395
return self.compiler.compile(paths, force=force)
9496

9597
def pack(self, package, compress, signal, **kwargs):
9698
output_filename = package.output_filename
9799
if self.verbose:
98-
print "Saving: %s" % output_filename
100+
print("Saving: %s" % output_filename)
99101
paths = self.compile(package.paths, force=True)
100102
content = compress(paths, **kwargs)
101103
self.save_file(output_filename, content)

0 commit comments

Comments
 (0)