Skip to content

Commit

Permalink
Merge pull request #12462 from jsirois/3.13/debug/fix
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr authored Mar 26, 2024
2 parents 7673a51 + 23ab857 commit 0807480
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Empty file.
4 changes: 2 additions & 2 deletions src/pip/_internal/commands/debug.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import importlib.resources
import locale
import logging
import os
Expand All @@ -17,6 +16,7 @@
from pip._internal.cli.status_codes import SUCCESS
from pip._internal.configuration import Configuration
from pip._internal.metadata import get_environment
from pip._internal.utils.compat import open_text_resource
from pip._internal.utils.logging import indent_log
from pip._internal.utils.misc import get_pip_version

Expand All @@ -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 open_text_resource("pip._vendor", "vendor.txt") as f:
# Purge non version specifying lines.
# Also, remove any space prefix or suffixes (including comments).
lines = [
Expand Down
16 changes: 16 additions & 0 deletions src/pip/_internal/utils/compat.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Stuff that differs in different Python versions and platform
distributions."""

import importlib.resources
import logging
import os
import sys
from typing import IO

__all__ = ["get_path_uid", "stdlib_pkgs", "WINDOWS"]

Expand Down Expand Up @@ -51,6 +53,20 @@ def get_path_uid(path: str) -> int:
return file_uid


# The importlib.resources.open_text function was deprecated in 3.11 with suggested
# replacement we use below.
if sys.version_info < (3, 11):
open_text_resource = importlib.resources.open_text
else:

def open_text_resource(
package: str, resource: str, encoding: str = "utf-8", errors: str = "strict"
) -> IO[str]:
return (importlib.resources.files(package) / resource).open(
"r", encoding=encoding, errors=errors
)


# packages in the stdlib that may have installation metadata, but should not be
# considered 'installed'. this theoretically could be determined based on
# dist.location (py27:`sysconfig.get_paths()['stdlib']`,
Expand Down

0 comments on commit 0807480

Please sign in to comment.