
Update all .py source files by $ pyupgrade --py3-only $(git ls-files | grep ".py$") to modernize the code according to Python 3 syntaxes. pep8 errors are fixed by $ autopep8 --select=E127,E128,E501 --max-line-length 79 -r \ --in-place oslo_vmware Also add the pyupgrade hook to pre-commit to avoid merging additional Python 2 syntaxes. Change-Id: I1b34f8026d69db4485b2eec03767e54331e7817c
52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
# Copyright (c) 2017 OpenStack Foundation.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
import re
|
|
|
|
from hacking import core
|
|
|
|
|
|
_all_log_levels = {'critical', 'error', 'exception', 'info',
|
|
'warning', 'debug'}
|
|
|
|
# Since _Lx() have been removed, we just need to check _()
|
|
_all_hints = {'_'}
|
|
|
|
_log_translation_hint = re.compile(
|
|
r".*LOG\.({levels})\(\s*({hints})\(".format(
|
|
levels='|'.join(_all_log_levels),
|
|
hints='|'.join(_all_hints),
|
|
))
|
|
|
|
|
|
@core.flake8ext
|
|
def no_translate_logs(logical_line, filename):
|
|
"""N537 - Don't translate logs.
|
|
|
|
Check for 'LOG.*(_('
|
|
|
|
Translators don't provide translations for log messages, and operators
|
|
asked not to translate them.
|
|
|
|
* This check assumes that 'LOG' is a logger.
|
|
|
|
:param logical_line: The logical line to check.
|
|
:param filename: The file name where the logical line exists.
|
|
:returns: None if the logical line passes the check, otherwise a tuple
|
|
is yielded that contains the offending index in logical line and a
|
|
message describe the check validation failure.
|
|
"""
|
|
if _log_translation_hint.match(logical_line):
|
|
yield (0, "N537: Log messages should not be translated!")
|