From 25f4e6eabf8fb8f10ea10e4bd9c542ed30cbba5e Mon Sep 17 00:00:00 2001 From: Greg Roodt Date: Mon, 10 Jul 2023 21:59:42 +1000 Subject: [PATCH 1/4] Fix deprecation warnings in Python 3.12 for usage of shutil.rmtree --- src/pip/_internal/utils/misc.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pip/_internal/utils/misc.py b/src/pip/_internal/utils/misc.py index bfed8270252..8afd85d9bed 100644 --- a/src/pip/_internal/utils/misc.py +++ b/src/pip/_internal/utils/misc.py @@ -127,10 +127,13 @@ def get_prog() -> str: # Tenacity raises RetryError by default, explicitly raise the original exception @retry(reraise=True, stop=stop_after_delay(3), wait=wait_fixed(0.5)) def rmtree(dir: str, ignore_errors: bool = False) -> None: - shutil.rmtree(dir, ignore_errors=ignore_errors, onerror=rmtree_errorhandler) + if sys.version_info >= (3, 12): + shutil.rmtree(dir, ignore_errors=ignore_errors, onexc=rmtree_errorhandler) + else: + shutil.rmtree(dir, ignore_errors=ignore_errors, onerror=rmtree_errorhandler) -def rmtree_errorhandler(func: Callable[..., Any], path: str, exc_info: ExcInfo) -> None: +def rmtree_errorhandler(func: Callable[..., Any], path: str, exc_info: Union[ExcInfo, BaseException]) -> None: """On Windows, the files in .svn are read-only, so when rmtree() tries to remove them, an exception is thrown. We catch that here, remove the read-only attribute, and hopefully continue without problems.""" From 9b47bc0fea396caf0cc6a89a404c039c6a44ac40 Mon Sep 17 00:00:00 2001 From: Greg Roodt Date: Mon, 10 Jul 2023 22:04:46 +1000 Subject: [PATCH 2/4] Make black formatter happy --- src/pip/_internal/utils/misc.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pip/_internal/utils/misc.py b/src/pip/_internal/utils/misc.py index 8afd85d9bed..afcf1709e80 100644 --- a/src/pip/_internal/utils/misc.py +++ b/src/pip/_internal/utils/misc.py @@ -133,7 +133,9 @@ def rmtree(dir: str, ignore_errors: bool = False) -> None: shutil.rmtree(dir, ignore_errors=ignore_errors, onerror=rmtree_errorhandler) -def rmtree_errorhandler(func: Callable[..., Any], path: str, exc_info: Union[ExcInfo, BaseException]) -> None: +def rmtree_errorhandler( + func: Callable[..., Any], path: str, exc_info: Union[ExcInfo, BaseException] +) -> None: """On Windows, the files in .svn are read-only, so when rmtree() tries to remove them, an exception is thrown. We catch that here, remove the read-only attribute, and hopefully continue without problems.""" From 41506d7bbf25009f0de06218744082ca4299f666 Mon Sep 17 00:00:00 2001 From: Greg Roodt Date: Tue, 11 Jul 2023 12:11:47 +1000 Subject: [PATCH 3/4] Add news entry --- news/11957.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/11957.bugfix.rst diff --git a/news/11957.bugfix.rst b/news/11957.bugfix.rst new file mode 100644 index 00000000000..96d56ef800f --- /dev/null +++ b/news/11957.bugfix.rst @@ -0,0 +1 @@ +Fix deprecation warnings in Python 3.12 for usage of shutil.rmtree \ No newline at end of file From 2c4947d51a002cd0ba4b01ec7682d86f297e6d37 Mon Sep 17 00:00:00 2001 From: Greg Roodt Date: Tue, 11 Jul 2023 12:14:53 +1000 Subject: [PATCH 4/4] Add news entry --- news/11957.bugfix.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/11957.bugfix.rst b/news/11957.bugfix.rst index 96d56ef800f..8d72e1733a0 100644 --- a/news/11957.bugfix.rst +++ b/news/11957.bugfix.rst @@ -1 +1 @@ -Fix deprecation warnings in Python 3.12 for usage of shutil.rmtree \ No newline at end of file +Fix deprecation warnings in Python 3.12 for usage of shutil.rmtree