forked from jupyter/nbviewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.py
158 lines (127 loc) · 4.37 KB
/
tasks.py
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import os
import hashlib
import pipes
import shutil
import tempfile
import sys
from tarfile import TarFile
import invoke
NOTEBOOK_VERSION = '5.7.8' # the notebook version whose LESS we will use
NOTEBOOK_CHECKSUM = '573e0ae650c5d76b18b6e564ba6d21bf321d00847de1d215b418acb64f056eb8' # sha256 checksum of notebook tarball
APP_ROOT = os.path.dirname(__file__)
NPM_BIN = os.path.join(APP_ROOT, "node_modules", ".bin")
NOTEBOOK_STATIC_PATH = os.path.join(APP_ROOT, 'notebook-%s' % NOTEBOOK_VERSION, 'notebook', 'static')
@invoke.task
def test(ctx):
ctx.run("nosetests -v")
@invoke.task
def bower(ctx):
ctx.run(
"cd {}/nbviewer/static &&".format(APP_ROOT) +
" {}/bower install".format(NPM_BIN) +
" --config.interactive=false --allow-root"
)
@invoke.task
def notebook_static(ctx):
if os.path.exists(NOTEBOOK_STATIC_PATH):
return
fname = "notebook-%s.tar.gz" % NOTEBOOK_VERSION
nb_archive = os.path.join(APP_ROOT, fname)
if not os.path.exists(nb_archive):
print("Downloading from pypi -> %s" % nb_archive)
ctx.run(
" ".join(
map(
pipes.quote,
[
sys.executable,
"-m",
"pip",
"download",
"notebook=={}".format(NOTEBOOK_VERSION),
"--no-deps",
"-d",
APP_ROOT,
"--no-binary",
":all:",
],
)
)
)
with open(nb_archive, "rb") as f:
checksum = hashlib.sha256(f.read()).hexdigest()
if checksum != NOTEBOOK_CHECKSUM:
print("Notebook sdist checksum mismatch", file=sys.stderr)
print("Expected: %s" % NOTEBOOK_CHECKSUM, file=sys.stderr)
print("Got: %s" % checksum, file=sys.stderr)
sys.exit(1)
with TarFile.open(nb_archive, 'r:gz') as nb_archive_file:
print("Extract {0} in {1}".format(nb_archive, nb_archive_file.extractall()))
@invoke.task
def less(ctx, debug=False):
notebook_static(ctx)
if debug:
extra = "--source-map"
else:
extra = " --clean-css='--s1 --advanced --compatibility=ie8'"
tmpl = (
"cd {}/nbviewer/static/less ".format(APP_ROOT) +
" && {}/lessc".format(NPM_BIN) +
" {1} "
" --include-path={2}"
" --autoprefix='> 1%'"
" {0}.less ../build/{0}.css"
)
args = (extra, NOTEBOOK_STATIC_PATH)
for less_file in ["styles", "notebook", "slides", "custom"]:
ctx.run(tmpl.format(less_file, *args))
@invoke.task
def screenshots(ctx, root="http://localhost:5000/", dest="./screenshots"):
dest = os.path.abspath(dest)
script = """
root = "{root}"
urls = ({{name, url}} for name, url of {{
home: ""
dir: "github/ipython/ipython/tree/3.x/examples/"
user: "github/ipython/"
gists: "gist/fperez/"
notebook: "github/ipython/ipython/blob/3.x/examples/Notebook/Notebook%20Basics.ipynb"}})
screens = ({{name, w, h}} for name, [w, h] of {{
smartphone_portrait: [320, 480]
smartphone_landscape: [480, 320]
tablet_portrait: [768, 1024]
tablet_landscape: [1024, 768]
desktop_standard: [1280, 1024]
desktop_1080p: [1920, 1080]
}})
casper.start root
casper.each screens, (_, screen) ->
@then ->
@viewport screen.w, screen.h, ->
_.each urls, (_, page) ->
@thenOpen root + page.url, ->
@wait 1000
@then ->
@echo "#{{page.name}} #{{screen.name}}"
@capture "{dest}/#{{page.name}}-#{{screen.name}}.png"
casper.run()
""".format(root=root, dest=dest)
tmpdir = tempfile.mkdtemp()
tmpfile = os.path.join(tmpdir, "screenshots.coffee")
with open(tmpfile, "w+") as f:
f.write(script)
ctx.run("casperjs test {script}".format(script=tmpfile))
shutil.rmtree(tmpdir)
@invoke.task
def sdist(ctx):
bower(ctx)
less(ctx)
ctx.run('python setup.py sdist')
@invoke.task
def release(ctx):
bower(ctx)
less(ctx)
ctx.run('python setup.py sdist bdist_wheel upload')