Allow manual builds
This commit is contained in:
parent
7c75c6b5c9
commit
a4e5a065b0
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,6 +9,7 @@ __pycache__
|
|||||||
/output
|
/output
|
||||||
/output.zip
|
/output.zip
|
||||||
*.pdf
|
*.pdf
|
||||||
|
/manual
|
||||||
|
|
||||||
# TeX build files
|
# TeX build files
|
||||||
*.synctex*
|
*.synctex*
|
||||||
|
@ -5,6 +5,7 @@ import tomllib
|
|||||||
import shutil
|
import shutil
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
# list handouts without solutions
|
# list handouts without solutions
|
||||||
@ -16,10 +17,22 @@ ROOT: Path = Path(os.getcwd())
|
|||||||
|
|
||||||
### CONFIGURATION
|
### CONFIGURATION
|
||||||
OUT_DIR: Path = ROOT / "output"
|
OUT_DIR: Path = ROOT / "output"
|
||||||
|
OUT_DIR_MANUAL: Path = ROOT / "manual"
|
||||||
TYPST_PATH: str = "typst"
|
TYPST_PATH: str = "typst"
|
||||||
XETEX_PATH: str = "xelatex"
|
XETEX_PATH: str = "xelatex"
|
||||||
### END CONFIGURATION
|
### END CONFIGURATION
|
||||||
|
|
||||||
|
|
||||||
|
# If we're given an argument, build one handout.
|
||||||
|
# This places output into `OUT_DIR_MANUAL`
|
||||||
|
#
|
||||||
|
# If we're given no arguments, build everything,
|
||||||
|
# Placing output into `OUT_DIR`
|
||||||
|
target = None
|
||||||
|
if len(sys.argv) == 2:
|
||||||
|
target = Path(sys.argv[1])
|
||||||
|
print(f"Compiling `{target}`")
|
||||||
|
|
||||||
# Allow path override
|
# Allow path override
|
||||||
_env = os.environ.get("TYPST_PATH")
|
_env = os.environ.get("TYPST_PATH")
|
||||||
if isinstance(_env, str):
|
if isinstance(_env, str):
|
||||||
@ -35,13 +48,6 @@ if not ROOT.is_dir():
|
|||||||
log("Root is not a directory, cannot continue")
|
log("Root is not a directory, cannot continue")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
log(f"Output dir is {OUT_DIR}")
|
|
||||||
if OUT_DIR.exists():
|
|
||||||
log("Output dir exists, removing")
|
|
||||||
shutil.rmtree(OUT_DIR)
|
|
||||||
|
|
||||||
OUT_DIR.mkdir(parents=True)
|
|
||||||
|
|
||||||
|
|
||||||
IndexEntry = TypedDict(
|
IndexEntry = TypedDict(
|
||||||
"IndexEntry",
|
"IndexEntry",
|
||||||
@ -115,7 +121,9 @@ def log_error(res):
|
|||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
def build_typst(source_dir: Path, out_subdir: Path) -> IndexEntry | None:
|
def build_typst(
|
||||||
|
source_dir: Path, out_subdir: Path, *, out_dir=OUT_DIR
|
||||||
|
) -> IndexEntry | None:
|
||||||
if not (source_dir / "main.typ").is_file():
|
if not (source_dir / "main.typ").is_file():
|
||||||
# log(f"No main.typ, skipping {source_dir}")
|
# log(f"No main.typ, skipping {source_dir}")
|
||||||
return None
|
return None
|
||||||
@ -136,7 +144,7 @@ def build_typst(source_dir: Path, out_subdir: Path) -> IndexEntry | None:
|
|||||||
# Build handout
|
# Build handout
|
||||||
log(f"Building typst (handout) : {source_dir}")
|
log(f"Building typst (handout) : {source_dir}")
|
||||||
|
|
||||||
out = OUT_DIR / out_subdir
|
out = out_dir / out_subdir
|
||||||
out.mkdir(parents=True, exist_ok=True)
|
out.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
res = subprocess.run(
|
res = subprocess.run(
|
||||||
@ -190,7 +198,9 @@ def build_typst(source_dir: Path, out_subdir: Path) -> IndexEntry | None:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def build_xetex(source_dir: Path, out_subdir: Path) -> IndexEntry | None:
|
def build_xetex(
|
||||||
|
source_dir: Path, out_subdir: Path, *, out_dir=OUT_DIR
|
||||||
|
) -> IndexEntry | None:
|
||||||
if not (source_dir / "main.tex").is_file():
|
if not (source_dir / "main.tex").is_file():
|
||||||
# log(f"No main.tex, skipping {source_dir}")
|
# log(f"No main.tex, skipping {source_dir}")
|
||||||
return None
|
return None
|
||||||
@ -211,7 +221,7 @@ def build_xetex(source_dir: Path, out_subdir: Path) -> IndexEntry | None:
|
|||||||
# Build handout
|
# Build handout
|
||||||
log(f"Building xetex (handout) : {source_dir}")
|
log(f"Building xetex (handout) : {source_dir}")
|
||||||
|
|
||||||
out = OUT_DIR / out_subdir
|
out = out_dir / out_subdir
|
||||||
out.mkdir(parents=True, exist_ok=True)
|
out.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
res = subprocess.run(
|
res = subprocess.run(
|
||||||
@ -297,10 +307,31 @@ def build_dir(base: str, out_sub: str, index: list[IndexEntry]):
|
|||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
index: list[IndexEntry] = []
|
if target is None:
|
||||||
build_dir("src/Advanced", "Advanced", index)
|
log(f"Output dir is {OUT_DIR}")
|
||||||
build_dir("src/Intermediate", "Intermediate", index)
|
if OUT_DIR.exists():
|
||||||
build_dir("src/Warm-Ups", "Warm-Ups", index)
|
log("Output dir exists, removing")
|
||||||
|
shutil.rmtree(OUT_DIR)
|
||||||
|
|
||||||
with open(OUT_DIR / "index.json", "w") as f:
|
OUT_DIR.mkdir(parents=True)
|
||||||
|
|
||||||
|
index: list[IndexEntry] = []
|
||||||
|
build_dir("src/Advanced", "Advanced", index)
|
||||||
|
build_dir("src/Intermediate", "Intermediate", index)
|
||||||
|
build_dir("src/Warm-Ups", "Warm-Ups", index)
|
||||||
|
|
||||||
|
with open(OUT_DIR / "index.json", "w") as f:
|
||||||
f.write(json.dumps(index))
|
f.write(json.dumps(index))
|
||||||
|
|
||||||
|
else:
|
||||||
|
log(f"Output dir is {OUT_DIR_MANUAL}")
|
||||||
|
# if OUT_DIR_MANUAL.exists():
|
||||||
|
# log("Output dir exists, removing")
|
||||||
|
# shutil.rmtree(OUT_DIR_MANUAL)
|
||||||
|
OUT_DIR_MANUAL.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
builders = [build_typst, build_xetex]
|
||||||
|
for builder in builders:
|
||||||
|
res = builder(target, Path("."), out_dir=OUT_DIR_MANUAL)
|
||||||
|
if res is not None:
|
||||||
|
break
|
||||||
|
Loading…
x
Reference in New Issue
Block a user