python: have %%dve and %%pml honor SPOT_TMPDIR and TMPDIR
* python/spot/aux.py (tmpdir): New context manager. * python/spot/ltsmin.i: Use it for the two magics. * NEWS: Mention this.
This commit is contained in:
parent
b136b81c6d
commit
e37f62dc75
3 changed files with 54 additions and 39 deletions
4
NEWS
4
NEWS
|
|
@ -127,6 +127,10 @@ New in spot 2.0.3a (not yet released)
|
|||
with spins, and dynamically load them. This is
|
||||
akin to the %%dve magic that was already supported.
|
||||
|
||||
* The %%dve and %%pml magics honor the SPOT_TMPDIR and
|
||||
TMPDIR environment variables. This especially helps
|
||||
when the current directory is read-only.
|
||||
|
||||
Documentation:
|
||||
|
||||
* A new example page shows how to test the equivalence of
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import subprocess
|
|||
import sys
|
||||
import os
|
||||
import errno
|
||||
import contextlib
|
||||
|
||||
def extend(*classes):
|
||||
"""
|
||||
|
|
@ -80,3 +81,13 @@ def rm_f(filename):
|
|||
except OSError as e:
|
||||
if e.errno != errno.ENOENT:
|
||||
raise
|
||||
|
||||
@contextlib.contextmanager
|
||||
def tmpdir():
|
||||
cwd = os.getcwd()
|
||||
tmpdir = os.environ.get('SPOT_TMPDIR') or os.environ.get('TMPDIR') or '.'
|
||||
try:
|
||||
os.chdir(tmpdir)
|
||||
yield
|
||||
finally:
|
||||
os.chdir(cwd)
|
||||
|
|
|
|||
|
|
@ -149,8 +149,7 @@ try:
|
|||
def dve(self, line, cell):
|
||||
if not line:
|
||||
raise ValueError("missing variable name for %%dve")
|
||||
# DiViNe prefers when files are in the current directory
|
||||
# so write cell into local file
|
||||
with spot.aux.tmpdir():
|
||||
with tempfile.NamedTemporaryFile(dir='.', suffix='.dve') as t:
|
||||
t.write(cell.encode('utf-8'))
|
||||
t.flush()
|
||||
|
|
@ -179,6 +178,7 @@ try:
|
|||
def pml(self, line, cell):
|
||||
if not line:
|
||||
raise ValueError("missing variable name for %%pml")
|
||||
with spot.aux.tmpdir():
|
||||
with tempfile.NamedTemporaryFile(dir='.', suffix='.pml') as t:
|
||||
t.write(cell.encode('utf-8'))
|
||||
t.flush()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue