Add docstrings for hacking.translation_checks

Cleaning up a little technical debt by adding docstrings
for our public APIs.

For hacking checks we use the pep8 docstring format [1] so
that the pep8 check codes can be auto-detected by pep8.
I've manually tested neutron-lib master + this change with
neutron master to ensure pep8 for neutron has no impacts.

Note: I plan to submit a patch per file as part of this bug work.
These patches won't depend on each other. The last patch of
the series will close the bug.

[1] https://github.com/PyCQA/pycodestyle/blob/1.5.7/pep8.py#L100

Change-Id: I5301c105b60a4f61e2a220d0eb11c611a367c1cf
Partial-Bug: #1614594
This commit is contained in:
Boden R 2016-08-22 16:23:51 -06:00
parent 72c7cd2d31
commit f54d49afbb

View File

@ -51,6 +51,15 @@ def _translation_is_not_expected(filename):
def validate_log_translations(logical_line, physical_line, filename):
"""N531 - Log messages require translation hints.
:param logical_line: The logical line to check.
:param physical_line: The physical 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 _translation_is_not_expected(filename):
return
@ -63,20 +72,35 @@ def validate_log_translations(logical_line, physical_line, filename):
def check_log_warn_deprecated(logical_line, filename):
"""N532 - Use LOG.warning due to compatibility with py3.
: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.
"""
msg = "N532: Use LOG.warning due to compatibility with py3"
if _log_warn.match(logical_line):
yield (0, msg)
def no_translate_debug_logs(logical_line, filename):
"""Check for 'LOG.debug(_(' and 'LOG.debug(_Lx('
"""N533 - Don't translate debug level logs.
Check for 'LOG.debug(_(' and 'LOG.debug(_Lx('
As per our translation policy,
https://wiki.openstack.org/wiki/LoggingStandards#Log_Translation
we shouldn't translate debug level logs.
* This check assumes that 'LOG' is a logger.
N533
: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.
"""
for hint in _all_hints:
if logical_line.startswith("LOG.debug(%s(" % hint):
@ -84,6 +108,14 @@ def no_translate_debug_logs(logical_line, filename):
def check_raised_localized_exceptions(logical_line, filename):
"""N534 - Untranslated exception message.
: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 _translation_is_not_expected(filename):
return
@ -98,10 +130,17 @@ def check_raised_localized_exceptions(logical_line, filename):
def check_delayed_string_interpolation(logical_line, filename, noqa):
"""N536 String interpolation should be delayed at logging calls.
"""N536 - String interpolation should be delayed at logging calls.
N536: LOG.debug('Example: %s' % 'bad')
Okay: LOG.debug('Example: %s', 'good')
:param logical_line: The logical line to check.
:param filename: The file name where the logical line exists.
:param noqa: Noqa indicator.
: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.
"""
msg = ("N536 String interpolation should be delayed to be "
"handled by the logging code, rather than being done "