Module: utils.tempdir

This module contains classes - NamedFileInTemporaryDirectory, TemporaryWorkingDirectory.

These classes add extra features such as creating a named file in temporary directory and creating a context manager for the working directory which is also temporary.

2 Classes

class IPython.utils.tempdir.NamedFileInTemporaryDirectory(filename: str, mode: str, bufsize: int = -1, add_to_syspath: bool = False, **kwds)

Bases: object

__init__(filename: str, mode: str, bufsize: int = -1, add_to_syspath: bool = False, **kwds)

Open a file named filename in a temporary directory.

This context manager is preferred over NamedTemporaryFile in stdlib tempfile when one needs to reopen the file.

Arguments mode and bufsize are passed to open. Rest of the arguments are passed to TemporaryDirectory.

class IPython.utils.tempdir.TemporaryWorkingDirectory(suffix=None, prefix=None, dir=None, ignore_cleanup_errors=False, *, delete=True)

Bases: TemporaryDirectory

Creates a temporary directory and sets the cwd to that directory. Automatically reverts to previous cwd upon cleanup. Usage example:

with TemporaryWorkingDirectory() as tmpdir: