-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
96 lines (76 loc) · 2.53 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
# Based on https://github.com/jupyterlab/jupyterlab-demo/blob/master/tasks.py
import os
from shutil import which
from invoke import task, Collection
env_name = 'jupyter-demo'
source = '' if os.name == 'nt' else 'source'
@task
def environment(ctx, clean=False, env_name=env_name):
'''
Creates environment for demo
Args:
clean: deletes environment prior to reinstallation
env_name: name of environment to install
'''
if clean and env_name != 'root':
print(f'deleting environment {env_name}')
ctx.run(f'{source} deactivate && conda env remove -n {env_name}')
# Create a new environment
print(f'creating environment {env_name}')
ctx.run(f'conda env create -n {env_name}')
build(ctx, env_name=env_name)
@task
def build(ctx, env_name=env_name):
'''
Builds an environment with appropriate extensions.
'''
cmd_str = ' && '.join(str for str in [
f'{source} activate {env_name}' if env_name != 'root' else None,
'jupyter labextension install @jupyter-widgets/[email protected]',
'jupyter labextension install beakerx-jupyterlab',
'jupyter labextension install bqplot',
'jupyter lab clean',
'jupyter lab build'
] if str)
print(f'> {cmd_str}')
ctx.run(cmd_str)
@task
def clean(ctx, env_name=env_name):
'''
Removes environment for demo
Args:
env_name: name of environment to install
'''
if env_name != 'root':
print(f'deleting environment {env_name}')
ctx.run(f'{source} deactivate && conda env remove -n {env_name}')
@task
def lab(ctx, env_name=env_name):
'''
Starts jupyterlab application
'''
cmd_str = ' && '.join(str for str in [
f'{source} activate {env_name}' if env_name != 'root' else None,
'jupyter lab'
] if str)
print(f'> {cmd_str}')
ctx.run(cmd_str)
@task
def notebook(ctx, env_name=env_name):
'''
Starts jupyter notebook application
'''
cmd_str = ' && '.join(str for str in [
f'{source} activate {env_name}' if env_name != 'root' else None,
'jupyter notebook'
] if str)
print(f'> {cmd_str}')
ctx.run(cmd_str)
# Configure cross-platform settings.
ns = Collection(environment, build, clean, lab, notebook)
ns.configure({
'run': {
'shell': which('bash') if os.name != 'nt' else which('cmd'),
'pty': False if os.name == 'nt' else True
}
})