Enable flake8-logging-format

This commit is contained in:
Nguyễn Gia Phong 2020-06-17 22:53:30 +07:00
parent 05bdc69aa3
commit f8b06a3906
16 changed files with 44 additions and 56 deletions

View File

@ -21,7 +21,8 @@ repos:
hooks: hooks:
- id: flake8 - id: flake8
additional_dependencies: [ additional_dependencies: [
'flake8-bugbear==20.1.4' 'flake8-bugbear==20.1.4',
'flake8-logging-format==0.6.0',
] ]
exclude: tests/data exclude: tests/data

View File

@ -23,7 +23,14 @@ exclude =
.scratch, .scratch,
_vendor, _vendor,
data data
enable-extensions = G
ignore =
G200, G202,
# pycodestyle checks ignored in the default configuration
E121, E123, E126, E133, E226, E241, E242, E704, W503, W504, W505,
per-file-ignores = per-file-ignores =
# G: The plugin logging-format treats every .log and .error as logging.
noxfile.py: G
# B011: Do not call assert False since python -O removes these calls # B011: Do not call assert False since python -O removes these calls
tests/*: B011 tests/*: B011
# TODO: Remove IOError from except (OSError, IOError) blocks in # TODO: Remove IOError from except (OSError, IOError) blocks in
@ -33,6 +40,7 @@ per-file-ignores =
src/pip/_internal/utils/filesystem.py: B014 src/pip/_internal/utils/filesystem.py: B014
src/pip/_internal/network/cache.py: B014 src/pip/_internal/network/cache.py: B014
src/pip/_internal/utils/misc.py: B014 src/pip/_internal/utils/misc.py: B014
[mypy] [mypy]
follow_imports = silent follow_imports = silent
ignore_missing_imports = True ignore_missing_imports = True

View File

@ -228,11 +228,9 @@ class SimpleWheelCache(Cache):
continue continue
if canonicalize_name(wheel.name) != canonical_package_name: if canonicalize_name(wheel.name) != canonical_package_name:
logger.debug( logger.debug(
"Ignoring cached wheel {} for {} as it " "Ignoring cached wheel %s for %s as it "
"does not match the expected distribution name {}.".format( "does not match the expected distribution name %s.",
wheel_name, link, package_name wheel_name, link, package_name)
)
)
continue continue
if not wheel.supported(supported_tags): if not wheel.supported(supported_tags):
# Built for a different python/arch/etc # Built for a different python/arch/etc

View File

@ -831,11 +831,11 @@ def _handle_merge_hash(option, opt_str, value, parser):
try: try:
algo, digest = value.split(':', 1) algo, digest = value.split(':', 1)
except ValueError: except ValueError:
parser.error('Arguments to {} must be a hash name ' parser.error('Arguments to {} must be a hash name ' # noqa
'followed by a value, like --hash=sha256:' 'followed by a value, like --hash=sha256:'
'abcde...'.format(opt_str)) 'abcde...'.format(opt_str))
if algo not in STRONG_HASHES: if algo not in STRONG_HASHES:
parser.error('Allowed hash algorithms for {} are {}.'.format( parser.error('Allowed hash algorithms for {} are {}.'.format( # noqa
opt_str, ', '.join(STRONG_HASHES))) opt_str, ', '.join(STRONG_HASHES)))
parser.values.hashes.setdefault(algo, []).append(digest) parser.values.hashes.setdefault(algo, []).append(digest)

View File

@ -59,9 +59,8 @@ class CacheCommand(Command):
# Determine action # Determine action
if not args or args[0] not in handlers: if not args or args[0] not in handlers:
logger.error("Need an action ({}) to perform.".format( logger.error("Need an action (%s) to perform.",
", ".join(sorted(handlers))) ", ".join(sorted(handlers)))
)
return ERROR return ERROR
action = args[0] action = args[0]

View File

@ -105,9 +105,8 @@ class ConfigurationCommand(Command):
# Determine action # Determine action
if not args or args[0] not in handlers: if not args or args[0] not in handlers:
logger.error("Need an action ({}) to perform.".format( logger.error("Need an action (%s) to perform.",
", ".join(sorted(handlers))) ", ".join(sorted(handlers)))
)
return ERROR return ERROR
action = args[0] action = args[0]

View File

@ -29,7 +29,7 @@ logger = logging.getLogger(__name__)
def show_value(name, value): def show_value(name, value):
# type: (str, Optional[str]) -> None # type: (str, Optional[str]) -> None
logger.info('{}: {}'.format(name, value)) logger.info('%s: %s', name, value)
def show_sys_implementation(): def show_sys_implementation():
@ -102,9 +102,9 @@ def get_vendor_version_from_module(module_name):
def show_actual_vendor_versions(vendor_txt_versions): def show_actual_vendor_versions(vendor_txt_versions):
# type: (Dict[str, str]) -> None # type: (Dict[str, str]) -> None
# Logs the actual version and print extra info """Log the actual version and print extra info if there is
# if there is a conflict or if the actual version could not be imported. a conflict or if the actual version could not be imported.
"""
for module_name, expected_version in vendor_txt_versions.items(): for module_name, expected_version in vendor_txt_versions.items():
extra_message = '' extra_message = ''
actual_version = get_vendor_version_from_module(module_name) actual_version = get_vendor_version_from_module(module_name)
@ -115,14 +115,7 @@ def show_actual_vendor_versions(vendor_txt_versions):
elif actual_version != expected_version: elif actual_version != expected_version:
extra_message = ' (CONFLICT: vendor.txt suggests version should'\ extra_message = ' (CONFLICT: vendor.txt suggests version should'\
' be {})'.format(expected_version) ' be {})'.format(expected_version)
logger.info('%s==%s%s', module_name, actual_version, extra_message)
logger.info(
'{name}=={actual}{extra}'.format(
name=module_name,
actual=actual_version,
extra=extra_message
)
)
def show_vendor_versions(): def show_vendor_versions():

View File

@ -436,7 +436,7 @@ class InstallCommand(RequirementCommand):
message = create_env_error_message( message = create_env_error_message(
error, show_traceback, options.use_user_site, error, show_traceback, options.use_user_site,
) )
logger.error(message, exc_info=show_traceback) logger.error(message, exc_info=show_traceback) # noqa
return ERROR return ERROR

View File

@ -529,9 +529,7 @@ def group_locations(locations, expand_dir=False):
urls.append(url) urls.append(url)
else: else:
logger.warning( logger.warning(
"Path '{0}' is ignored: " "Path '%s' is ignored: it is a directory.", path)
"it is a directory.".format(path),
)
elif os.path.isfile(path): elif os.path.isfile(path):
sort_path(path) sort_path(path)
else: else:

View File

@ -95,8 +95,8 @@ class SearchScope(object):
# exceptions for malformed URLs # exceptions for malformed URLs
if not purl.scheme and not purl.netloc: if not purl.scheme and not purl.netloc:
logger.warning( logger.warning(
'The index url "{}" seems invalid, ' 'The index url "%s" seems invalid, '
'please provide a scheme.'.format(redacted_index_url)) 'please provide a scheme.', redacted_index_url)
redacted_index_urls.append(redacted_index_url) redacted_index_urls.append(redacted_index_url)

View File

@ -308,9 +308,7 @@ def get_csv_rows_for_installed(
installed_rows = [] # type: List[InstalledCSVRow] installed_rows = [] # type: List[InstalledCSVRow]
for row in old_csv_rows: for row in old_csv_rows:
if len(row) > 3: if len(row) > 3:
logger.warning( logger.warning('RECORD line has more than three elements: %s', row)
'RECORD line has more than three elements: {}'.format(row)
)
old_record_path = _parse_record_path(row[0]) old_record_path = _parse_record_path(row[0])
new_record_path = installed.pop(old_record_path, old_record_path) new_record_path = installed.pop(old_record_path, old_record_path)
if new_record_path in changed: if new_record_path in changed:

View File

@ -173,8 +173,8 @@ def deduce_helpful_msg(req):
" the packages specified within it." " the packages specified within it."
).format(req) ).format(req)
except RequirementParseError: except RequirementParseError:
logger.debug("Cannot parse '{}' as requirements \ logger.debug("Cannot parse '%s' as requirements file",
file".format(req), exc_info=True) req, exc_info=True)
else: else:
msg += " File '{}' does not exist.".format(req) msg += " File '{}' does not exist.".format(req)
return msg return msg

View File

@ -612,9 +612,7 @@ class UninstallPthEntries(object):
# If the file doesn't exist, log a warning and return # If the file doesn't exist, log a warning and return
if not os.path.isfile(self.file): if not os.path.isfile(self.file):
logger.warning( logger.warning(
"Cannot remove entries from nonexistent file {}".format( "Cannot remove entries from nonexistent file %s", self.file)
self.file)
)
return return
with open(self.file, 'rb') as fh: with open(self.file, 'rb') as fh:
# windows uses '\r\n' with py3k, but uses '\n' with py2.x # windows uses '\r\n' with py3k, but uses '\n' with py2.x

View File

@ -377,13 +377,13 @@ class Factory(object):
# satisfied. We just report that case. # satisfied. We just report that case.
if len(e.causes) == 1: if len(e.causes) == 1:
req, parent = e.causes[0] req, parent = e.causes[0]
if parent is None:
req_disp = str(req)
else:
req_disp = '{} (from {})'.format(req, parent.name)
logger.critical( logger.critical(
"Could not find a version that satisfies " + "Could not find a version that satisfies the requirement %s",
"the requirement " + req_disp,
str(req) +
("" if parent is None else " (from {})".format(
parent.name
))
) )
return DistributionNotFound( return DistributionNotFound(
'No matching distribution found for {}'.format(req) 'No matching distribution found for {}'.format(req)

View File

@ -241,10 +241,8 @@ def call_subprocess(
).format(proc.returncode, command_desc) ).format(proc.returncode, command_desc)
raise InstallationError(exc_msg) raise InstallationError(exc_msg)
elif on_returncode == 'warn': elif on_returncode == 'warn':
subprocess_logger.warning( subprocess_logger.warning('Command "%s" had error code %s in %s',
'Command "{}" had error code {} in {}'.format( command_desc, proc.returncode, cwd)
command_desc, proc.returncode, cwd)
)
elif on_returncode == 'ignore': elif on_returncode == 'ignore':
pass pass
else: else:

View File

@ -183,9 +183,8 @@ class TempDirectory(object):
# scripts, so we canonicalize the path by traversing potential # scripts, so we canonicalize the path by traversing potential
# symlinks here. # symlinks here.
path = os.path.realpath( path = os.path.realpath(
tempfile.mkdtemp(prefix="pip-{}-".format(kind)) tempfile.mkdtemp(prefix="pip-{}-".format(kind)))
) logger.debug("Created temporary directory: %s", path)
logger.debug("Created temporary directory: {}".format(path))
return path return path
def cleanup(self): def cleanup(self):
@ -267,8 +266,7 @@ class AdjacentTempDirectory(TempDirectory):
else: else:
# Final fallback on the default behavior. # Final fallback on the default behavior.
path = os.path.realpath( path = os.path.realpath(
tempfile.mkdtemp(prefix="pip-{}-".format(kind)) tempfile.mkdtemp(prefix="pip-{}-".format(kind)))
)
logger.debug("Created temporary directory: {}".format(path)) logger.debug("Created temporary directory: %s", path)
return path return path