mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-10 13:24: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,20 +1,23 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
import contextlib
|
||||
import functools
|
||||
import importlib
|
||||
import io
|
||||
import os
|
||||
import sys
|
||||
|
||||
import warnings
|
||||
import functools
|
||||
import importlib
|
||||
from collections import defaultdict
|
||||
from functools import partial
|
||||
from functools import wraps
|
||||
from glob import iglob
|
||||
import contextlib
|
||||
|
||||
from distutils.errors import DistutilsOptionError, DistutilsFileError
|
||||
from setuptools.extern.packaging.version import LegacyVersion, parse
|
||||
from distutils.errors import DistutilsFileError
|
||||
from distutils.errors import DistutilsOptionError
|
||||
from setuptools.extern.packaging.specifiers import SpecifierSet
|
||||
from setuptools.extern.packaging.version import LegacyVersion
|
||||
from setuptools.extern.packaging.version import parse
|
||||
|
||||
|
||||
class StaticModule:
|
||||
|
|
@ -41,7 +44,7 @@ class StaticModule:
|
|||
)
|
||||
except Exception as e:
|
||||
raise AttributeError(
|
||||
"{self.name} has no attribute {attr}".format(**locals())
|
||||
f'{self.name} has no attribute {attr}',
|
||||
) from e
|
||||
|
||||
|
||||
|
|
@ -93,7 +96,7 @@ def read_configuration(filepath, find_others=False, ignore_option_errors=False):
|
|||
_Distribution.parse_config_files(dist, filenames=filenames)
|
||||
|
||||
handlers = parse_configuration(
|
||||
dist, dist.command_options, ignore_option_errors=ignore_option_errors
|
||||
dist, dist.command_options, ignore_option_errors=ignore_option_errors,
|
||||
)
|
||||
|
||||
finally:
|
||||
|
|
@ -108,7 +111,7 @@ def _get_option(target_obj, key):
|
|||
the target object, either through a get_{key} method or
|
||||
from an attribute directly.
|
||||
"""
|
||||
getter_name = 'get_{key}'.format(**locals())
|
||||
getter_name = f'get_{key}'
|
||||
by_attribute = functools.partial(getattr, target_obj, key)
|
||||
getter = getattr(target_obj, getter_name, by_attribute)
|
||||
return getter()
|
||||
|
|
@ -196,7 +199,7 @@ class ConfigHandler:
|
|||
def parsers(self):
|
||||
"""Metadata item name to parser function mapping."""
|
||||
raise NotImplementedError(
|
||||
'%s must provide .parsers property' % self.__class__.__name__
|
||||
'%s must provide .parsers property' % self.__class__.__name__,
|
||||
)
|
||||
|
||||
def __setitem__(self, option_name, value):
|
||||
|
|
@ -275,9 +278,12 @@ class ConfigHandler:
|
|||
# Has globby characters?
|
||||
if any(char in value for char in glob_characters):
|
||||
# then expand the glob pattern while keeping paths *relative*:
|
||||
expanded_values.extend(sorted(
|
||||
os.path.relpath(path, os.getcwd())
|
||||
for path in iglob(os.path.abspath(value))))
|
||||
expanded_values.extend(
|
||||
sorted(
|
||||
os.path.relpath(path, os.getcwd())
|
||||
for path in iglob(os.path.abspath(value))
|
||||
),
|
||||
)
|
||||
|
||||
else:
|
||||
# take the value as-is:
|
||||
|
|
@ -298,7 +304,7 @@ class ConfigHandler:
|
|||
key, sep, val = line.partition(separator)
|
||||
if sep != separator:
|
||||
raise DistutilsOptionError(
|
||||
'Unable to parse option value to dict: %s' % value
|
||||
'Unable to parse option value to dict: %s' % value,
|
||||
)
|
||||
result[key.strip()] = val.strip()
|
||||
|
||||
|
|
@ -330,8 +336,8 @@ class ConfigHandler:
|
|||
exclude_directive = 'file:'
|
||||
if value.startswith(exclude_directive):
|
||||
raise ValueError(
|
||||
'Only strings are accepted for the {0} field, '
|
||||
'files are not accepted'.format(key)
|
||||
'Only strings are accepted for the {} field, '
|
||||
'files are not accepted'.format(key),
|
||||
)
|
||||
return value
|
||||
|
||||
|
|
@ -359,7 +365,7 @@ class ConfigHandler:
|
|||
if not value.startswith(include_directive):
|
||||
return value
|
||||
|
||||
spec = value[len(include_directive) :]
|
||||
spec = value[len(include_directive):]
|
||||
filepaths = (os.path.abspath(path.strip()) for path in spec.split(','))
|
||||
return '\n'.join(
|
||||
cls._read_file(path)
|
||||
|
|
@ -374,7 +380,7 @@ class ConfigHandler:
|
|||
|
||||
@staticmethod
|
||||
def _read_file(filepath):
|
||||
with io.open(filepath, encoding='utf-8') as f:
|
||||
with open(filepath, encoding='utf-8') as f:
|
||||
return f.read()
|
||||
|
||||
@classmethod
|
||||
|
|
@ -492,7 +498,7 @@ class ConfigHandler:
|
|||
if section_parser_method is None:
|
||||
raise DistutilsOptionError(
|
||||
'Unsupported distribution option section: [%s.%s]'
|
||||
% (self.section_prefix, section_name)
|
||||
% (self.section_prefix, section_name),
|
||||
)
|
||||
|
||||
section_parser_method(section_options)
|
||||
|
|
@ -531,10 +537,10 @@ class ConfigMetadataHandler(ConfigHandler):
|
|||
"""
|
||||
|
||||
def __init__(
|
||||
self, target_obj, options, ignore_option_errors=False, package_dir=None
|
||||
self, target_obj, options, ignore_option_errors=False, package_dir=None,
|
||||
):
|
||||
super(ConfigMetadataHandler, self).__init__(
|
||||
target_obj, options, ignore_option_errors
|
||||
super().__init__(
|
||||
target_obj, options, ignore_option_errors,
|
||||
)
|
||||
self.package_dir = package_dir
|
||||
|
||||
|
|
@ -552,8 +558,8 @@ class ConfigMetadataHandler(ConfigHandler):
|
|||
'provides': parse_list,
|
||||
'requires': self._deprecated_config_handler(
|
||||
parse_list,
|
||||
"The requires parameter is deprecated, please use "
|
||||
"install_requires for runtime dependencies.",
|
||||
'The requires parameter is deprecated, please use '
|
||||
'install_requires for runtime dependencies.',
|
||||
DeprecationWarning,
|
||||
),
|
||||
'obsoletes': parse_list,
|
||||
|
|
@ -561,8 +567,8 @@ class ConfigMetadataHandler(ConfigHandler):
|
|||
'license': exclude_files_parser('license'),
|
||||
'license_file': self._deprecated_config_handler(
|
||||
exclude_files_parser('license_file'),
|
||||
"The license_file parameter is deprecated, "
|
||||
"use license_files instead.",
|
||||
'The license_file parameter is deprecated, '
|
||||
'use license_files instead.',
|
||||
DeprecationWarning,
|
||||
),
|
||||
'license_files': parse_list,
|
||||
|
|
@ -642,7 +648,7 @@ class ConfigOptionsHandler(ConfigHandler):
|
|||
def _parse_cmdclass(self, value):
|
||||
def resolve_class(qualified_class_name):
|
||||
idx = qualified_class_name.rfind('.')
|
||||
class_name = qualified_class_name[idx + 1 :]
|
||||
class_name = qualified_class_name[idx + 1:]
|
||||
pkg_name = qualified_class_name[:idx]
|
||||
|
||||
module = __import__(pkg_name)
|
||||
|
|
@ -667,7 +673,7 @@ class ConfigOptionsHandler(ConfigHandler):
|
|||
|
||||
# Read function arguments from a dedicated section.
|
||||
find_kwargs = self.parse_section_packages__find(
|
||||
self.sections.get('packages.find', {})
|
||||
self.sections.get('packages.find', {}),
|
||||
)
|
||||
|
||||
if findns:
|
||||
|
|
@ -688,9 +694,9 @@ class ConfigOptionsHandler(ConfigHandler):
|
|||
|
||||
valid_keys = ['where', 'include', 'exclude']
|
||||
|
||||
find_kwargs = dict(
|
||||
[(k, v) for k, v in section_data.items() if k in valid_keys and v]
|
||||
)
|
||||
find_kwargs = {
|
||||
k: v for k, v in section_data.items() if k in valid_keys and v
|
||||
}
|
||||
|
||||
where = find_kwargs.get('where')
|
||||
if where is not None:
|
||||
|
|
@ -737,7 +743,7 @@ class ConfigOptionsHandler(ConfigHandler):
|
|||
"""
|
||||
parse_list = partial(self._parse_list, separator=';')
|
||||
self['extras_require'] = self._parse_section_to_dict(
|
||||
section_options, parse_list
|
||||
section_options, parse_list,
|
||||
)
|
||||
|
||||
def parse_section_data_files(self, section_options):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue