Skip to content

Commit f7ebd8d

Browse files
Add temporary directory context manager
1 parent 2f4f53c commit f7ebd8d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pyrolite/util/general.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import contextlib
12
import datetime
23
import operator
34
import os
@@ -52,6 +53,14 @@ def temp_path(suffix=""):
5253
return Path(directory)
5354

5455

56+
@contextlib.contextmanager
57+
def tempdir(**kwargs):
58+
tmp_dir = Path(mkdtemp(**kwargs))
59+
try:
60+
yield tmp_dir
61+
finally:
62+
remove_tempdir(tmp_dir)
63+
5564
def flatten_dict(d, climb=False, safemode=False):
5665
"""
5766
Flattens a nested dictionary containing only string keys.

0 commit comments

Comments
 (0)