mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 05:35:49 -04:00
16 lines
336 B
Python
16 lines
336 B
Python
|
|
from contextlib import contextmanager
|
||
|
|
import os
|
||
|
|
import tempfile
|
||
|
|
|
||
|
|
|
||
|
|
@contextmanager
|
||
|
|
def cdtemp():
|
||
|
|
"""Context manager to change to/return from a tmpdir."""
|
||
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
||
|
|
cwd = os.getcwd()
|
||
|
|
try:
|
||
|
|
os.chdir(tmpdir)
|
||
|
|
yield
|
||
|
|
finally:
|
||
|
|
os.chdir(cwd)
|