-
-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Session.chdir() a context manager #543
Make Session.chdir() a context manager #543
Conversation
87c0386
to
2b1424d
Compare
2b1424d
to
3ae10ac
Compare
Could this be simplified further to a functional context manager? i.e. you wouldn't need the Something like: @contextlib.contextmanager
def chdir(self, to: str) -> Iterator:
original = os.getcwd()
try:
os.chdir(to)
yield
finally:
os.chdir(original) I haven't done much with context managers tbh so I'm not 100% that these are equivalent |
As far as I know the problem with this is that it would break the current functionality. @nox.session()
def some_session(session):
session.chdir("path/to/somewhere")
# Clean has been run here, so we are back in old working dir Using the class approach we are able to keep the current functionality at the cost of some complexity. |
Cool, makes sense, thanks! This looks good to me then |
Closes #512. Also see the discussion here: #513.
I'm a bit unsure if the changes to the docs are sufficient. Please suggest changes as you see fit.