[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,5 +1,6 @@
from __future__ import annotations
import fnmatch
import os
import os.path
import random
import shutil
@ -7,18 +8,24 @@ import stat
import sys
from contextlib import contextmanager
from tempfile import NamedTemporaryFile
from typing import Any, BinaryIO, Iterator, List, Union, cast
from pip._vendor.tenacity import retry, stop_after_delay, wait_fixed
from typing import Any
from typing import BinaryIO
from typing import cast
from typing import Iterator
from typing import List
from typing import Union
from pip._internal.utils.compat import get_path_uid
from pip._internal.utils.misc import format_size
from pip._vendor.tenacity import retry
from pip._vendor.tenacity import stop_after_delay
from pip._vendor.tenacity import wait_fixed
def check_path_owner(path: str) -> bool:
# If we don't have a way to check the effective uid of this process, then
# we'll just assume that we own the directory.
if sys.platform == "win32" or not hasattr(os, "geteuid"):
if sys.platform == 'win32' or not hasattr(os, 'geteuid'):
return True
assert os.path.isabs(path)
@ -60,7 +67,7 @@ def copy2_fixed(src: str, dest: str) -> None:
pass
else:
if is_socket_file:
raise shutil.SpecialFileError(f"`{f}` is a socket")
raise shutil.SpecialFileError(f'`{f}` is a socket')
raise
@ -83,7 +90,7 @@ def adjacent_tmp_file(path: str, **kwargs: Any) -> Iterator[BinaryIO]:
delete=False,
dir=os.path.dirname(path),
prefix=os.path.basename(path),
suffix=".tmp",
suffix='.tmp',
**kwargs,
) as f:
result = cast(BinaryIO, f)
@ -114,7 +121,7 @@ def test_writable_dir(path: str) -> bool:
break # Should never get here, but infinite loops are bad
path = parent
if os.name == "posix":
if os.name == 'posix':
return os.access(path, os.W_OK)
return _test_writable_dir_win(path)
@ -123,10 +130,10 @@ def test_writable_dir(path: str) -> bool:
def _test_writable_dir_win(path: str) -> bool:
# os.access doesn't work on Windows: http://bugs.python.org/issue2528
# and we can't use tempfile: http://bugs.python.org/issue22107
basename = "accesstest_deleteme_fishfingers_custard_"
alphabet = "abcdefghijklmnopqrstuvwxyz0123456789"
basename = 'accesstest_deleteme_fishfingers_custard_'
alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789'
for _ in range(10):
name = basename + "".join(random.choice(alphabet) for _ in range(6))
name = basename + ''.join(random.choice(alphabet) for _ in range(6))
file = os.path.join(path, name)
try:
fd = os.open(file, os.O_RDWR | os.O_CREAT | os.O_EXCL)
@ -145,20 +152,20 @@ def _test_writable_dir_win(path: str) -> bool:
return True
# This should never be reached
raise OSError("Unexpected condition testing for writable directory")
raise OSError('Unexpected condition testing for writable directory')
def find_files(path: str, pattern: str) -> List[str]:
def find_files(path: str, pattern: str) -> list[str]:
"""Returns a list of absolute paths of files beneath path, recursively,
with filenames which match the UNIX-style shell glob pattern."""
result: List[str] = []
result: list[str] = []
for root, _, files in os.walk(path):
matches = fnmatch.filter(files, pattern)
result.extend(os.path.join(root, f) for f in matches)
return result
def file_size(path: str) -> Union[int, float]:
def file_size(path: str) -> int | float:
# If it's a symlink, return 0.
if os.path.islink(path):
return 0
@ -169,7 +176,7 @@ def format_file_size(path: str) -> str:
return format_size(file_size(path))
def directory_size(path: str) -> Union[int, float]:
def directory_size(path: str) -> int | float:
size = 0.0
for root, _dirs, files in os.walk(path):
for filename in files: