import importlib.resources import locale import logging import os import sys from optparse import Values from types import ModuleType from typing import Any, Dict, List, Optional
import pip._vendor from pip._vendor.certifi import where from pip._vendor.packaging.version import parse as parse_version
from pip._internal.cli import cmdoptions from pip._internal.cli.base_command import Command from pip._internal.cli.cmdoptions import make_target_python 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.logging import indent_log from pip._internal.utils.misc import get_pip_version
def create_vendor_txt_map() -> Dict[str, str]: 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 = [
line.strip().split(" ", 1)[0] for line in f.readlines() if"=="in line
]
# Transform into "module" -> version dict. return dict(line.split("==", 1) for line in lines)
def get_module_from_module_name(module_name: str) -> Optional[ModuleType]: # Module name can be uppercase in vendor.txt for some reason...
module_name = module_name.lower().replace("-", "_") # PATCH: setuptools is actually only pkg_resources. if module_name == "setuptools":
module_name = "pkg_resources"
try:
__import__(f"pip._vendor.{module_name}", globals(), locals(), level=0) return getattr(pip._vendor, module_name) except ImportError: # We allow 'truststore' to fail to import due # to being unavailable on Python 3.9 and earlier. if module_name == "truststore"and sys.version_info < (3, 10): returnNone raise
if module andnot version: # Try to find version in debundled module info. assert module.__file__ isnotNone
env = get_environment([os.path.dirname(module.__file__)])
dist = env.get_distribution(module_name) if dist:
version = str(dist.version)
return version
def show_actual_vendor_versions(vendor_txt_versions: Dict[str, str]) -> None: """Log the actual version and print extra info if there is
a conflict orif the actual version could not be imported. """ for module_name, expected_version in vendor_txt_versions.items():
extra_message = ""
actual_version = get_vendor_version_from_module(module_name) ifnot actual_version:
extra_message = ( " (Unable to locate actual module version, using" " vendor.txt specified version)"
)
actual_version = expected_version elif parse_version(actual_version) != parse_version(expected_version):
extra_message = ( " (CONFLICT: vendor.txt suggests version should"
f" be {expected_version})"
)
logger.info("%s==%s%s", module_name, actual_version, extra_message)
def run(self, options: Values, args: List[str]) -> int:
logger.warning( "This command is only meant for debugging. " "Do not use this with automation for parsing and getting these " "details, since the output and options of this command may " "change without notice."
)
show_value("pip version", get_pip_version())
show_value("sys.version", sys.version)
show_value("sys.executable", sys.executable)
show_value("sys.getdefaultencoding", sys.getdefaultencoding())
show_value("sys.getfilesystemencoding", sys.getfilesystemencoding())
show_value( "locale.getpreferredencoding",
locale.getpreferredencoding(),
)
show_value("sys.platform", sys.platform)
show_sys_implementation()
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.