Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drop dependency on testpath. (#1723)
Co-authored-by: Steven Silvester <steven.silvester@ieee.org>
- Loading branch information
Showing
5 changed files
with
43 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"""Backport of Python 3.11's contextlib.chdir.""" | ||
|
||
|
||
from contextlib import AbstractContextManager | ||
import os | ||
|
||
|
||
class chdir(AbstractContextManager): | ||
"""Non thread-safe context manager to change the current working directory.""" | ||
|
||
def __init__(self, path): | ||
self.path = path | ||
self._old_cwd = [] | ||
|
||
def __enter__(self): | ||
self._old_cwd.append(os.getcwd()) | ||
os.chdir(self.path) | ||
|
||
def __exit__(self, *excinfo): | ||
os.chdir(self._old_cwd.pop()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters