[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,45 +1,46 @@
from __future__ import annotations
import logging
import os
import re
from typing import List, Optional, Tuple
from typing import List
from typing import Optional
from typing import Tuple
from pip._internal.utils.misc import (
HiddenText,
display_path,
is_console_interactive,
is_installable_dir,
split_auth_from_netloc,
)
from pip._internal.utils.subprocess import CommandArgs, make_command
from pip._internal.vcs.versioncontrol import (
AuthInfo,
RemoteNotFoundError,
RevOptions,
VersionControl,
vcs,
)
from pip._internal.utils.misc import display_path
from pip._internal.utils.misc import HiddenText
from pip._internal.utils.misc import is_console_interactive
from pip._internal.utils.misc import is_installable_dir
from pip._internal.utils.misc import split_auth_from_netloc
from pip._internal.utils.subprocess import CommandArgs
from pip._internal.utils.subprocess import make_command
from pip._internal.vcs.versioncontrol import AuthInfo
from pip._internal.vcs.versioncontrol import RemoteNotFoundError
from pip._internal.vcs.versioncontrol import RevOptions
from pip._internal.vcs.versioncontrol import vcs
from pip._internal.vcs.versioncontrol import VersionControl
logger = logging.getLogger(__name__)
_svn_xml_url_re = re.compile('url="([^"]+)"')
_svn_rev_re = re.compile(r'committed-rev="(\d+)"')
_svn_info_xml_rev_re = re.compile(r'\s*revision="(\d+)"')
_svn_info_xml_url_re = re.compile(r"<url>(.*)</url>")
_svn_info_xml_url_re = re.compile(r'<url>(.*)</url>')
class Subversion(VersionControl):
name = "svn"
dirname = ".svn"
repo_name = "checkout"
schemes = ("svn+ssh", "svn+http", "svn+https", "svn+svn", "svn+file")
name = 'svn'
dirname = '.svn'
repo_name = 'checkout'
schemes = ('svn+ssh', 'svn+http', 'svn+https', 'svn+svn', 'svn+file')
@classmethod
def should_add_vcs_url_prefix(cls, remote_url: str) -> bool:
return True
@staticmethod
def get_base_rev_args(rev: str) -> List[str]:
return ["-r", rev]
def get_base_rev_args(rev: str) -> list[str]:
return ['-r', rev]
@classmethod
def get_revision(cls, location: str) -> str:
@ -54,7 +55,7 @@ class Subversion(VersionControl):
dirs[:] = []
continue # no sense walking uncontrolled subdirs
dirs.remove(cls.dirname)
entries_fn = os.path.join(base, cls.dirname, "entries")
entries_fn = os.path.join(base, cls.dirname, 'entries')
if not os.path.exists(entries_fn):
# FIXME: should we warn?
continue
@ -63,7 +64,7 @@ class Subversion(VersionControl):
if base == location:
assert dirurl is not None
base = dirurl + "/" # save the root url
base = dirurl + '/' # save the root url
elif not dirurl or not dirurl.startswith(base):
dirs[:] = []
continue # not part of the same svn tree, skip it
@ -72,13 +73,13 @@ class Subversion(VersionControl):
@classmethod
def get_netloc_and_auth(
cls, netloc: str, scheme: str
) -> Tuple[str, Tuple[Optional[str], Optional[str]]]:
cls, netloc: str, scheme: str,
) -> tuple[str, tuple[str | None, str | None]]:
"""
This override allows the auth information to be passed to svn via the
--username and --password options instead of via the URL.
"""
if scheme == "ssh":
if scheme == 'ssh':
# The --username and --password options can't be used for
# svn+ssh URLs, so keep the auth information in the URL.
return super().get_netloc_and_auth(netloc, scheme)
@ -86,22 +87,22 @@ class Subversion(VersionControl):
return split_auth_from_netloc(netloc)
@classmethod
def get_url_rev_and_auth(cls, url: str) -> Tuple[str, Optional[str], AuthInfo]:
def get_url_rev_and_auth(cls, url: str) -> tuple[str, str | None, AuthInfo]:
# hotfix the URL scheme after removing svn+ from svn+ssh:// readd it
url, rev, user_pass = super().get_url_rev_and_auth(url)
if url.startswith("ssh://"):
url = "svn+" + url
if url.startswith('ssh://'):
url = 'svn+' + url
return url, rev, user_pass
@staticmethod
def make_rev_args(
username: Optional[str], password: Optional[HiddenText]
username: str | None, password: HiddenText | None,
) -> CommandArgs:
extra_args: CommandArgs = []
if username:
extra_args += ["--username", username]
extra_args += ['--username', username]
if password:
extra_args += ["--password", password]
extra_args += ['--password', password]
return extra_args
@ -117,8 +118,8 @@ class Subversion(VersionControl):
# We've traversed up to the root of the filesystem without
# finding a Python project.
logger.warning(
"Could not find Python project for directory %s (tried all "
"parent directories)",
'Could not find Python project for directory %s (tried all '
'parent directories)',
orig_location,
)
raise RemoteNotFoundError
@ -130,26 +131,26 @@ class Subversion(VersionControl):
return url
@classmethod
def _get_svn_url_rev(cls, location: str) -> Tuple[Optional[str], int]:
def _get_svn_url_rev(cls, location: str) -> tuple[str | None, int]:
from pip._internal.exceptions import InstallationError
entries_path = os.path.join(location, cls.dirname, "entries")
entries_path = os.path.join(location, cls.dirname, 'entries')
if os.path.exists(entries_path):
with open(entries_path) as f:
data = f.read()
else: # subversion >= 1.7 does not have the 'entries' file
data = ""
data = ''
url = None
if data.startswith("8") or data.startswith("9") or data.startswith("10"):
entries = list(map(str.splitlines, data.split("\n\x0c\n")))
if data.startswith('8') or data.startswith('9') or data.startswith('10'):
entries = list(map(str.splitlines, data.split('\n\x0c\n')))
del entries[0][0] # get rid of the '8'
url = entries[0][3]
revs = [int(d[9]) for d in entries if len(d) > 9 and d[9]] + [0]
elif data.startswith("<?xml"):
elif data.startswith('<?xml'):
match = _svn_xml_url_re.search(data)
if not match:
raise ValueError(f"Badly formatted data: {data!r}")
raise ValueError(f'Badly formatted data: {data!r}')
url = match.group(1) # get repository URL
revs = [int(m.group(1)) for m in _svn_rev_re.finditer(data)] + [0]
else:
@ -161,7 +162,7 @@ class Subversion(VersionControl):
# is being used to prompt for passwords, because passwords
# are only potentially needed for remote server requests.
xml = cls.run_command(
["info", "--xml", location],
['info', '--xml', location],
show_stdout=False,
stdout_only=True,
)
@ -180,7 +181,7 @@ class Subversion(VersionControl):
return url, rev
@classmethod
def is_commit_id_equal(cls, dest: str, name: Optional[str]) -> bool:
def is_commit_id_equal(cls, dest: str, name: str | None) -> bool:
"""Always assume the versions don't match"""
return False
@ -194,11 +195,11 @@ class Subversion(VersionControl):
# Special value definitions:
# None: Not evaluated yet.
# Empty tuple: Could not parse version.
self._vcs_version: Optional[Tuple[int, ...]] = None
self._vcs_version: tuple[int, ...] | None = None
super().__init__()
def call_vcs_version(self) -> Tuple[int, ...]:
def call_vcs_version(self) -> tuple[int, ...]:
"""Query the version of the currently installed Subversion client.
:return: A tuple containing the parts of the version information or
@ -212,13 +213,13 @@ class Subversion(VersionControl):
# compiled Mar 28 2018, 08:49:13 on x86_64-pc-linux-gnu
# svn, version 1.12.0-SlikSvn (SlikSvn/1.12.0)
# compiled May 28 2019, 13:44:56 on x86_64-microsoft-windows6.2
version_prefix = "svn, version "
version = self.run_command(["--version"], show_stdout=False, stdout_only=True)
version_prefix = 'svn, version '
version = self.run_command(['--version'], show_stdout=False, stdout_only=True)
if not version.startswith(version_prefix):
return ()
version = version[len(version_prefix) :].split()[0]
version_list = version.partition("-")[0].split(".")
version = version[len(version_prefix):].split()[0]
version_list = version.partition('-')[0].split('.')
try:
parsed_version = tuple(map(int, version_list))
except ValueError:
@ -226,7 +227,7 @@ class Subversion(VersionControl):
return parsed_version
def get_vcs_version(self) -> Tuple[int, ...]:
def get_vcs_version(self) -> tuple[int, ...]:
"""Return the version of the currently installed Subversion client.
If the version of the Subversion client has already been queried,
@ -261,7 +262,7 @@ class Subversion(VersionControl):
if not self.use_interactive:
# --non-interactive switch is available since Subversion 0.14.4.
# Subversion < 1.8 runs in interactive mode by default.
return ["--non-interactive"]
return ['--non-interactive']
svn_version = self.get_vcs_version()
# By default, Subversion >= 1.8 runs in non-interactive mode if
@ -273,26 +274,26 @@ class Subversion(VersionControl):
# SVN 1.7, pip should continue to support SVN 1.7. Therefore, pip
# can't safely add the option if the SVN version is < 1.8 (or unknown).
if svn_version >= (1, 8):
return ["--force-interactive"]
return ['--force-interactive']
return []
def fetch_new(
self, dest: str, url: HiddenText, rev_options: RevOptions, verbosity: int
self, dest: str, url: HiddenText, rev_options: RevOptions, verbosity: int,
) -> None:
rev_display = rev_options.to_display()
logger.info(
"Checking out %s%s to %s",
'Checking out %s%s to %s',
url,
rev_display,
display_path(dest),
)
if verbosity <= 0:
flag = "--quiet"
flag = '--quiet'
else:
flag = ""
flag = ''
cmd_args = make_command(
"checkout",
'checkout',
flag,
self.get_remote_call_options(),
rev_options.to_args(),
@ -303,7 +304,7 @@ class Subversion(VersionControl):
def switch(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
cmd_args = make_command(
"switch",
'switch',
self.get_remote_call_options(),
rev_options.to_args(),
url,
@ -313,7 +314,7 @@ class Subversion(VersionControl):
def update(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
cmd_args = make_command(
"update",
'update',
self.get_remote_call_options(),
rev_options.to_args(),
dest,