-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtasks.py
120 lines (94 loc) · 2.84 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
"""
invoke file for automating build/config stuff.
Example:
invoke build
invoke --list
Can be executed everywhere inside the abinit-panel directory, including build directories.
Use: `pip install invoke --user` to install invoke package.
"""
import os
#import sys
import platform
from contextlib import contextmanager
try:
from invoke import task
except ImportError:
raise ImportError("Cannot import invoke package. Use `pip install invoke --user`")
HERE = os.path.dirname(__file__)
@contextmanager
def cd(path):
"""
A Fabric-inspired cd context that temporarily changes directory for
performing some tasks, and returns to the original working directory
afterwards. E.g.,
with cd("/my/path/"):
do_something()
Args:
path: Path to cd to.
"""
# Taken from monty.os
cwd = os.getcwd()
os.chdir(path)
try:
yield
finally:
os.chdir(cwd)
@task
def build(ctx):
"""
Build the book.
"""
with cd(HERE):
ctx.run("jb build abipy_book", pty=True)
@task
def build_all(ctx):
"""
Build the book from scratch.
"""
with cd(HERE):
ctx.run("jb clean abipy_book", pty=True)
ctx.run("jb build abipy_book --all", pty=True)
# When debugging your book build, the following options can be helpful:
#
# jupyter-book build -W -n --keep-going mybookname/
# This will check for missing references (-n), turning them into errors (-W), but will still attempt to run the full build (--keep-going), so that you can see all errors in one run.
#
# You can also use -v or -vvv to increase verbosity.
#@task
#def build_no_cache(ctx):
# """
# Build the docker image locally (Do not use cache when building the image)
# """
# _before_building()
# with cd(HERE):
# ctx.run("docker build --no-cache -t abinit-panel:latest .", pty=True)
#@task
#def submodules(ctx):
# """Update submodules."""
# with cd(HERE):
# # https://stackoverflow.com/questions/1030169/easy-way-to-pull-latest-of-all-git-submodules
# ctx.run("git submodule update --remote --init", pty=True)
# #ctx.run("git submodule update --remote", pty=True)
# ctx.run("git submodule update --recursive --remote", pty=True)
@task
def linkcheck(ctx):
"""
If you’d like to make sure that the links outside of your book are valid,
run the Sphinx link checker with Jupyter Book. This will check each of your external links
and ensure that they resolve.
"""
with cd(HERE):
ctx.run("jb build abipy_book --builder linkcheck", pty=True)
@task
def du(ctx):
"""
Compute disk usage.
"""
with cd(HERE):
ctx.run("du -msh -I _build abipy_book/", pty=True)
@task
def md2nb(ctx, md_filename):
"""
Convert markdown file to notebook.
"""
ctx.run("jupytext {md_filename} --to ipynb" ,pty=True)