File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change
1
+ Provide helper `chdir ` method on the context object.
Original file line number Diff line number Diff line change 10
10
import pathlib
11
11
import sys
12
12
import typing
13
+ from collections .abc import Iterator
14
+ from contextlib import contextmanager
13
15
from functools import partial
14
16
from subprocess import CompletedProcess
15
17
from types import FunctionType
@@ -147,6 +149,21 @@ def run(
147
149
capture = capture ,
148
150
)
149
151
152
+ @contextmanager
153
+ def chdir (self , path : pathlib .Path ) -> Iterator [pathlib .Path ]:
154
+ """
155
+ Change the current working directory to the provided path.
156
+ """
157
+ cwd = pathlib .Path .cwd ()
158
+ try :
159
+ os .chdir (path )
160
+ yield path
161
+ finally :
162
+ if not cwd .exists ():
163
+ self .error (f"Unable to change back to path { cwd } " )
164
+ else :
165
+ os .chdir (cwd )
166
+
150
167
151
168
class Parser :
152
169
"""
You can’t perform that action at this time.
0 commit comments