Changes the current directory to the given path and prepends it to `sys.path`. This method is intended to use with `with`, so after its usage, the current directory will be set to the previous value.
(new_dir: str, verbose: bool = False)
| 63 | |
| 64 | @contextmanager |
| 65 | def pushd(new_dir: str, verbose: bool = False): |
| 66 | """ |
| 67 | Changes the current directory to the given path and prepends it to `sys.path`. |
| 68 | This method is intended to use with `with`, so after its usage, the current |
| 69 | directory will be set to the previous value. |
| 70 | """ |
| 71 | previous_dir = os.getcwd() |
| 72 | if verbose: |
| 73 | logger.info(f'Changing directory to {new_dir}') # type: ignore |
| 74 | os.chdir(new_dir) |
| 75 | try: |
| 76 | yield |
| 77 | finally: |
| 78 | if verbose: |
| 79 | logger.info(f'Changing directory back to {previous_dir}') |
| 80 | os.chdir(previous_dir) |
| 81 | |
| 82 | |
| 83 | @contextmanager |
searching dependent graphs…