1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
"""fabfile to prepare IPython notebook dependencies
via bower and bower-like process for non-bowerables
"""
import glob
import json
import os
import tempfile
import urllib2
import shutil
from io import BytesIO
from tarfile import TarFile
from zipfile import ZipFile
from fabric.api import local,lcd
from fabric.utils import abort
pjoin = os.path.join
here = os.path.dirname(__file__)
components_dir = here
def clean():
for cfgfile in ("bower.json", "nonbower.json"):
with open(cfgfile) as f:
cfg = json.load(f)
for name in cfg.get('dependencies', {}).keys():
d = pjoin(components_dir, name)
if os.path.exists(d):
print("removing %s" % d)
shutil.rmtree(d)
def dependencies():
local("npm install -g bower")
def bower():
"""install components with bower"""
with lcd(here):
local('bower install')
def nonbower():
if not os.path.exists(components_dir):
components()
with open("nonbower.json") as f:
cfg = json.load(f)
for name, repo in cfg.get('dependencies', {}).items():
clone = "git clone"
if '#' in repo:
repo, tag = repo.split('#')
else:
tag = None
clone += " --depth 1"
with lcd(components_dir):
local("{clone} {repo} {name}".format(**locals()))
if tag:
with lcd(pjoin(components_dir, name)):
local("git checkout -b {0} tags/{0}".format(tag))
# remove the git tree, so we don't get submodules
shutil.rmtree(pjoin(components_dir, name, '.git'))
def postprocess():
with lcd(pjoin(components_dir, "bootstrap")):
local("npm install")
local("make bootstrap-css")
local("make bootstrap-js")
# add bootsrap packages to the PATH
# (less.js needs uglify, which bootstrap just installed above)
bins = glob.glob(pjoin(components_dir, "bootstrap", "node_modules", "*", "bin"))
os.environ['PATH'] = os.pathsep.join(bins + [os.environ['PATH']])
# build highlight.js
with lcd(pjoin(components_dir, "highlight.js")):
local("python tools/build.py")
for toignore in glob.glob(pjoin(here, "*", ".gitignore")):
os.unlink(toignore)
def update():
clean()
bower()
nonbower()
postprocess()
|