MCPcopy Index your code
hub / github.com/ipython/ipython / TemporaryWorkingDirectory

Class TemporaryWorkingDirectory

IPython/utils/tempdir.py:45–62  ·  view source on GitHub ↗

Creates a temporary directory and sets the cwd to that directory. Automatically reverts to previous cwd upon cleanup. Usage example: with TemporaryWorkingDirectory() as tmpdir: ...

Source from the content-addressed store, hash-verified

43
44
45class TemporaryWorkingDirectory(TemporaryDirectory):
46 """
47 Creates a temporary directory and sets the cwd to that directory.
48 Automatically reverts to previous cwd upon cleanup.
49 Usage example:
50
51 with TemporaryWorkingDirectory() as tmpdir:
52 ...
53 """
54
55 def __enter__(self) -> str:
56 self.old_wd = Path.cwd()
57 _os.chdir(self.name)
58 return super(TemporaryWorkingDirectory, self).__enter__()
59
60 def __exit__(self, exc: Optional[Type[BaseException]], value: Optional[BaseException], tb: Optional[TracebackType]) -> None:
61 _os.chdir(self.old_wd)
62 return super(TemporaryWorkingDirectory, self).__exit__(exc, value, tb)

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…