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

Make the debug command safe for use in a zipapp #11248

Merged
merged 2 commits into from
Jul 11, 2022
Merged
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
2 changes: 2 additions & 0 deletions news/11248.bugfix.rst
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 2 additions & 6 deletions src/pip/_internal/commands/debug.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import importlib.resources
import locale
import logging
import os
Expand All @@ -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
Expand All @@ -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 = [
Expand Down