-
Notifications
You must be signed in to change notification settings - Fork 26
/
tasks.py
52 lines (42 loc) · 1.27 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
#!/usr/bin/env python
"""
Deployment file to facilitate releases of monty.
"""
from __future__ import division
import glob
import requests
import json
import os
import re
import subprocess
from pathlib import Path
from invoke import task
from monty.os import cd
@task
def cleanup(ctx):
with cd("lectures/slides_tex"):
ctx.run("rm *.toc *.snm *.aux *.vrb *.log *.nav *.out *.bbl *.blg", warn=True)
ctx.run("rm -r _minted*", warn=True)
@task
def build_pdf(ctx, fname):
with cd("lectures/slides_tex"):
fn, ext = fname.split(".")
ctx.run('pdflatex -shell-escape "%s"' % fn)
ctx.run('bibtex "%s"' % fn, warn=True)
ctx.run('pdflatex -shell-escape "%s"' % fn)
ctx.run('pdflatex -shell-escape "%s"' % fn)
ctx.run("mv *.pdf ../../assets/slides", warn=True)
@task
def build_changed(ctx):
status = subprocess.check_output(["git", "diff", "--name-only", "HEAD"])
changed = [Path(l).name for l in status.decode("utf").split("\n") if l.endswith(".tex")]
if changed:
for fname in changed:
build_pdf(ctx, fname)
cleanup(ctx)
@task
def build_all(ctx):
for fname in glob.glob("lectures/slides_tex/*.tex"):
path = Path(fname)
build_pdf(ctx, path.name)
cleanup(ctx)