[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,14 +1,16 @@
import os
import sys
import tempfile
import operator
from __future__ import annotations
import builtins
import contextlib
import functools
import itertools
import re
import contextlib
import operator
import os
import pickle
import re
import sys
import tempfile
import textwrap
import builtins
import pkg_resources
from distutils.errors import DistutilsError
@ -26,10 +28,10 @@ _open = open
__all__ = [
"AbstractSandbox",
"DirectorySandbox",
"SandboxViolation",
"run_setup",
'AbstractSandbox',
'DirectorySandbox',
'SandboxViolation',
'run_setup',
]
@ -134,7 +136,7 @@ class ExceptionSaver:
return True
def resume(self):
"restore and re-raise any exception"
'restore and re-raise any exception'
if '_saved' not in vars(self):
return
@ -160,9 +162,9 @@ def save_modules():
del_modules = (
mod_name
for mod_name in sys.modules
if mod_name not in saved
if mod_name not in saved and
# exclude any encodings modules. See #285
and not mod_name.startswith('encodings.')
not mod_name.startswith('encodings.')
)
_clear_modules(del_modules)
@ -308,7 +310,7 @@ class AbstractSandbox:
return wrap
for name in ["rename", "link", "symlink"]:
for name in ['rename', 'link', 'symlink']:
if hasattr(_os, name):
locals()[name] = _mk_dual_path_wrapper(name)
@ -326,25 +328,25 @@ class AbstractSandbox:
_file = _mk_single_path_wrapper('file', _file)
_open = _mk_single_path_wrapper('open', _open)
for name in [
"stat",
"listdir",
"chdir",
"open",
"chmod",
"chown",
"mkdir",
"remove",
"unlink",
"rmdir",
"utime",
"lchown",
"chroot",
"lstat",
"startfile",
"mkfifo",
"mknod",
"pathconf",
"access",
'stat',
'listdir',
'chdir',
'open',
'chmod',
'chown',
'mkdir',
'remove',
'unlink',
'rmdir',
'utime',
'lchown',
'chroot',
'lstat',
'startfile',
'mkfifo',
'mknod',
'pathconf',
'access',
]:
if hasattr(_os, name):
locals()[name] = _mk_single_path_wrapper(name)
@ -410,24 +412,24 @@ class DirectorySandbox(AbstractSandbox):
write_ops = dict.fromkeys(
[
"open",
"chmod",
"chown",
"mkdir",
"remove",
"unlink",
"rmdir",
"utime",
"lchown",
"chroot",
"mkfifo",
"mknod",
"tempnam",
]
'open',
'chmod',
'chown',
'mkdir',
'remove',
'unlink',
'rmdir',
'utime',
'lchown',
'chroot',
'mkfifo',
'mknod',
'tempnam',
],
)
_exception_patterns = []
"exempt writing to paths that match the pattern"
'exempt writing to paths that match the pattern'
def __init__(self, sandbox, exceptions=_EXCEPTIONS):
self._sandbox = os.path.normcase(os.path.realpath(sandbox))
@ -446,16 +448,16 @@ class DirectorySandbox(AbstractSandbox):
def _file(self, path, mode='r', *args, **kw):
if mode not in ('r', 'rt', 'rb', 'rU', 'U') and not self._ok(path):
self._violation("file", path, mode, *args, **kw)
self._violation('file', path, mode, *args, **kw)
return _file(path, mode, *args, **kw)
def _open(self, path, mode='r', *args, **kw):
if mode not in ('r', 'rt', 'rb', 'rU', 'U') and not self._ok(path):
self._violation("open", path, mode, *args, **kw)
self._violation('open', path, mode, *args, **kw)
return _open(path, mode, *args, **kw)
def tmpnam(self):
self._violation("tmpnam")
self._violation('tmpnam')
def _ok(self, path):
active = self._active
@ -463,9 +465,9 @@ class DirectorySandbox(AbstractSandbox):
self._active = False
realpath = os.path.normcase(os.path.realpath(path))
return (
self._exempted(realpath)
or realpath == self._sandbox
or realpath.startswith(self._prefix)
self._exempted(realpath) or
realpath == self._sandbox or
realpath.startswith(self._prefix)
)
finally:
self._active = active
@ -495,7 +497,7 @@ class DirectorySandbox(AbstractSandbox):
def open(self, file, flags, mode=0o777, *args, **kw):
"""Called for low-level os.open()"""
if flags & WRITE_FLAGS and not self._ok(file):
self._violation("os.open", file, flags, mode, *args, **kw)
self._violation('os.open', file, flags, mode, *args, **kw)
return _os.open(file, flags, mode, *args, **kw)
@ -503,7 +505,7 @@ WRITE_FLAGS = functools.reduce(
operator.or_,
[
getattr(_os, a, 0)
for a in "O_WRONLY O_RDWR O_APPEND O_CREAT O_TRUNC O_TEMPORARY".split()
for a in 'O_WRONLY O_RDWR O_APPEND O_CREAT O_TRUNC O_TEMPORARY'.split()
],
)
@ -522,7 +524,7 @@ class SandboxViolation(DistutilsError):
support alternate installation locations even if you run its setup
script by hand. Please inform the package's author and the EasyInstall
maintainers to find out if a fix or workaround is available.
"""
""",
).lstrip()
def __str__(self):