Skip to content

Commit 0807480

Browse files
authored
Merge pull request #12462 from jsirois/3.13/debug/fix
2 parents 7673a51 + 23ab857 commit 0807480

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

news/23f96da0-5535-40c4-ad79-3feb7f694ec2.trivial.rst

Whitespace-only changes.

src/pip/_internal/commands/debug.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import importlib.resources
21
import locale
32
import logging
43
import os
@@ -17,6 +16,7 @@
1716
from pip._internal.cli.status_codes import SUCCESS
1817
from pip._internal.configuration import Configuration
1918
from pip._internal.metadata import get_environment
19+
from pip._internal.utils.compat import open_text_resource
2020
from pip._internal.utils.logging import indent_log
2121
from pip._internal.utils.misc import get_pip_version
2222

@@ -35,7 +35,7 @@ def show_sys_implementation() -> None:
3535

3636

3737
def create_vendor_txt_map() -> Dict[str, str]:
38-
with importlib.resources.open_text("pip._vendor", "vendor.txt") as f:
38+
with open_text_resource("pip._vendor", "vendor.txt") as f:
3939
# Purge non version specifying lines.
4040
# Also, remove any space prefix or suffixes (including comments).
4141
lines = [

src/pip/_internal/utils/compat.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
"""Stuff that differs in different Python versions and platform
22
distributions."""
33

4+
import importlib.resources
45
import logging
56
import os
67
import sys
8+
from typing import IO
79

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

@@ -51,6 +53,20 @@ def get_path_uid(path: str) -> int:
5153
return file_uid
5254

5355

56+
# The importlib.resources.open_text function was deprecated in 3.11 with suggested
57+
# replacement we use below.
58+
if sys.version_info < (3, 11):
59+
open_text_resource = importlib.resources.open_text
60+
else:
61+
62+
def open_text_resource(
63+
package: str, resource: str, encoding: str = "utf-8", errors: str = "strict"
64+
) -> IO[str]:
65+
return (importlib.resources.files(package) / resource).open(
66+
"r", encoding=encoding, errors=errors
67+
)
68+
69+
5470
# packages in the stdlib that may have installation metadata, but should not be
5571
# considered 'installed'. this theoretically could be determined based on
5672
# dist.location (py27:`sysconfig.get_paths()['stdlib']`,

0 commit comments

Comments
 (0)