From d80a04413b61bb1fbdc91bf0a51d43c1fe1224ed Mon Sep 17 00:00:00 2001 From: Dimitri Merejkowsky Date: Fri, 8 Nov 2019 19:34:00 +0100 Subject: [PATCH] Small build system to build lectures --- saison-2/cours/.gitignore | 1 + saison-2/cours/Makefile | 4 ---- saison-2/cours/build.in.ninja | 2 ++ saison-2/cours/build.py | 21 +++++++++++++++++++++ 4 files changed, 24 insertions(+), 4 deletions(-) delete mode 100644 saison-2/cours/Makefile create mode 100644 saison-2/cours/build.in.ninja create mode 100644 saison-2/cours/build.py diff --git a/saison-2/cours/.gitignore b/saison-2/cours/.gitignore index a136337..89ab085 100644 --- a/saison-2/cours/.gitignore +++ b/saison-2/cours/.gitignore @@ -1 +1,2 @@ *.pdf +build/ diff --git a/saison-2/cours/Makefile b/saison-2/cours/Makefile deleted file mode 100644 index 36bd93d..0000000 --- a/saison-2/cours/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -all: ./e2l-python-classes-01.pdf - -%.pdf: %.md - pandoc --pdf-engine=xelatex $< -o $@ diff --git a/saison-2/cours/build.in.ninja b/saison-2/cours/build.in.ninja new file mode 100644 index 0000000..402d8b9 --- /dev/null +++ b/saison-2/cours/build.in.ninja @@ -0,0 +1,2 @@ +rule pandoc + command = pandoc --pdf-engine=xelatex $in -o $out diff --git a/saison-2/cours/build.py b/saison-2/cours/build.py new file mode 100644 index 0000000..4c5d395 --- /dev/null +++ b/saison-2/cours/build.py @@ -0,0 +1,21 @@ +from path import Path +import sys +import subprocess + + +def main(): + template = Path("build.in.ninja").text() + to_write = template + for md_file in Path(".").files("*.md"): + to_write += f"build ../{md_file.with_suffix('.pdf')}: pandoc ../{md_file}\n" + build_path = Path("build") + build_path.mkdir_p() + out = build_path / "build.ninja" + out.write_text(to_write) + process = subprocess.run(["ninja", "-C", build_path]) + if process.returncode != 0: + sys.exit(1) + + +if __name__ == "__main__": + main()