Context manager that temporarily creates and changes the CWD. The function temporarily changes the current working directory after creating a temporary directory in the current directory with name *name*. If *name* is None, the temporary directory is created using tempfile.mkd
(name='tempcwd', quiet=False)
| 581 | |
| 582 | @contextlib.contextmanager |
| 583 | def temp_cwd(name='tempcwd', quiet=False): |
| 584 | """ |
| 585 | Context manager that temporarily creates and changes the CWD. |
| 586 | |
| 587 | The function temporarily changes the current working directory |
| 588 | after creating a temporary directory in the current directory with |
| 589 | name *name*. If *name* is None, the temporary directory is |
| 590 | created using tempfile.mkdtemp. |
| 591 | |
| 592 | If *quiet* is False (default) and it is not possible to |
| 593 | create or change the CWD, an error is raised. If *quiet* is True, |
| 594 | only a warning is raised and the original CWD is used. |
| 595 | |
| 596 | """ |
| 597 | with temp_dir(path=name, quiet=quiet) as temp_path: |
| 598 | with change_cwd(temp_path, quiet=quiet) as cwd_dir: |
| 599 | yield cwd_dir |
| 600 | |
| 601 | |
| 602 | def create_empty_file(filename): |
searching dependent graphs…