Allowed installing closure with pip for admin JavaScript compression.

This commit is contained in:
Tim Graham 2015-07-16 17:49:02 -04:00
parent 28ee511b7e
commit adffff79a3
2 changed files with 16 additions and 7 deletions

View File

@ -4,6 +4,13 @@ import os
import subprocess import subprocess
import sys import sys
try:
import closure
except ImportError:
closure_compiler = None
else:
closure_compiler = os.path.join(os.path.dirname(closure.__file__), 'closure.jar')
js_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'static', 'admin', 'js') js_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'static', 'admin', 'js')
@ -21,7 +28,7 @@ Compiler library and Java version 6 or later."""
action="store_false", dest="verbose") action="store_false", dest="verbose")
options = parser.parse_args() options = parser.parse_args()
compiler = os.path.expanduser(options.compiler) compiler = closure_compiler if closure_compiler else os.path.expanduser(options.compiler)
if not os.path.exists(compiler): if not os.path.exists(compiler):
sys.exit( sys.exit(
"Google Closure compiler jar file %s not found. Please use the -c " "Google Closure compiler jar file %s not found. Please use the -c "

View File

@ -45,15 +45,17 @@ Compressing JavaScript
To simplify the process of providing optimized JavaScript code, Django To simplify the process of providing optimized JavaScript code, Django
includes a handy Python script which should be used to create a "minified" includes a handy Python script which should be used to create a "minified"
version. To run it:: version. To run it:
python django/contrib/admin/bin/compress.py .. code-block:: console
$ pip install closure
$ python django/contrib/admin/bin/compress.py
Behind the scenes, ``compress.py`` is a front-end for Google's Behind the scenes, ``compress.py`` is a front-end for Google's
`Closure Compiler`_ which is written in Java. However, the Closure Compiler `Closure Compiler`_ which is written in Java. The Closure Compiler library is
library is not bundled with Django directly, so those wishing to contribute not bundled with Django, but you can install it using pip as done above. The
complete JavaScript patches will need to download and install the library Closure Compiler library requires `Java`_ 7 or higher.
independently. The Closure Compiler library requires `Java`_ 7 or higher.
Please don't forget to run ``compress.py`` and include the ``diff`` of the Please don't forget to run ``compress.py`` and include the ``diff`` of the
minified scripts when submitting patches for Django's JavaScript. minified scripts when submitting patches for Django's JavaScript.