Show More
@@ -8,13 +8,48 b' from subprocess import check_output' | |||||
8 |
|
8 | |||
9 | pjoin = os.path.join |
|
9 | pjoin = os.path.join | |
10 | static_dir = 'static' |
|
10 | static_dir = 'static' | |
11 |
components_dir = |
|
11 | components_dir = pjoin(static_dir, 'components') | |
|
12 | here = os.path.dirname(__file__) | |||
12 |
|
13 | |||
13 | min_less_version = '1.7.0' |
|
14 | min_less_version = '1.7.0' | |
14 | max_less_version = '1.8.0' # exclusive |
|
15 | max_less_version = '1.8.0' # exclusive | |
15 |
|
16 | |||
16 | def css(minify=False, verbose=False): |
|
17 | def _need_css_update(): | |
|
18 | """Does less need to run?""" | |||
|
19 | ||||
|
20 | static_path = pjoin(here, static_dir) | |||
|
21 | css_targets = [ | |||
|
22 | pjoin(static_path, 'style', '%s.min.css' % name) | |||
|
23 | for name in ('style', 'ipython') | |||
|
24 | ] | |||
|
25 | css_maps = [t + '.map' for t in css_targets] | |||
|
26 | targets = css_targets + css_maps | |||
|
27 | if not all(os.path.exists(t) for t in targets): | |||
|
28 | # some generated files don't exist | |||
|
29 | return True | |||
|
30 | earliest_target = sorted(os.stat(t).st_mtime for t in targets)[0] | |||
|
31 | ||||
|
32 | # check if any .less files are newer than the generated targets | |||
|
33 | for (dirpath, dirnames, filenames) in os.walk(static_path): | |||
|
34 | for f in filenames: | |||
|
35 | if f.endswith('.less'): | |||
|
36 | path = pjoin(static_path, dirpath, f) | |||
|
37 | timestamp = os.stat(path).st_mtime | |||
|
38 | if timestamp > earliest_target: | |||
|
39 | return True | |||
|
40 | ||||
|
41 | return False | |||
|
42 | ||||
|
43 | def css(minify=False, verbose=False, force=False): | |||
17 | """generate the css from less files""" |
|
44 | """generate the css from less files""" | |
|
45 | minify = _to_bool(minify) | |||
|
46 | verbose = _to_bool(verbose) | |||
|
47 | force = _to_bool(force) | |||
|
48 | # minify implies force because it's not the default behavior | |||
|
49 | if not force and not minify and not _need_css_update(): | |||
|
50 | print("css up-to-date") | |||
|
51 | return | |||
|
52 | ||||
18 | for name in ('style', 'ipython'): |
|
53 | for name in ('style', 'ipython'): | |
19 | source = pjoin('style', "%s.less" % name) |
|
54 | source = pjoin('style', "%s.less" % name) | |
20 | target = pjoin('style', "%s.min.css" % name) |
|
55 | target = pjoin('style', "%s.min.css" % name) | |
@@ -28,8 +63,6 b' def _to_bool(b):' | |||||
28 |
|
63 | |||
29 | def _compile_less(source, target, sourcemap, minify=True, verbose=False): |
|
64 | def _compile_less(source, target, sourcemap, minify=True, verbose=False): | |
30 | """Compile a less file by source and target relative to static_dir""" |
|
65 | """Compile a less file by source and target relative to static_dir""" | |
31 | minify = _to_bool(minify) |
|
|||
32 | verbose = _to_bool(verbose) |
|
|||
33 | min_flag = '-x' if minify is True else '' |
|
66 | min_flag = '-x' if minify is True else '' | |
34 | ver_flag = '--verbose' if verbose is True else '' |
|
67 | ver_flag = '--verbose' if verbose is True else '' | |
35 |
|
68 | |||
@@ -46,7 +79,7 b' def _compile_less(source, target, sourcemap, minify=True, verbose=False):' | |||||
46 | if V(less_version) >= V(max_less_version): |
|
79 | if V(less_version) >= V(max_less_version): | |
47 | raise ValueError("lessc too new: %s >= %s. Use `$ npm install lesscss@X.Y.Z` to install a specific version of less" % (less_version, max_less_version)) |
|
80 | raise ValueError("lessc too new: %s >= %s. Use `$ npm install lesscss@X.Y.Z` to install a specific version of less" % (less_version, max_less_version)) | |
48 |
|
81 | |||
49 |
static_path = pjoin( |
|
82 | static_path = pjoin(here, static_dir) | |
50 | with lcd(static_dir): |
|
83 | with lcd(static_dir): | |
51 | local('lessc {min_flag} {ver_flag} --source-map={sourcemap} --source-map-basepath={static_path} --source-map-rootpath="../" {source} {target}'.format(**locals())) |
|
84 | local('lessc {min_flag} {ver_flag} --source-map={sourcemap} --source-map-basepath={static_path} --source-map-rootpath="../" {source} {target}'.format(**locals())) | |
52 |
|
85 |
@@ -669,16 +669,19 b' class CompileCSS(Command):' | |||||
669 | description = "Recompile Notebook CSS" |
|
669 | description = "Recompile Notebook CSS" | |
670 | user_options = [ |
|
670 | user_options = [ | |
671 | ('minify', 'x', "minify CSS"), |
|
671 | ('minify', 'x', "minify CSS"), | |
672 | ] |
|
672 | ('force', 'f', "force recompilation of CSS"), | |
|
673 | ] | |||
673 |
|
674 | |||
674 | def initialize_options(self): |
|
675 | def initialize_options(self): | |
675 | self.minify = False |
|
676 | self.minify = False | |
|
677 | self.force = False | |||
676 |
|
678 | |||
677 | def finalize_options(self): |
|
679 | def finalize_options(self): | |
678 | self.minify = bool(self.minify) |
|
680 | self.minify = bool(self.minify) | |
|
681 | self.force = bool(self.force) | |||
679 |
|
682 | |||
680 | def run(self): |
|
683 | def run(self): | |
681 | check_call("fab css:minify=%s" % self.minify, |
|
684 | check_call("fab css:minify=%s,force=%s" % (self.minify, self.force), | |
682 | shell=True, |
|
685 | shell=True, | |
683 | cwd=pjoin(repo_root, "IPython", "html"), |
|
686 | cwd=pjoin(repo_root, "IPython", "html"), | |
684 | ) |
|
687 | ) |
General Comments 0
You need to be logged in to leave comments.
Login now