From 5f28f83fd995b32a124c79e2dccfd5f2b13f5bd3 Mon Sep 17 00:00:00 2001 From: eggplants Date: Sat, 23 Mar 2024 21:04:32 +0900 Subject: [PATCH 1/3] Fix pip debug error in Python 3.13 --- src/pip/_internal/commands/debug.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pip/_internal/commands/debug.py b/src/pip/_internal/commands/debug.py index 7e5271c9886..9c1f7cd6e1f 100644 --- a/src/pip/_internal/commands/debug.py +++ b/src/pip/_internal/commands/debug.py @@ -35,7 +35,7 @@ def show_sys_implementation() -> None: def create_vendor_txt_map() -> Dict[str, str]: - with importlib.resources.open_text("pip._vendor", "vendor.txt") as f: + with importlib.resources.files("pip._vendor").joinpath("vendor.txt").open("r") as f: # Purge non version specifying lines. # Also, remove any space prefix or suffixes (including comments). lines = [ From b1bc7eebab4bb5c69cacca4e110732ed74b683ae Mon Sep 17 00:00:00 2001 From: eggplants Date: Sat, 23 Mar 2024 21:10:23 +0900 Subject: [PATCH 2/3] Add news fragment for #12590 --- news/12590.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/12590.bugfix.rst diff --git a/news/12590.bugfix.rst b/news/12590.bugfix.rst new file mode 100644 index 00000000000..89e22c68d16 --- /dev/null +++ b/news/12590.bugfix.rst @@ -0,0 +1 @@ +This change fixes ``AttributeError`` while running ``pip debug`` since Python 3.13. From e6ad25ef1a19290920db23b224f76e699e7ab2dc Mon Sep 17 00:00:00 2001 From: eggplants Date: Sat, 23 Mar 2024 22:02:44 +0900 Subject: [PATCH 3/3] Use open_text under Python 3.8 --- src/pip/_internal/commands/debug.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/pip/_internal/commands/debug.py b/src/pip/_internal/commands/debug.py index 9c1f7cd6e1f..a7d4daf88ba 100644 --- a/src/pip/_internal/commands/debug.py +++ b/src/pip/_internal/commands/debug.py @@ -5,7 +5,7 @@ import sys from optparse import Values from types import ModuleType -from typing import Any, Dict, List, Optional +from typing import IO, Any, Dict, List, Optional import pip._vendor from pip._vendor.certifi import where @@ -34,8 +34,19 @@ def show_sys_implementation() -> None: show_value("name", implementation_name) +if sys.version_info < (3, 9): + # Python 3.8 compatibility + def _open_text(package: str, resource: str) -> IO[str]: + return importlib.resources.open_text(package, resource) + +else: + + def _open_text(package: str, resource: str) -> IO[str]: + return importlib.resources.files(package).joinpath(resource).open("r") + + def create_vendor_txt_map() -> Dict[str, str]: - with importlib.resources.files("pip._vendor").joinpath("vendor.txt").open("r") as f: + with _open_text("pip._vendor", "vendor.txt") as f: # Purge non version specifying lines. # Also, remove any space prefix or suffixes (including comments). lines = [