File: util.py

package info (click to toggle)
python-srsly 2.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,852 kB
  • sloc: python: 21,404; ansic: 4,160; cpp: 51; sh: 12; makefile: 6
file content (16 lines) | stat: -rw-r--r-- 415 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import tempfile
from pathlib import Path
from contextlib import contextmanager
import shutil


@contextmanager
def make_tempdir(files={}, mode="w"):
    temp_dir_str = tempfile.mkdtemp()
    temp_dir = Path(temp_dir_str)
    for name, content in files.items():
        path = temp_dir / name
        with path.open(mode) as file_:
            file_.write(content)
    yield temp_dir
    shutil.rmtree(temp_dir_str)