MCPcopy
hub / github.com/GitGuardian/ggshield / cd

Function cd

ggshield/utils/os.py:56–66  ·  view source on GitHub ↗

A context manager to temporarily change the current directory

(newdir: Union[str, Path])

Source from the content-addressed store, hash-verified

54
55@contextmanager
56def cd(newdir: Union[str, Path]) -> Iterator[None]:
57 """
58 A context manager to temporarily change the current directory
59 """
60 prevdir = Path.cwd()
61 newdir = Path(newdir).expanduser()
62 os.chdir(newdir)
63 try:
64 yield
65 finally:
66 os.chdir(prevdir)
67
68
69@overload

Calls

no outgoing calls