Skip to content
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

Fix pip debug error in Python 3.13 #12591

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/12590.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This change fixes ``AttributeError`` while running ``pip debug`` since Python 3.13.
15 changes: 13 additions & 2 deletions src/pip/_internal/commands/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.open_text("pip._vendor", "vendor.txt") 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 = [
Expand Down
Loading