forked from jupyter/nbgrader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
168 lines (133 loc) · 4.39 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
159
160
161
162
163
164
165
166
167
168
import os
import re
from invoke import task, collection
from textwrap import dedent
import sys
if sys.platform == 'win32':
WINDOWS = True
else:
WINDOWS = False
def run(ctx, *args, **kwargs):
if 'pty' not in kwargs:
kwargs['pty'] = True
if WINDOWS:
kwargs['pty'] = False
if 'echo' not in kwargs:
kwargs['echo'] = True
return ctx.run(*args, **kwargs)
def echo(msg):
print("\033[1;37m{0}\033[0m".format(msg))
def _check_if_directory_in_path(pth, target):
while pth != '':
pth, dirname = os.path.split(pth)
if dirname == target:
return True
return False
try:
from nbformat import read
except ImportError:
echo("Warning: nbformat could not be imported, some tasks may not work")
@task
def docs(ctx):
if not WINDOWS:
run(ctx, 'py.test --nbval-lax --current-env nbgrader/docs/source/user_guide/*.ipynb')
run(ctx, 'python nbgrader/docs/source/build_docs.py')
run(ctx, 'make -C nbgrader/docs html')
run(ctx, 'make -C nbgrader/docs linkcheck')
run(ctx, 'make -C nbgrader/docs spelling')
@task
def clean_docs(ctx):
run(ctx, 'python nbgrader/docs/source/clear_docs.py')
def _run_tests(ctx, mark=None, skip=None, junitxml=None):
if not WINDOWS:
import distutils.sysconfig
site = distutils.sysconfig.get_python_lib()
sitecustomize_path = os.path.join(site, "sitecustomize.py")
if os.path.exists(sitecustomize_path):
with open(sitecustomize_path, "r") as fh:
sitecustomize = fh.read()
with open(sitecustomize_path, "w") as fh:
fh.write(re.sub(
"^### begin nbgrader changes$.*^### end nbgrader changes$[\n]",
"",
sitecustomize,
flags=re.MULTILINE | re.DOTALL))
with open(sitecustomize_path, "a") as fh:
fh.write(dedent(
"""
### begin nbgrader changes
import coverage; coverage.process_startup()
### end nbgrader changes
"""
).lstrip())
cmd = []
if not WINDOWS:
cmd.append('COVERAGE_PROCESS_START={}'.format(os.path.join(os.getcwd(), ".coveragerc")))
cmd.append('py.test')
if not WINDOWS:
cmd.append('--cov nbgrader')
cmd.append('--no-cov-on-fail')
if junitxml:
cmd.extend(['--junitxml', junitxml])
cmd.append('-v')
cmd.append('-x')
cmd.extend(['--rerun', '4'])
marks = []
if mark is not None:
marks.append(mark)
if skip is not None:
marks.append("not {}".format(skip))
if len(marks) > 0:
cmd.append('-m "{}"'.format(" and ".join(marks)))
run(ctx, " ".join(cmd))
if not WINDOWS:
run(ctx, "ls -a .coverage*")
run(ctx, "coverage combine")
@task
def tests(ctx, group='all', skip=None, junitxml=None):
if group == 'python':
_run_tests(ctx, mark="not nbextensions", skip=skip, junitxml=junitxml)
elif group == 'nbextensions':
_run_tests(ctx, mark="nbextensions", skip=skip, junitxml=junitxml)
elif group == 'docs':
docs(ctx)
elif group == 'all':
_run_tests(ctx, skip=skip, junitxml=junitxml)
else:
raise ValueError("Invalid test group: {}".format(group))
@task
def after_success(ctx, group):
if group in ('python', 'nbextensions'):
run(ctx, 'codecov')
else:
echo('Nothing to do.')
@task
def js(ctx, clean=True):
run(ctx, 'npm install')
run(ctx, './node_modules/.bin/bower install --config.interactive=false')
if clean:
run(ctx, 'git clean -fdX nbgrader/server_extensions/formgrader/static/components')
@task
def install(ctx, group):
# The docs don't seem to build correctly if it's a symlinked install.
if group == 'docs':
cmd = 'pip install -r dev-requirements.txt .'
else:
cmd = 'pip install -r dev-requirements.txt -e .'
# clone travis wheels repo to make installing requirements easier
run(ctx, 'git clone --quiet --depth 1 https://github.com/minrk/travis-wheels ~/travis-wheels')
run(ctx, 'PIP_FIND_LINKS=~/travis-wheels/wheelhouse {}'.format(cmd))
ns = collection.Collection(
after_success,
clean_docs,
docs,
install,
js,
tests,
)
if WINDOWS:
ns.configure({
'run': {
'shell': os.environ.get('COMSPEC', os.environ.get('SHELL')),
}
})