mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-10 21:34:18 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
72ad6dc953
commit
f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions
|
|
@ -1,4 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import annotations
|
||||
__all__ = ['Distribution']
|
||||
|
||||
import io
|
||||
|
|
@ -48,7 +48,7 @@ __import__('setuptools.extern.packaging.version')
|
|||
|
||||
|
||||
def _get_unpatched(cls):
|
||||
warnings.warn("Do not call this function", DistDeprecationWarning)
|
||||
warnings.warn('Do not call this function', DistDeprecationWarning)
|
||||
return get_unpatched(cls)
|
||||
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ def rfc822_unescape(content: str) -> str:
|
|||
return '\n'.join((lines[0].lstrip(), textwrap.dedent('\n'.join(lines[1:]))))
|
||||
|
||||
|
||||
def _read_field_from_msg(msg: "Message", field: str) -> Optional[str]:
|
||||
def _read_field_from_msg(msg: Message, field: str) -> str | None:
|
||||
"""Read Message header field."""
|
||||
value = msg[field]
|
||||
if value == 'UNKNOWN':
|
||||
|
|
@ -76,7 +76,7 @@ def _read_field_from_msg(msg: "Message", field: str) -> Optional[str]:
|
|||
return value
|
||||
|
||||
|
||||
def _read_field_unescaped_from_msg(msg: "Message", field: str) -> Optional[str]:
|
||||
def _read_field_unescaped_from_msg(msg: Message, field: str) -> str | None:
|
||||
"""Read Message header field and apply rfc822_unescape."""
|
||||
value = _read_field_from_msg(msg, field)
|
||||
if value is None:
|
||||
|
|
@ -84,7 +84,7 @@ def _read_field_unescaped_from_msg(msg: "Message", field: str) -> Optional[str]:
|
|||
return rfc822_unescape(value)
|
||||
|
||||
|
||||
def _read_list_from_msg(msg: "Message", field: str) -> Optional[List[str]]:
|
||||
def _read_list_from_msg(msg: Message, field: str) -> list[str] | None:
|
||||
"""Read Message header field and return all results as list."""
|
||||
values = msg.get_all(field, None)
|
||||
if values == []:
|
||||
|
|
@ -92,7 +92,7 @@ def _read_list_from_msg(msg: "Message", field: str) -> Optional[List[str]]:
|
|||
return values
|
||||
|
||||
|
||||
def _read_payload_from_msg(msg: "Message") -> Optional[str]:
|
||||
def _read_payload_from_msg(msg: Message) -> str | None:
|
||||
value = msg.get_payload().strip()
|
||||
if value == 'UNKNOWN':
|
||||
return None
|
||||
|
|
@ -148,7 +148,7 @@ def single_line(val):
|
|||
# quick and dirty validation for description pypa/setuptools#1390
|
||||
if '\n' in val:
|
||||
# TODO after 2021-07-31: Replace with `raise ValueError("newlines not allowed")`
|
||||
warnings.warn("newlines not allowed and will break in the future")
|
||||
warnings.warn('newlines not allowed and will break in the future')
|
||||
val = val.replace('\n', ' ')
|
||||
return val
|
||||
|
||||
|
|
@ -159,7 +159,7 @@ def write_pkg_file(self, file): # noqa: C901 # is too complex (14) # FIXME
|
|||
version = self.get_metadata_version()
|
||||
|
||||
def write_field(key, value):
|
||||
file.write("%s: %s\n" % (key, value))
|
||||
file.write('{}: {}\n'.format(key, value))
|
||||
|
||||
write_field('Metadata-Version', str(version))
|
||||
write_field('Name', self.get_name())
|
||||
|
|
@ -213,7 +213,7 @@ def write_pkg_file(self, file): # noqa: C901 # is too complex (14) # FIXME
|
|||
|
||||
self._write_list(file, 'License-File', self.license_files or [])
|
||||
|
||||
file.write("\n%s\n\n" % self.get_long_description())
|
||||
file.write('\n%s\n\n' % self.get_long_description())
|
||||
|
||||
|
||||
sequence = tuple, list
|
||||
|
|
@ -225,7 +225,7 @@ def check_importable(dist, attr, value):
|
|||
assert not ep.extras
|
||||
except (TypeError, ValueError, AttributeError, AssertionError) as e:
|
||||
raise DistutilsSetupError(
|
||||
"%r must be importable 'module:attrs' string (got %r)" % (attr, value)
|
||||
"{!r} must be importable 'module:attrs' string (got {!r})".format(attr, value),
|
||||
) from e
|
||||
|
||||
|
||||
|
|
@ -239,7 +239,7 @@ def assert_string_list(dist, attr, value):
|
|||
assert ''.join(value) != value
|
||||
except (TypeError, ValueError, AttributeError, AssertionError) as e:
|
||||
raise DistutilsSetupError(
|
||||
"%r must be a list of strings (got %r)" % (attr, value)
|
||||
'{!r} must be a list of strings (got {!r})'.format(attr, value),
|
||||
) from e
|
||||
|
||||
|
||||
|
|
@ -250,14 +250,14 @@ def check_nsp(dist, attr, value):
|
|||
for nsp in ns_packages:
|
||||
if not dist.has_contents_for(nsp):
|
||||
raise DistutilsSetupError(
|
||||
"Distribution contains no modules or packages for "
|
||||
+ "namespace package %r" % nsp
|
||||
'Distribution contains no modules or packages for ' +
|
||||
'namespace package %r' % nsp,
|
||||
)
|
||||
parent, sep, child = nsp.rpartition('.')
|
||||
if parent and parent not in ns_packages:
|
||||
distutils.log.warn(
|
||||
"WARNING: %r is declared as a package namespace, but %r"
|
||||
" is not: please correct this in setup.py",
|
||||
'WARNING: %r is declared as a package namespace, but %r'
|
||||
' is not: please correct this in setup.py',
|
||||
nsp,
|
||||
parent,
|
||||
)
|
||||
|
|
@ -270,30 +270,30 @@ def check_extras(dist, attr, value):
|
|||
except (TypeError, ValueError, AttributeError) as e:
|
||||
raise DistutilsSetupError(
|
||||
"'extras_require' must be a dictionary whose values are "
|
||||
"strings or lists of strings containing valid project/version "
|
||||
"requirement specifiers."
|
||||
'strings or lists of strings containing valid project/version '
|
||||
'requirement specifiers.',
|
||||
) from e
|
||||
|
||||
|
||||
def _check_extra(extra, reqs):
|
||||
name, sep, marker = extra.partition(':')
|
||||
if marker and pkg_resources.invalid_marker(marker):
|
||||
raise DistutilsSetupError("Invalid environment marker: " + marker)
|
||||
raise DistutilsSetupError('Invalid environment marker: ' + marker)
|
||||
list(pkg_resources.parse_requirements(reqs))
|
||||
|
||||
|
||||
def assert_bool(dist, attr, value):
|
||||
"""Verify that value is True, False, 0, or 1"""
|
||||
if bool(value) != value:
|
||||
tmpl = "{attr!r} must be a boolean value (got {value!r})"
|
||||
tmpl = '{attr!r} must be a boolean value (got {value!r})'
|
||||
raise DistutilsSetupError(tmpl.format(attr=attr, value=value))
|
||||
|
||||
|
||||
def invalid_unless_false(dist, attr, value):
|
||||
if not value:
|
||||
warnings.warn(f"{attr} is ignored.", DistDeprecationWarning)
|
||||
warnings.warn(f'{attr} is ignored.', DistDeprecationWarning)
|
||||
return
|
||||
raise DistutilsSetupError(f"{attr} is invalid.")
|
||||
raise DistutilsSetupError(f'{attr} is invalid.')
|
||||
|
||||
|
||||
def check_requirements(dist, attr, value):
|
||||
|
|
@ -301,11 +301,11 @@ def check_requirements(dist, attr, value):
|
|||
try:
|
||||
list(pkg_resources.parse_requirements(value))
|
||||
if isinstance(value, (dict, set)):
|
||||
raise TypeError("Unordered types are not allowed")
|
||||
raise TypeError('Unordered types are not allowed')
|
||||
except (TypeError, ValueError) as error:
|
||||
tmpl = (
|
||||
"{attr!r} must be a string or list of strings "
|
||||
"containing valid project/version requirement specifiers; {error}"
|
||||
'{attr!r} must be a string or list of strings '
|
||||
'containing valid project/version requirement specifiers; {error}'
|
||||
)
|
||||
raise DistutilsSetupError(tmpl.format(attr=attr, error=error)) from error
|
||||
|
||||
|
|
@ -316,7 +316,7 @@ def check_specifier(dist, attr, value):
|
|||
packaging.specifiers.SpecifierSet(value)
|
||||
except (packaging.specifiers.InvalidSpecifier, AttributeError) as error:
|
||||
tmpl = (
|
||||
"{attr!r} must be a string " "containing valid version specifiers; {error}"
|
||||
'{attr!r} must be a string ' 'containing valid version specifiers; {error}'
|
||||
)
|
||||
raise DistutilsSetupError(tmpl.format(attr=attr, error=error)) from error
|
||||
|
||||
|
|
@ -331,30 +331,30 @@ def check_entry_points(dist, attr, value):
|
|||
|
||||
def check_test_suite(dist, attr, value):
|
||||
if not isinstance(value, str):
|
||||
raise DistutilsSetupError("test_suite must be a string")
|
||||
raise DistutilsSetupError('test_suite must be a string')
|
||||
|
||||
|
||||
def check_package_data(dist, attr, value):
|
||||
"""Verify that value is a dictionary of package names to glob lists"""
|
||||
if not isinstance(value, dict):
|
||||
raise DistutilsSetupError(
|
||||
"{!r} must be a dictionary mapping package names to lists of "
|
||||
"string wildcard patterns".format(attr)
|
||||
'{!r} must be a dictionary mapping package names to lists of '
|
||||
'string wildcard patterns'.format(attr),
|
||||
)
|
||||
for k, v in value.items():
|
||||
if not isinstance(k, str):
|
||||
raise DistutilsSetupError(
|
||||
"keys of {!r} dict must be strings (got {!r})".format(attr, k)
|
||||
f'keys of {attr!r} dict must be strings (got {k!r})',
|
||||
)
|
||||
assert_string_list(dist, 'values of {!r} dict'.format(attr), v)
|
||||
assert_string_list(dist, f'values of {attr!r} dict', v)
|
||||
|
||||
|
||||
def check_packages(dist, attr, value):
|
||||
for pkgname in value:
|
||||
if not re.match(r'\w+(\.\w+)*', pkgname):
|
||||
distutils.log.warn(
|
||||
"WARNING: %r not a valid package name; please use only "
|
||||
".-separated package names in setup.py",
|
||||
'WARNING: %r not a valid package name; please use only '
|
||||
'.-separated package names in setup.py',
|
||||
pkgname,
|
||||
)
|
||||
|
||||
|
|
@ -438,13 +438,13 @@ class Distribution(_Distribution):
|
|||
self._patched_dist = dist
|
||||
|
||||
def __init__(self, attrs=None):
|
||||
have_package_data = hasattr(self, "package_data")
|
||||
have_package_data = hasattr(self, 'package_data')
|
||||
if not have_package_data:
|
||||
self.package_data = {}
|
||||
attrs = attrs or {}
|
||||
self.dist_files = []
|
||||
# Filter-out setuptools' specific options.
|
||||
self.src_root = attrs.pop("src_root", None)
|
||||
self.src_root = attrs.pop('src_root', None)
|
||||
self.patch_missing_pkg_info(attrs)
|
||||
self.dependency_links = attrs.pop('dependency_links', [])
|
||||
self.setup_requires = attrs.pop('setup_requires', [])
|
||||
|
|
@ -462,7 +462,7 @@ class Distribution(_Distribution):
|
|||
self._set_metadata_defaults(attrs)
|
||||
|
||||
self.metadata.version = self._normalize_version(
|
||||
self._validate_version(self.metadata.version)
|
||||
self._validate_version(self.metadata.version),
|
||||
)
|
||||
self._finalize_requires()
|
||||
|
||||
|
|
@ -499,10 +499,10 @@ class Distribution(_Distribution):
|
|||
packaging.version.Version(version)
|
||||
except (packaging.version.InvalidVersion, TypeError):
|
||||
warnings.warn(
|
||||
"The version specified (%r) is an invalid version, this "
|
||||
"may not work as expected with newer versions of "
|
||||
"setuptools, pip, and PyPI. Please see PEP 440 for more "
|
||||
"details." % version
|
||||
'The version specified (%r) is an invalid version, this '
|
||||
'may not work as expected with newer versions of '
|
||||
'setuptools, pip, and PyPI. Please see PEP 440 for more '
|
||||
'details.' % version,
|
||||
)
|
||||
return setuptools.sic(version)
|
||||
return version
|
||||
|
|
@ -571,10 +571,10 @@ class Distribution(_Distribution):
|
|||
|
||||
for r in complex_reqs:
|
||||
self._tmp_extras_require[':' + str(r.marker)].append(r)
|
||||
self.extras_require = dict(
|
||||
(k, [str(r) for r in map(self._clean_req, v)])
|
||||
self.extras_require = {
|
||||
k: [str(r) for r in map(self._clean_req, v)]
|
||||
for k, v in self._tmp_extras_require.items()
|
||||
)
|
||||
}
|
||||
|
||||
def _clean_req(self, req):
|
||||
"""
|
||||
|
|
@ -585,10 +585,10 @@ class Distribution(_Distribution):
|
|||
|
||||
def _finalize_license_files(self):
|
||||
"""Compute names of all license files which should be included."""
|
||||
license_files: Optional[List[str]] = self.metadata.license_files
|
||||
patterns: List[str] = license_files if license_files else []
|
||||
license_files: list[str] | None = self.metadata.license_files
|
||||
patterns: list[str] = license_files if license_files else []
|
||||
|
||||
license_file: Optional[str] = self.metadata.license_file
|
||||
license_file: str | None = self.metadata.license_file
|
||||
if license_file and license_file not in patterns:
|
||||
patterns.append(license_file)
|
||||
|
||||
|
|
@ -599,7 +599,7 @@ class Distribution(_Distribution):
|
|||
patterns = ('LICEN[CS]E*', 'COPYING*', 'NOTICE*', 'AUTHORS*')
|
||||
|
||||
self.metadata.license_files = list(
|
||||
unique_everseen(self._expand_patterns(patterns))
|
||||
unique_everseen(self._expand_patterns(patterns)),
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
|
|
@ -653,14 +653,14 @@ class Distribution(_Distribution):
|
|||
filenames = self.find_config_files()
|
||||
|
||||
if DEBUG:
|
||||
self.announce("Distribution.parse_config_files():")
|
||||
self.announce('Distribution.parse_config_files():')
|
||||
|
||||
parser = ConfigParser()
|
||||
parser.optionxform = str
|
||||
for filename in filenames:
|
||||
with io.open(filename, encoding='utf-8') as reader:
|
||||
with open(filename, encoding='utf-8') as reader:
|
||||
if DEBUG:
|
||||
self.announce(" reading {filename}".format(**locals()))
|
||||
self.announce(f' reading {filename}')
|
||||
parser.read_file(reader)
|
||||
for section in parser.sections():
|
||||
options = parser.options(section)
|
||||
|
|
@ -707,9 +707,9 @@ class Distribution(_Distribution):
|
|||
underscore_opt = opt.replace('-', '_')
|
||||
commands = distutils.command.__all__ + self._setuptools_commands()
|
||||
if (
|
||||
not section.startswith('options')
|
||||
and section != 'metadata'
|
||||
and section not in commands
|
||||
not section.startswith('options') and
|
||||
section != 'metadata' and
|
||||
section not in commands
|
||||
):
|
||||
return underscore_opt
|
||||
|
||||
|
|
@ -717,7 +717,7 @@ class Distribution(_Distribution):
|
|||
warnings.warn(
|
||||
"Usage of dash-separated '%s' will not be supported in future "
|
||||
"versions. Please use the underscore name '%s' instead"
|
||||
% (opt, underscore_opt)
|
||||
% (opt, underscore_opt),
|
||||
)
|
||||
return underscore_opt
|
||||
|
||||
|
|
@ -737,7 +737,7 @@ class Distribution(_Distribution):
|
|||
warnings.warn(
|
||||
"Usage of uppercase key '%s' in '%s' will be deprecated in future "
|
||||
"versions. Please use lowercase '%s' instead"
|
||||
% (opt, section, lowercase_opt)
|
||||
% (opt, section, lowercase_opt),
|
||||
)
|
||||
return lowercase_opt
|
||||
|
||||
|
|
@ -762,7 +762,7 @@ class Distribution(_Distribution):
|
|||
self.announce(" setting options for '%s' command:" % command_name)
|
||||
for (option, (source, value)) in option_dict.items():
|
||||
if DEBUG:
|
||||
self.announce(" %s = %s (from %s)" % (option, value, source))
|
||||
self.announce(' {} = {} (from {})'.format(option, value, source))
|
||||
try:
|
||||
bool_opts = [translate_longopt(o) for o in command_obj.boolean_options]
|
||||
except AttributeError:
|
||||
|
|
@ -783,7 +783,7 @@ class Distribution(_Distribution):
|
|||
else:
|
||||
raise DistutilsOptionError(
|
||||
"error in %s: command '%s' has no such option '%s'"
|
||||
% (source, command_name, option)
|
||||
% (source, command_name, option),
|
||||
)
|
||||
except ValueError as e:
|
||||
raise DistutilsOptionError(e) from e
|
||||
|
|
@ -796,7 +796,7 @@ class Distribution(_Distribution):
|
|||
self._parse_config_files(filenames=filenames)
|
||||
|
||||
parse_configuration(
|
||||
self, self.command_options, ignore_option_errors=ignore_option_errors
|
||||
self, self.command_options, ignore_option_errors=ignore_option_errors,
|
||||
)
|
||||
self._finalize_requires()
|
||||
self._finalize_license_files()
|
||||
|
|
@ -860,11 +860,11 @@ class Distribution(_Distribution):
|
|||
with open(readme_txt_filename, 'w') as f:
|
||||
f.write(
|
||||
'This directory contains eggs that were downloaded '
|
||||
'by setuptools to build, test, and run plug-ins.\n\n'
|
||||
'by setuptools to build, test, and run plug-ins.\n\n',
|
||||
)
|
||||
f.write(
|
||||
'This directory caches those eggs to prevent '
|
||||
'repeated downloads.\n\n'
|
||||
'repeated downloads.\n\n',
|
||||
)
|
||||
f.write('However, it is safe to delete this directory.\n\n')
|
||||
|
||||
|
|
@ -961,15 +961,15 @@ class Distribution(_Distribution):
|
|||
"""Handle 'exclude()' for list/tuple attrs without a special handler"""
|
||||
if not isinstance(value, sequence):
|
||||
raise DistutilsSetupError(
|
||||
"%s: setting must be a list or tuple (%r)" % (name, value)
|
||||
'{}: setting must be a list or tuple ({!r})'.format(name, value),
|
||||
)
|
||||
try:
|
||||
old = getattr(self, name)
|
||||
except AttributeError as e:
|
||||
raise DistutilsSetupError("%s: No such distribution setting" % name) from e
|
||||
raise DistutilsSetupError('%s: No such distribution setting' % name) from e
|
||||
if old is not None and not isinstance(old, sequence):
|
||||
raise DistutilsSetupError(
|
||||
name + ": this setting cannot be changed via include/exclude"
|
||||
name + ': this setting cannot be changed via include/exclude',
|
||||
)
|
||||
elif old:
|
||||
setattr(self, name, [item for item in old if item not in value])
|
||||
|
|
@ -978,16 +978,16 @@ class Distribution(_Distribution):
|
|||
"""Handle 'include()' for list/tuple attrs without a special handler"""
|
||||
|
||||
if not isinstance(value, sequence):
|
||||
raise DistutilsSetupError("%s: setting must be a list (%r)" % (name, value))
|
||||
raise DistutilsSetupError('{}: setting must be a list ({!r})'.format(name, value))
|
||||
try:
|
||||
old = getattr(self, name)
|
||||
except AttributeError as e:
|
||||
raise DistutilsSetupError("%s: No such distribution setting" % name) from e
|
||||
raise DistutilsSetupError('%s: No such distribution setting' % name) from e
|
||||
if old is None:
|
||||
setattr(self, name, value)
|
||||
elif not isinstance(old, sequence):
|
||||
raise DistutilsSetupError(
|
||||
name + ": this setting cannot be changed via include/exclude"
|
||||
name + ': this setting cannot be changed via include/exclude',
|
||||
)
|
||||
else:
|
||||
new = [item for item in value if item not in old]
|
||||
|
|
@ -1019,7 +1019,7 @@ class Distribution(_Distribution):
|
|||
def _exclude_packages(self, packages):
|
||||
if not isinstance(packages, sequence):
|
||||
raise DistutilsSetupError(
|
||||
"packages: setting must be a list or tuple (%r)" % (packages,)
|
||||
'packages: setting must be a list or tuple ({!r})'.format(packages),
|
||||
)
|
||||
list(map(self.exclude_package, packages))
|
||||
|
||||
|
|
@ -1044,7 +1044,7 @@ class Distribution(_Distribution):
|
|||
# Handle commands that want to consume all remaining arguments
|
||||
cmd_class = self.get_command_class(command)
|
||||
if getattr(cmd_class, 'command_consumes_arguments', None):
|
||||
self.get_option_dict(command)['args'] = ("command line", nargs)
|
||||
self.get_option_dict(command)['args'] = ('command line', nargs)
|
||||
if nargs is not None:
|
||||
return []
|
||||
|
||||
|
|
@ -1066,7 +1066,7 @@ class Distribution(_Distribution):
|
|||
|
||||
for opt, (src, val) in opts.items():
|
||||
|
||||
if src != "command line":
|
||||
if src != 'command line':
|
||||
continue
|
||||
|
||||
opt = opt.replace('_', '-')
|
||||
|
|
@ -1093,11 +1093,9 @@ class Distribution(_Distribution):
|
|||
def iter_distribution_names(self):
|
||||
"""Yield all packages, modules, and extension names in distribution"""
|
||||
|
||||
for pkg in self.packages or ():
|
||||
yield pkg
|
||||
yield from self.packages or ()
|
||||
|
||||
for module in self.py_modules or ():
|
||||
yield module
|
||||
yield from self.py_modules or ()
|
||||
|
||||
for ext in self.ext_modules or ():
|
||||
if isinstance(ext, tuple):
|
||||
|
|
@ -1135,13 +1133,13 @@ class Distribution(_Distribution):
|
|||
line_buffering = sys.stdout.line_buffering
|
||||
|
||||
sys.stdout = io.TextIOWrapper(
|
||||
sys.stdout.detach(), 'utf-8', errors, newline, line_buffering
|
||||
sys.stdout.detach(), 'utf-8', errors, newline, line_buffering,
|
||||
)
|
||||
try:
|
||||
return _Distribution.handle_display_options(self, option_order)
|
||||
finally:
|
||||
sys.stdout = io.TextIOWrapper(
|
||||
sys.stdout.detach(), encoding, errors, newline, line_buffering
|
||||
sys.stdout.detach(), encoding, errors, newline, line_buffering,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue