action
This commit is contained in:
@ -16,10 +16,15 @@ ROOT: Path = Path(os.getcwd())
|
||||
|
||||
### CONFIGURATION
|
||||
OUT_DIR: Path = ROOT / "output"
|
||||
TYPST_PATH = "typst"
|
||||
XETEX_PATH = "xelatex"
|
||||
TYPST_PATH: str = "typst"
|
||||
XETEX_PATH: str = "xelatex"
|
||||
### END CONFIGURATION
|
||||
|
||||
# Allow path override
|
||||
_env = os.environ.get("TYPST_PATH")
|
||||
if isinstance(_env, str):
|
||||
TYPST_PATH = _env
|
||||
|
||||
|
||||
def log(msg):
|
||||
print(f"[BUILD.PY] {msg}")
|
||||
@ -49,6 +54,10 @@ MetaToml = TypedDict(
|
||||
)
|
||||
|
||||
|
||||
def sanitize_file_name(file: str) -> str:
|
||||
return file.replace("?", "")
|
||||
|
||||
|
||||
def read_meta_toml(file: Path) -> MetaToml:
|
||||
with file.open("rb") as f:
|
||||
base = tomllib.load(f)
|
||||
@ -127,6 +136,7 @@ def build_typst(source_dir: Path, out_subdir: Path) -> IndexEntry | None:
|
||||
out = OUT_DIR / out_subdir
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
file_name = sanitize_file_name(f"{meta['title']}.pdf")
|
||||
res = subprocess.run(
|
||||
[
|
||||
TYPST_PATH,
|
||||
@ -135,7 +145,7 @@ def build_typst(source_dir: Path, out_subdir: Path) -> IndexEntry | None:
|
||||
"main.typ",
|
||||
"--input",
|
||||
"show_solutions=false",
|
||||
f"{out}/{meta['title']}.pdf",
|
||||
f"{out}/{file_name}",
|
||||
],
|
||||
cwd=source_dir,
|
||||
stdout=subprocess.PIPE,
|
||||
@ -148,13 +158,14 @@ def build_typst(source_dir: Path, out_subdir: Path) -> IndexEntry | None:
|
||||
# Build solutions
|
||||
if meta["publish_solutions"]:
|
||||
log(f"Building typst (solutions): {source_dir}")
|
||||
file_name = sanitize_file_name(f"{meta['title']}.sols.pdf")
|
||||
res = subprocess.run(
|
||||
[
|
||||
TYPST_PATH,
|
||||
"compile",
|
||||
"--ignore-system-fonts",
|
||||
"main.typ",
|
||||
f"{out}/{meta['title']}.sols.pdf",
|
||||
f"{out}/{file_name}",
|
||||
],
|
||||
cwd=source_dir,
|
||||
stdout=subprocess.PIPE,
|
||||
@ -208,7 +219,12 @@ def build_xetex(source_dir: Path, out_subdir: Path) -> IndexEntry | None:
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
|
||||
shutil.copy(source_dir / "main.pdf", f"{out}/{meta['title']}.pdf")
|
||||
file_name = sanitize_file_name(f"{meta['title']}.pdf")
|
||||
try:
|
||||
shutil.copy(source_dir / "main.pdf", f"{out}/{file_name}")
|
||||
except Exception as e:
|
||||
log(f"Error: {e}")
|
||||
log_error(res)
|
||||
|
||||
if res.returncode != 0:
|
||||
log_error(res)
|
||||
@ -227,7 +243,12 @@ def build_xetex(source_dir: Path, out_subdir: Path) -> IndexEntry | None:
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
|
||||
shutil.copy(source_dir / "main.pdf", f"{out}/{meta['title']}.sols.pdf")
|
||||
file_name = sanitize_file_name(f"{meta['title']}.sols.pdf")
|
||||
try:
|
||||
shutil.copy(source_dir / "main.pdf", f"{out}/{file_name}")
|
||||
except Exception as e:
|
||||
log(f"Error: {e}")
|
||||
log_error(res)
|
||||
|
||||
if res.returncode != 0:
|
||||
log_error(res)
|
||||
@ -278,6 +299,7 @@ def build_dir(base: str, out_sub: str, index: list[IndexEntry]):
|
||||
|
||||
index: list[IndexEntry] = []
|
||||
|
||||
index.extend(build_dir("Warm-Ups", "Warm-Ups", index))
|
||||
index.extend(build_dir("Advanced", "Advanced", index))
|
||||
index.extend(build_dir("Intermediate", "Intermediate", index))
|
||||
|
||||
|
Reference in New Issue
Block a user