Skip to content

Commit c0fb4bf

Browse files
authored
Merge pull request #11248 from pfmoore/debug_resources
Make the debug command safe for use in a zipapp
2 parents f66b3e8 + 080cd2f commit c0fb4bf

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

news/11248.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Use ``importlib.resources`` to read the ``vendor.txt`` file in ``pip debug``.
2+
This makes the command safe for use from a zipapp.

src/pip/_internal/commands/debug.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import importlib.resources
12
import locale
23
import logging
34
import os
@@ -10,7 +11,6 @@
1011
from pip._vendor.certifi import where
1112
from pip._vendor.packaging.version import parse as parse_version
1213

13-
from pip import __file__ as pip_location
1414
from pip._internal.cli import cmdoptions
1515
from pip._internal.cli.base_command import Command
1616
from pip._internal.cli.cmdoptions import make_target_python
@@ -35,11 +35,7 @@ def show_sys_implementation() -> None:
3535

3636

3737
def create_vendor_txt_map() -> Dict[str, str]:
38-
vendor_txt_path = os.path.join(
39-
os.path.dirname(pip_location), "_vendor", "vendor.txt"
40-
)
41-
42-
with open(vendor_txt_path) as f:
38+
with importlib.resources.open_text("pip._vendor", "vendor.txt") as f:
4339
# Purge non version specifying lines.
4440
# Also, remove any space prefix or suffixes (including comments).
4541
lines = [

0 commit comments

Comments
 (0)