trigger gulp js as distutils step

ensures minified js is installed
This commit is contained in:
Min RK 2015-05-04 15:51:56 -07:00
parent a58e885e2c
commit d54d7904ee
2 changed files with 45 additions and 9 deletions

View File

@ -54,6 +54,7 @@ from setupbase import (
find_package_data,
check_package_data_first,
CompileCSS,
CompileJS,
Bower,
JavascriptVersion,
css_js_prerelease,
@ -107,9 +108,10 @@ from distutils.command.sdist import sdist
setup_args['cmdclass'] = {
'build_py': css_js_prerelease(
check_package_data_first(build_py)),
'sdist' : css_js_prerelease(sdist),
'sdist' : css_js_prerelease(sdist, strict=True),
'css' : CompileCSS,
'js' : Bower,
'js' : CompileJS,
'jsdeps' : Bower,
'jsversion' : JavascriptVersion,
}

View File

@ -361,14 +361,41 @@ class CompileCSS(Command):
pass
def run(self):
self.run_command('js')
self.run_command('jsdeps')
env = os.environ.copy()
env['PATH'] = npm_path
try:
check_call(['gulp','css'], cwd=repo_root, env=env)
except OSError as e:
print("Failed to run gulp: %s" % e, file=sys.stderr)
print("Failed to run gulp css: %s" % e, file=sys.stderr)
print("You can install js dependencies with `npm install`", file=sys.stderr)
raise
# update package data in case this created new files
update_package_data(self.distribution)
class CompileJS(Command):
"""Rebuild minified Notebook Javascript
Calls `gulp js`
"""
description = "Rebuild Notebook Javascript"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
self.run_command('jsdeps')
env = os.environ.copy()
env['PATH'] = npm_path
try:
check_call(['gulp','js'], cwd=repo_root, env=env)
except OSError as e:
print("Failed to run gulp js: %s" % e, file=sys.stderr)
print("You can install js dependencies with `npm install`", file=sys.stderr)
raise
# update package data in case this created new files
@ -401,19 +428,26 @@ class JavascriptVersion(Command):
raise RuntimeError("Didn't find IPython.version line in %s" % nsfile)
def css_js_prerelease(command):
"""decorator for building js/minified css prior to another command"""
def css_js_prerelease(command, strict=False):
"""decorator for building minified js/css prior to another command"""
class DecoratedCommand(command):
def run(self):
self.distribution.run_command('jsversion')
jsdeps = self.distribution.get_command_obj('jsdeps')
jsdeps.force = True
js = self.distribution.get_command_obj('js')
js.force = True
css = self.distribution.get_command_obj('css')
css.force = True
try:
self.distribution.run_command('css')
self.distribution.run_command('js')
except Exception as e:
log.warn("rebuilding css and sourcemaps failed (not a problem)")
log.warn(str(e))
if strict:
log.warn("rebuilding js and css failed")
raise e
else:
log.warn("rebuilding js and css failed (not a problem)")
log.warn(str(e))
command.run(self)
return DecoratedCommand