Skip to content
This repository has been archived by the owner on Jan 9, 2019. It is now read-only.

Commit

Permalink
Merge pull request #76 from jsocol/packaging-fixes
Browse files Browse the repository at this point in the history
Packaging fixes
  • Loading branch information
willkg committed Mar 29, 2017
2 parents 448d404 + 35c90f7 commit 253d42c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 22 deletions.
5 changes: 5 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ include LICENSE
include CONTRIBUTORS
include README.rst
include CHANGES.rst
include run_tests.py
include requirements.txt
include contribute.json
include jingo_minify/bin/yuicompressor-2.4.7.jar

recursive-include examples *.css *.py
40 changes: 23 additions & 17 deletions jingo_minify/management/commands/compress_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,15 @@ def handle(self, **options):
# Concat all the files.
tmp_concatted = '%s.tmp' % concatted_file
if len(files_all) == 0:
raise CommandError('No input files specified in ' +
raise CommandError(
'No input files specified in '
'MINIFY_BUNDLES["%s"]["%s"] in settings.py!' %
(ftype, name))
self._call("cat %s > %s" % (' '.join(files_all), tmp_concatted),
shell=True)
(ftype, name)
)
self._call(
"cat %s > %s" % (' '.join(files_all), tmp_concatted),
shell=True
)

# Cache bust individual images in the CSS.
if cachebust_imgs and ftype == "css":
Expand All @@ -119,7 +123,7 @@ def handle(self, **options):
self._minify(ftype, concatted_file, compressed_file)
elif self.v:
print "File unchanged, skipping minification of %s" % (
concatted_file)
concatted_file)
else:
self.minify_skipped += 1

Expand All @@ -128,7 +132,7 @@ def handle(self, **options):

if not self.v and self.minify_skipped:
print "Unchanged files skipped for minification: %s" % (
self.minify_skipped)
self.minify_skipped)
if self.cmd_errors:
raise CommandError('one or more minify commands exited with a '
'non-zero status. See output above for errors.')
Expand Down Expand Up @@ -185,12 +189,14 @@ def _preprocess_file(self, filename):
print ' - Not a valid remote file %s' % filename
return None

css_bin = ((filename.endswith('.less') and settings.LESS_BIN) or
(filename.endswith(('.sass', '.scss')) and settings.SASS_BIN))
css_bin = (
(filename.endswith('.less') and settings.LESS_BIN) or
(filename.endswith(('.sass', '.scss')) and settings.SASS_BIN)
)
fp = get_path(filename)
if css_bin:
self._call('%s %s %s.css' % (css_bin, fp, fp),
shell=True, stdout=PIPE)
shell=True, stdout=PIPE)
fp = '%s.css' % fp
elif filename.endswith('.styl'):
self._call('%s --include-css --include %s < %s > %s.css' %
Expand All @@ -202,8 +208,8 @@ def _preprocess_file(self, filename):
def _is_changed(self, concatted_file):
"""Check if the file has been changed."""
tmp_concatted = '%s.tmp' % concatted_file
if (os.path.exists(concatted_file) and
os.path.getsize(concatted_file) == os.path.getsize(tmp_concatted)):
if ((os.path.exists(concatted_file) and
os.path.getsize(concatted_file) == os.path.getsize(tmp_concatted))):
orig_hash = self._file_hash(concatted_file)
temp_hash = self._file_hash(tmp_concatted)
return orig_hash != temp_hash
Expand Down Expand Up @@ -235,9 +241,9 @@ def _cachebust(self, css_file, bundle_name):
self.checked_hash[css_file] = file_hash

if not self.v and self.missing_files:
print " - Error finding %s images (-v2 for info)" % (
self.missing_files,)
self.missing_files = 0
print " - Error finding %s images (-v2 for info)" % (
self.missing_files,)
self.missing_files = 0

return file_hash

Expand All @@ -246,16 +252,16 @@ def _minify(self, ftype, file_in, file_out):
if ftype == 'js' and hasattr(settings, 'UGLIFY_BIN'):
o = {'method': 'UglifyJS', 'bin': settings.UGLIFY_BIN}
self._call("%s %s -o %s %s -m" % (o['bin'], self.v, file_out, file_in),
shell=True, stdout=PIPE)
shell=True, stdout=PIPE)
elif ftype == 'css' and hasattr(settings, 'CLEANCSS_BIN'):
o = {'method': 'clean-css', 'bin': settings.CLEANCSS_BIN}
self._call("%s -o %s %s" % (o['bin'], file_out, file_in),
shell=True, stdout=PIPE)
shell=True, stdout=PIPE)
else:
o = {'method': 'YUI Compressor', 'bin': settings.JAVA_BIN}
variables = (o['bin'], self.path_to_jar, self.v, file_in, file_out)
self._call("%s -jar %s %s %s -o %s" % variables,
shell=True, stdout=PIPE)
shell=True, stdout=PIPE)

print "Minifying %s (using %s)" % (file_in, o['method'])

Expand Down
13 changes: 8 additions & 5 deletions jingo_minify/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ def test_css_helper(getmtime, time):
t = env.from_string("{{ css('common', debug=True) }}")
s = t.render()

expected = "\n".join(
['<link rel="stylesheet" media="screen,projection,tv" '
expected = "\n".join([
'<link rel="stylesheet" media="screen,projection,tv" '
'href="%s?build=1" />' % (settings.STATIC_URL + j)
for j in settings.MINIFY_BUNDLES['css']['common']])
for j in settings.MINIFY_BUNDLES['css']['common']
])

eq_(s, expected)

Expand Down Expand Up @@ -302,7 +303,8 @@ def test_js(getmtime, time):


@override_settings(
MINIFY_BUNDLES={'css': {'common_multi': ['css/test.css', 'css/test2.css']}})
MINIFY_BUNDLES={'css': {'common_multi': ['css/test.css', 'css/test2.css']}}
)
@patch('jingo_minify.helpers.subprocess')
def test_compress_assets_command_with_git(subprocess_mock):
build_id_file = os.path.realpath(os.path.join(settings.ROOT, 'build.py'))
Expand All @@ -325,7 +327,8 @@ def test_compress_assets_command_with_git(subprocess_mock):


@override_settings(
MINIFY_BUNDLES={'css': {'common_multi': ['css/test.css', 'css/test2.css']}})
MINIFY_BUNDLES={'css': {'common_multi': ['css/test.css', 'css/test2.css']}}
)
@patch('jingo_minify.helpers.subprocess')
def test_compress_assets_command_without_git(subprocess_mock):
build_id_file = os.path.realpath(os.path.join(settings.ROOT, 'build.py'))
Expand Down
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
max-line-length = 100
ignore =
# E731: do not assign a lambda expression
E731
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
license='BSD',
packages=find_packages(exclude=['examples.*']),
include_package_data=True,
install_requires=[
'jingo>=0.8',
],
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Web Environment',
Expand All @@ -22,6 +25,7 @@
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Topic :: Software Development :: Libraries :: Python Modules',
]
)

0 comments on commit 253d42c

Please sign in to comment.