[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

@ -2,6 +2,8 @@
Implements the Distutils 'check' command.
"""
from __future__ import annotations
from distutils.core import Command
from distutils.errors import DistutilsSetupError
@ -14,17 +16,23 @@ try:
class SilentReporter(Reporter):
def __init__(self, source, report_level, halt_level, stream=None,
debug=0, encoding='ascii', error_handler='replace'):
def __init__(
self, source, report_level, halt_level, stream=None,
debug=0, encoding='ascii', error_handler='replace',
):
self.messages = []
Reporter.__init__(self, source, report_level, halt_level, stream,
debug, encoding, error_handler)
Reporter.__init__(
self, source, report_level, halt_level, stream,
debug, encoding, error_handler,
)
def system_message(self, level, message, *children, **kwargs):
self.messages.append((level, message, children, kwargs))
return nodes.system_message(message, level=level,
type=self.levels[level],
*children, **kwargs)
return nodes.system_message(
message, level=level,
type=self.levels[level],
*children, **kwargs,
)
HAS_DOCUTILS = True
except Exception:
@ -32,16 +40,25 @@ except Exception:
# indicate that docutils is not ported to Py3k.
HAS_DOCUTILS = False
class check(Command):
"""This command checks the meta-data of the package.
"""
description = ("perform some checks on the package")
user_options = [('metadata', 'm', 'Verify meta-data'),
('restructuredtext', 'r',
('Checks if long string meta-data syntax '
'are reStructuredText-compliant')),
('strict', 's',
'Will exit with an error if a check fails')]
description = ('perform some checks on the package')
user_options = [
('metadata', 'm', 'Verify meta-data'),
(
'restructuredtext', 'r',
(
'Checks if long string meta-data syntax '
'are reStructuredText-compliant'
),
),
(
'strict', 's',
'Will exit with an error if a check fails',
),
]
boolean_options = ['metadata', 'restructuredtext', 'strict']
@ -95,19 +112,25 @@ class check(Command):
missing.append(attr)
if missing:
self.warn("missing required meta-data: %s" % ', '.join(missing))
self.warn('missing required meta-data: %s' % ', '.join(missing))
if metadata.author:
if not metadata.author_email:
self.warn("missing meta-data: if 'author' supplied, " +
"'author_email' should be supplied too")
self.warn(
"missing meta-data: if 'author' supplied, " +
"'author_email' should be supplied too",
)
elif metadata.maintainer:
if not metadata.maintainer_email:
self.warn("missing meta-data: if 'maintainer' supplied, " +
"'maintainer_email' should be supplied too")
self.warn(
"missing meta-data: if 'maintainer' supplied, " +
"'maintainer_email' should be supplied too",
)
else:
self.warn("missing meta-data: either (author and author_email) " +
"or (maintainer and maintainer_email) " +
"should be supplied")
self.warn(
'missing meta-data: either (author and author_email) ' +
'or (maintainer and maintainer_email) ' +
'should be supplied',
)
def check_restructuredtext(self):
"""Checks if the long string fields are reST-compliant."""
@ -117,7 +140,7 @@ class check(Command):
if line is None:
warning = warning[1]
else:
warning = '%s (line %s)' % (warning[1], line)
warning = '{} (line {})'.format(warning[1], line)
self.warn(warning)
def _check_rst_data(self, data):
@ -129,13 +152,15 @@ class check(Command):
settings.tab_width = 4
settings.pep_references = None
settings.rfc_references = None
reporter = SilentReporter(source_path,
settings.report_level,
settings.halt_level,
stream=settings.warning_stream,
debug=settings.debug,
encoding=settings.error_encoding,
error_handler=settings.error_encoding_error_handler)
reporter = SilentReporter(
source_path,
settings.report_level,
settings.halt_level,
stream=settings.warning_stream,
debug=settings.debug,
encoding=settings.error_encoding,
error_handler=settings.error_encoding_error_handler,
)
document = nodes.document(settings, reporter, source=source_path)
document.note_source(source_path, -1)
@ -143,6 +168,7 @@ class check(Command):
parser.parse(data, document)
except AttributeError as e:
reporter.messages.append(
(-1, 'Could not finish the parsing: %s.' % e, '', {}))
(-1, 'Could not finish the parsing: %s.' % e, '', {}),
)
return reporter.messages