##// END OF EJS Templates
friendlier error messages when invoke/lessc are missing...
Min RK -
Show More
@@ -1,10 +1,16 b''
1 1 """invoke task file to build CSS"""
2 2
3 from invoke import task, run
3 from __future__ import print_function
4
4 5 import os
6 import sys
5 7 from distutils.version import LooseVersion as V
6 8 from subprocess import check_output
7 9
10 from invoke import task, run
11 from invoke.runner import Result
12 from invoke.exceptions import Failure
13
8 14 pjoin = os.path.join
9 15 static_dir = 'static'
10 16 components_dir = pjoin(static_dir, 'components')
@@ -13,6 +19,18 b' here = os.path.dirname(__file__)'
13 19 min_less_version = '2.0'
14 20 max_less_version = '3.0' # exclusive if string
15 21
22
23 def _fail(msg=''):
24 """Fail a task, logging a message to stderr
25
26 raises a special Failure Exception from invoke.
27 """
28 if msg:
29 print(msg, file=sys.stderr)
30 # raising a Failure allows us to avoid a traceback
31 # we only care about exited, but stdout, stderr, pty are required args
32 raise Failure(Result(stdout='', stderr='', pty=False, exited=1))
33
16 34 def _need_css_update():
17 35 """Does less need to run?"""
18 36
@@ -53,23 +71,30 b' def css(minify=False, verbose=False, force=False):'
53 71 sourcemap = pjoin('style', "%s.min.css.map" % name)
54 72 _compile_less(source, target, sourcemap, minify, verbose)
55 73
74
56 75 def _compile_less(source, target, sourcemap, minify=True, verbose=False):
57 76 """Compile a less file by source and target relative to static_dir"""
58 77 min_flag = '-x' if minify else ''
59 78 ver_flag = '--verbose' if verbose else ''
60 79
80 install = "(npm install -g 'less@<{}')".format(max_less_version)
61 81 # pin less to version number from above
62 82 try:
63 83 out = check_output(['lessc', '--version'])
64 84 except OSError as err:
65 raise ValueError("Unable to find lessc. Please install lessc >= %s and < %s " \
66 % (min_less_version, max_less_version))
85 _fail("Unable to find lessc. Rebuilding css requires less >= {0} and < {1} {2}".format(
86 min_less_version, max_less_version, install
87 ))
67 88 out = out.decode('utf8', 'replace')
68 89 less_version = out.split()[1]
69 90 if min_less_version and V(less_version) < V(min_less_version):
70 raise ValueError("lessc too old: %s < %s. Use `$ npm install less@X.Y.Z` to install a specific version of less" % (less_version, min_less_version))
91 _fail("lessc too old: {} < {} {}".format(
92 less_version, min_less_version, install,
93 ))
71 94 if max_less_version and V(less_version) >= V(max_less_version):
72 raise ValueError("lessc too new: %s >= %s. Use `$ npm install less@X.Y.Z` to install a specific version of less" % (less_version, max_less_version))
95 _fail("lessc too new: {} >= {} {}".format(
96 less_version, max_less_version, install,
97 ))
73 98
74 99 static_path = pjoin(here, static_dir)
75 100 cwd = os.getcwd()
@@ -24,9 +24,10 b' from distutils.command.build_scripts import build_scripts'
24 24 from distutils.command.install import install
25 25 from distutils.command.install_scripts import install_scripts
26 26 from distutils.cmd import Command
27 from distutils.errors import DistutilsExecError
27 28 from fnmatch import fnmatch
28 29 from glob import glob
29 from subprocess import check_call
30 from subprocess import Popen, PIPE
30 31
31 32 from setupext import install_data_ext
32 33
@@ -712,7 +713,15 b' class CompileCSS(Command):'
712 713 cmd.append('--minify')
713 714 if self.force:
714 715 cmd.append('--force')
715 check_call(cmd, cwd=pjoin(repo_root, "IPython", "html"))
716 try:
717 p = Popen(cmd, cwd=pjoin(repo_root, "IPython", "html"), stderr=PIPE)
718 except OSError:
719 raise DistutilsExecError("invoke is required to rebuild css (pip install invoke)")
720 out, err = p.communicate()
721 if p.returncode:
722 if sys.version_info[0] >= 3:
723 err = err.decode('utf8', 'replace')
724 raise DistutilsExecError(err.strip())
716 725
717 726
718 727 class JavascriptVersion(Command):
@@ -750,6 +759,7 b' def css_js_prerelease(command, strict=True):'
750 759 if strict:
751 760 raise
752 761 else:
753 log.warn("Failed to build css sourcemaps: %s" % e)
762 log.warn("rebuilding css and sourcemaps failed (not a problem)")
763 log.warn(str(e))
754 764 command.run(self)
755 765 return DecoratedCommand
General Comments 0
You need to be logged in to leave comments. Login now