Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: Invoke coqdoc in a temporary directory #17

Merged
merged 1 commit into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions alectryon/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion recipes/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/output/*.css
/output/*.js
coqdoc.css