From eef43826b3b8c13704c049933dab91a883c62cd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Pit-Claudel?= Date: Fri, 18 Dec 2020 13:21:11 -0500 Subject: [PATCH] cli: Invoke coqdoc in a temporary directory Coqdoc writes coqdoc.css unconditionally in its cwd, so invoke it from a temporary directory. Fixes GH-16. --- alectryon/cli.py | 12 +++++++----- recipes/.gitignore | 1 - 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/alectryon/cli.py b/alectryon/cli.py index 9b20a58d..d331bf80 100755 --- a/alectryon/cli.py +++ b/alectryon/cli.py @@ -188,19 +188,21 @@ def gen_latex_snippets(annotated): def _run_coqdoc(coq_snippets, coqdoc_bin=None): """Get the output of coqdoc on coq_code.""" - from tempfile import mkstemp + from shutil import rmtree + from tempfile import mkstemp, mkdtemp from subprocess import check_output coqdoc_bin = coqdoc_bin or os.path.join(os.getenv("COQBIN", ""), "coqdoc") - fd, filename = mkstemp(prefix="coqdoc_", suffix=".v") + dpath = mkdtemp(prefix="alectryon_coqdoc_") + fd, filename = mkstemp(prefix="alectryon_coqdoc_", suffix=".v", dir=dpath) try: for snippet in coq_snippets: os.write(fd, snippet.encode("utf-8")) os.write(fd, b"\n(* --- *)\n") # Separator to prevent fusing os.close(fd) - coqdoc = [coqdoc_bin, *COQDOC_OPTIONS, filename] - return check_output(coqdoc, timeout=10).decode("utf-8") + coqdoc = [coqdoc_bin, *COQDOC_OPTIONS, "-d", dpath, filename] + return check_output(coqdoc, cwd=dpath, timeout=10).decode("utf-8") finally: - os.remove(filename) + rmtree(dpath) def _gen_coqdoc_html(coqdoc_comments): from bs4 import BeautifulSoup diff --git a/recipes/.gitignore b/recipes/.gitignore index 52c7f36c..ba18ce4f 100644 --- a/recipes/.gitignore +++ b/recipes/.gitignore @@ -1,3 +1,2 @@ /output/*.css /output/*.js -coqdoc.css