[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-04-13 00:00:18 +00:00
parent 72ad6dc953
commit f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions

View file

@ -1,15 +1,17 @@
from __future__ import annotations
import locale
import logging
import os
import sys
from optparse import Values
from types import ModuleType
from typing import Any, Dict, List, Optional
from typing import Any
from typing import Dict
from typing import List
from typing import Optional
import pip._vendor
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
@ -19,51 +21,53 @@ 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
from pip._vendor.certifi import where
from pip._vendor.packaging.version import parse as parse_version
logger = logging.getLogger(__name__)
def show_value(name: str, value: Any) -> None:
logger.info("%s: %s", name, value)
logger.info('%s: %s', name, value)
def show_sys_implementation() -> None:
logger.info("sys.implementation:")
logger.info('sys.implementation:')
implementation_name = sys.implementation.name
with indent_log():
show_value("name", implementation_name)
show_value('name', implementation_name)
def create_vendor_txt_map() -> Dict[str, str]:
def create_vendor_txt_map() -> dict[str, str]:
vendor_txt_path = os.path.join(
os.path.dirname(pip_location), "_vendor", "vendor.txt"
os.path.dirname(pip_location), '_vendor', 'vendor.txt',
)
with open(vendor_txt_path) 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
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) # type: ignore
return dict(line.split('==', 1) for line in lines) # type: ignore
def get_module_from_module_name(module_name: str) -> ModuleType:
# Module name can be uppercase in vendor.txt for some reason...
module_name = module_name.lower()
# PATCH: setuptools is actually only pkg_resources.
if module_name == "setuptools":
module_name = "pkg_resources"
if module_name == 'setuptools':
module_name = 'pkg_resources'
__import__(f"pip._vendor.{module_name}", globals(), locals(), level=0)
__import__(f'pip._vendor.{module_name}', globals(), locals(), level=0)
return getattr(pip._vendor, module_name)
def get_vendor_version_from_module(module_name: str) -> Optional[str]:
def get_vendor_version_from_module(module_name: str) -> str | None:
module = get_module_from_module_name(module_name)
version = getattr(module, "__version__", None)
version = getattr(module, '__version__', None)
if not version:
# Try to find version in debundled module info.
@ -75,29 +79,29 @@ def get_vendor_version_from_module(module_name: str) -> Optional[str]:
return version
def show_actual_vendor_versions(vendor_txt_versions: Dict[str, str]) -> None:
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 or if the actual version could not be imported.
"""
for module_name, expected_version in vendor_txt_versions.items():
extra_message = ""
extra_message = ''
actual_version = get_vendor_version_from_module(module_name)
if not actual_version:
extra_message = (
" (Unable to locate actual module version, using"
" vendor.txt specified version)"
' (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"
" be {})".format(expected_version)
' (CONFLICT: vendor.txt suggests version should'
' be {})'.format(expected_version)
)
logger.info("%s==%s%s", module_name, actual_version, extra_message)
logger.info('%s==%s%s', module_name, actual_version, extra_message)
def show_vendor_versions() -> None:
logger.info("vendored library versions:")
logger.info('vendored library versions:')
vendor_txt_versions = create_vendor_txt_map()
with indent_log():
@ -112,11 +116,11 @@ def show_tags(options: Values) -> None:
# Display the target options that were explicitly provided.
formatted_target = target_python.format_given()
suffix = ""
suffix = ''
if formatted_target:
suffix = f" (target: {formatted_target})"
suffix = f' (target: {formatted_target})'
msg = "Compatible tags: {}{}".format(len(tags), suffix)
msg = f'Compatible tags: {len(tags)}{suffix}'
logger.info(msg)
if options.verbose < 1 and len(tags) > tag_limit:
@ -131,7 +135,7 @@ def show_tags(options: Values) -> None:
if tags_limited:
msg = (
"...\n[First {tag_limit} tags shown. Pass --verbose to show all.]"
'...\n[First {tag_limit} tags shown. Pass --verbose to show all.]'
).format(tag_limit=tag_limit)
logger.info(msg)
@ -139,21 +143,21 @@ def show_tags(options: Values) -> None:
def ca_bundle_info(config: Configuration) -> str:
levels = set()
for key, _ in config.items():
levels.add(key.split(".")[0])
levels.add(key.split('.')[0])
if not levels:
return "Not specified"
return 'Not specified'
levels_that_override_global = ["install", "wheel", "download"]
levels_that_override_global = ['install', 'wheel', 'download']
global_overriding_level = [
level for level in levels if level in levels_that_override_global
]
if not global_overriding_level:
return "global"
return 'global'
if "global" in levels:
levels.remove("global")
return ", ".join(levels)
if 'global' in levels:
levels.remove('global')
return ', '.join(levels)
class DebugCommand(Command):
@ -170,30 +174,30 @@ class DebugCommand(Command):
self.parser.insert_option_group(0, self.cmd_opts)
self.parser.config.load()
def run(self, options: Values, args: List[str]) -> int:
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."
'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('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',
locale.getpreferredencoding(),
)
show_value("sys.platform", sys.platform)
show_value('sys.platform', sys.platform)
show_sys_implementation()
show_value("'cert' config value", ca_bundle_info(self.parser.config))
show_value("REQUESTS_CA_BUNDLE", os.environ.get("REQUESTS_CA_BUNDLE"))
show_value("CURL_CA_BUNDLE", os.environ.get("CURL_CA_BUNDLE"))
show_value("pip._vendor.certifi.where()", where())
show_value("pip._vendor.DEBUNDLED", pip._vendor.DEBUNDLED)
show_value('REQUESTS_CA_BUNDLE', os.environ.get('REQUESTS_CA_BUNDLE'))
show_value('CURL_CA_BUNDLE', os.environ.get('CURL_CA_BUNDLE'))
show_value('pip._vendor.certifi.where()', where())
show_value('pip._vendor.DEBUNDLED', pip._vendor.DEBUNDLED)
show_vendor_versions()