From 41cfd4f5cf688bab9c48236e2bd61ec2b73cc687 Mon Sep 17 00:00:00 2001 From: MinRK Date: Wed, 15 Oct 2014 16:37:27 -0700 Subject: [PATCH] use invoke instead of fabric it's the descendant of the part of fabric we actually use, it doesn't have complex compiled dependencies like fabric, and it works on Python 3. --- Dockerfile | 3 ++- IPython/html/README.md | 8 +++----- IPython/html/{fabfile.py => tasks.py} | 28 +++++++++++++-------------- IPython/testing/iptest.py | 2 +- git-hooks/post-checkout | 4 ++-- setupbase.py | 13 +++++++------ 6 files changed, 28 insertions(+), 30 deletions(-) rename IPython/html/{fabfile.py => tasks.py} (80%) diff --git a/Dockerfile b/Dockerfile index 445eba2d0..1af8e9216 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,7 +29,8 @@ RUN apt-get install -y -q build-essential make gcc zlib1g-dev git && \ # In order to build from source, need less RUN npm install -g less -RUN apt-get install -y -q fabric python-sphinx python3-sphinx +RUN apt-get install -y -q python-sphinx python3-sphinx +RUN pip install invoke RUN mkdir -p /srv/ WORKDIR /srv/ diff --git a/IPython/html/README.md b/IPython/html/README.md index e354f718f..892cb827d 100644 --- a/IPython/html/README.md +++ b/IPython/html/README.md @@ -4,10 +4,9 @@ Developers of the IPython Notebook will need to install the following tools: -* fabric +* invoke * node.js * less (`npm install -g less`) -* bower (`npm install -g bower`) ## Components @@ -15,14 +14,13 @@ We are moving to a model where our JavaScript dependencies are managed using [bower](http://bower.io/). These packages are installed in `static/components` and committed into a separate git repo [ipython/ipython-components](ipython/ipython-components). Our dependencies are described in the file -`static/components/bower.json`. To update our bower packages, run `fab update` +`static/components/bower.json`. To update our bower packages, run `bower install` in this directory. ## less If you edit our `.less` files you will need to run the less compiler to build -our minified css files. This can be done by running `fab css` from this directory, -or `python setup.py css` from the root of the repository. +our minified css files. This can be done by running `python setup.py css` from the root of the repository. If you are working frequently with `.less` files please consider installing git hooks that rebuild the css files and corresponding maps in `${RepoRoot}/git-hooks/install-hooks.sh`. diff --git a/IPython/html/fabfile.py b/IPython/html/tasks.py similarity index 80% rename from IPython/html/fabfile.py rename to IPython/html/tasks.py index 9283b8e47..a384a6bd7 100644 --- a/IPython/html/fabfile.py +++ b/IPython/html/tasks.py @@ -1,7 +1,6 @@ -""" fabfile to prepare the notebook """ +"""invoke task file to build CSS""" -from fabric.api import local,lcd -from fabric.utils import abort +from invoke import task, run import os from distutils.version import LooseVersion as V from subprocess import check_output @@ -40,11 +39,9 @@ def _need_css_update(): return False +@task def css(minify=False, verbose=False, force=False): """generate the css from less files""" - minify = _to_bool(minify) - verbose = _to_bool(verbose) - force = _to_bool(force) # minify implies force because it's not the default behavior if not force and not minify and not _need_css_update(): print("css up-to-date") @@ -56,15 +53,10 @@ def css(minify=False, verbose=False, force=False): sourcemap = pjoin('style', "%s.min.css.map" % name) _compile_less(source, target, sourcemap, minify, verbose) -def _to_bool(b): - if not b in ['True', 'False', True, False]: - abort('boolean expected, got: %s' % b) - return (b in ['True', True]) - def _compile_less(source, target, sourcemap, minify=True, verbose=False): """Compile a less file by source and target relative to static_dir""" - min_flag = '-x' if minify is True else '' - ver_flag = '--verbose' if verbose is True else '' + min_flag = '-x' if minify else '' + ver_flag = '--verbose' if verbose else '' # pin less to version number from above try: @@ -80,6 +72,12 @@ def _compile_less(source, target, sourcemap, minify=True, verbose=False): 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)) static_path = pjoin(here, static_dir) - with lcd(static_dir): - local('lessc {min_flag} {ver_flag} --source-map={sourcemap} --source-map-basepath={static_path} --source-map-rootpath="../" {source} {target}'.format(**locals())) + cwd = os.getcwd() + try: + os.chdir(static_dir) + run('lessc {min_flag} {ver_flag} --source-map={sourcemap} --source-map-basepath={static_path} --source-map-rootpath="../" {source} {target}'.format(**locals()), + echo=True, + ) + finally: + os.chdir(cwd) diff --git a/IPython/testing/iptest.py b/IPython/testing/iptest.py index 1389dd5e6..50876c5ab 100644 --- a/IPython/testing/iptest.py +++ b/IPython/testing/iptest.py @@ -259,7 +259,7 @@ sec.requires('zmq', 'tornado', 'requests', 'sqlite3', 'jsonschema') # file in there (MathJax ships a conf.py), so we might as # well play it safe and skip the whole thing. sec.exclude('static') -sec.exclude('fabfile') +sec.exclude('tasks') if not have['jinja2']: sec.exclude('notebookapp') if not have['pygments'] or not have['jinja2']: diff --git a/git-hooks/post-checkout b/git-hooks/post-checkout index a8b12067a..e491e8f84 100755 --- a/git-hooks/post-checkout +++ b/git-hooks/post-checkout @@ -9,12 +9,12 @@ else PREVIOUS_HEAD=$1 fi -# if style changed (and less/fabric available), rebuild sourcemaps +# if style changed (and less/invoke available), rebuild sourcemaps if [[ ! -z "$(git diff $PREVIOUS_HEAD IPython/html/static/style/ipython.min.css)" && ! -z "$(git diff $PREVIOUS_HEAD IPython/html/static/style/style.min.css)" && ! -z $(which 2>/dev/null lessc) - && ! -z $(which 2>/dev/null fab) + && ! -z $(which 2>/dev/null invoke) ]]; then echo "rebuilding sourcemaps" cd IPython/html diff --git a/setupbase.py b/setupbase.py index 2516e4fc2..5e85d4b75 100644 --- a/setupbase.py +++ b/setupbase.py @@ -669,7 +669,7 @@ class CompileCSS(Command): Regenerate the compiled CSS from LESS sources. - Requires various dev dependencies, such as fabric and lessc. + Requires various dev dependencies, such as invoke and lessc. """ description = "Recompile Notebook CSS" user_options = [ @@ -686,11 +686,12 @@ class CompileCSS(Command): self.force = bool(self.force) def run(self): - check_call([ - "fab", - "css:minify=%s,force=%s" % (self.minify, self.force), - ], cwd=pjoin(repo_root, "IPython", "html"), - ) + cmd = ['invoke', 'css'] + if self.minify: + cmd.append('--minify') + if self.force: + cmd.append('--force') + check_call(cmd, cwd=pjoin(repo_root, "IPython", "html")) class JavascriptVersion(Command):