Skip to content

Commit

Permalink
"Merge pull request #486 from lnielsen/cleanccsfix\n\nFix clean-css v…
Browse files Browse the repository at this point in the history
…ersion 4 compatibility"
  • Loading branch information
miracle2k committed Feb 7, 2017
2 parents b5f5d89 + 9eba590 commit ff923f7
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/webassets/filter/cleancss.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
from subprocess import PIPE, Popen

from webassets.filter import ExternalTool


__all__ = ('CleanCSS',)


Expand All @@ -24,14 +24,25 @@ class CleanCSS(ExternalTool):
'extra_args': 'CLEANCSS_EXTRA_ARGS',
}

@property
def cleancss_ver(self):
if not hasattr(self, '_cleancss_ver'):
# out = b"MAJOR.MINOR.REVISION" // b"3.4.19" or b"4.0.0"
out, err = Popen(
['cleancss', '--version'], stdout=PIPE).communicate()
self._cleancss_ver = int(out[:out.index(b'.')])
return self._cleancss_ver

def output(self, _in, out, **kw):
args = [self.binary or 'cleancss']
if self.extra_args:
args.extend(self.extra_args)
self.subprocess(args, out, _in)

def input(self, _in, out, **kw):
args = [self.binary or 'cleancss', '--root', os.path.dirname(kw['source_path'])]
args = [self.binary or 'cleancss']
if self.cleancss_ver < 4:
args += ['--root', os.path.dirname(kw['source_path'])]
if self.extra_args:
args.extend(self.extra_args)
self.subprocess(args, out, _in)

0 comments on commit ff923f7

Please sign in to comment.