summaryrefslogtreecommitdiff
path: root/support/asymptote
diff options
context:
space:
mode:
authorMichael Schwarz <michi.schwarz@gmail.com>2015-09-11 22:02:36 +0200
committerMichael Schwarz <michi.schwarz@gmail.com>2015-09-16 01:41:26 +0200
commitab26e5a8d54de099315e2cf473ec52610a6e3a17 (patch)
tree86766831c6d816fb1be11c5db19844a779ae9853 /support/asymptote
parent987fa08ce66809cfd2389042b27508a66bfa99a0 (diff)
downloadpogojig-ab26e5a8d54de099315e2cf473ec52610a6e3a17.tar.gz
pogojig-ab26e5a8d54de099315e2cf473ec52610a6e3a17.tar.bz2
pogojig-ab26e5a8d54de099315e2cf473ec52610a6e3a17.zip
Compile Asymptote files in separate working dir.
Asymptote leaves a trail of partially cleaned-up temporary files behind it when PDFLaTeX is used. With this changes, Asymptote files are compiled in a temporary directory outside the project root.
Diffstat (limited to 'support/asymptote')
-rw-r--r--support/asymptote/__main__.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/support/asymptote/__main__.py b/support/asymptote/__main__.py
index 1816224..5c6f67a 100644
--- a/support/asymptote/__main__.py
+++ b/support/asymptote/__main__.py
@@ -1,16 +1,23 @@
-import os, sys
+import os, sys, shutil
from lib import util
-def _asymptote(in_path, out_path, asymptote_dir):
- util.command([os.environ['ASYMPTOTE'], '-f', 'pdf', '-o', out_path, in_path], set_env = { 'ASYMPTOTE_DIR': asymptote_dir })
+def _asymptote(in_path, out_path, asymptote_dir, working_dir):
+ util.command([os.environ['ASYMPTOTE'], '-f', 'pdf', '-o', out_path, in_path], set_env = { 'ASYMPTOTE_DIR': asymptote_dir }, working_dir = working_dir)
def main(in_path, out_path):
_, out_suffix = os.path.splitext(out_path)
if out_suffix == '.pdf':
- _asymptote(in_path, out_path, os.path.dirname(in_path))
+ with util.TemporaryDirectory() as temp_dir:
+ absolute_in_path = os.path.abspath(in_path)
+ temp_out_path = os.path.join(temp_dir, 'out.pdf')
+
+ # Asymptote creates A LOT of temp files (presumably when invoking LaTeX) and leaves some of them behind. Thus we run asymptote in a temporary directory.
+ _asymptote(absolute_in_path, 'out', os.path.dirname(absolute_in_path), temp_dir)
+
+ shutil.copyfile(temp_out_path, out_path)
else:
raise Exception('Unknown file type: {}'.format(out_suffix))