From c70dcc7f1dd271c8f22d1795dbb6479cd0e09ee3 Mon Sep 17 00:00:00 2001
From: Paul Moore
Date: Mon, 11 Jul 2022 16:30:32 +0100
Subject: [PATCH 1/2] Make the debug command safe for use in a zipapp
---
src/pip/_internal/commands/debug.py | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/src/pip/_internal/commands/debug.py b/src/pip/_internal/commands/debug.py
index 084d7fa980c..6fad1fe8943 100644
--- a/src/pip/_internal/commands/debug.py
+++ b/src/pip/_internal/commands/debug.py
@@ -1,3 +1,4 @@
+import importlib.resources
import locale
import logging
import os
@@ -10,7 +11,6 @@
from pip._vendor.certifi import where
from pip._vendor.packaging.version import parse as parse_version
-from pip import __file__ as pip_location
from pip._internal.cli import cmdoptions
from pip._internal.cli.base_command import Command
from pip._internal.cli.cmdoptions import make_target_python
@@ -35,11 +35,7 @@ def show_sys_implementation() -> None:
def create_vendor_txt_map() -> Dict[str, str]:
- vendor_txt_path = os.path.join(
- os.path.dirname(pip_location), "_vendor", "vendor.txt"
- )
-
- with open(vendor_txt_path) as f:
+ with importlib.resources.open_text("pip._vendor", "vendor.txt") as f:
# Purge non version specifying lines.
# Also, remove any space prefix or suffixes (including comments).
lines = [
From 080cd2f8e3b36a475a0296d53d0c855f87389828 Mon Sep 17 00:00:00 2001
From: Paul Moore
Date: Mon, 11 Jul 2022 16:33:41 +0100
Subject: [PATCH 2/2] Add a news file
---
news/11248.bugfix.rst | 2 ++
1 file changed, 2 insertions(+)
create mode 100644 news/11248.bugfix.rst
diff --git a/news/11248.bugfix.rst b/news/11248.bugfix.rst
new file mode 100644
index 00000000000..c48146973cd
--- /dev/null
+++ b/news/11248.bugfix.rst
@@ -0,0 +1,2 @@
+Use ``importlib.resources`` to read the ``vendor.txt`` file in ``pip debug``.
+This makes the command safe for use from a zipapp.