Add hacking check for print() statements

We are frequently having to -1 patches because people
forget print() statements that were used for debug in
their development.  Can save everyone time and trouble by
adding this simple hacking check.

The check excluded the cinder/cmd directory as the files in there
legitimately need to use the print() command.  Also wsgi.py and
the test_hds_nas_backend.py files make use of print, so I have
excluded those from checking as well.

Change-Id: I2066eeb2bdc6c9af294d0b9befb7e0b32abd1378
This commit is contained in:
Jay S. Bryant
2015-04-06 11:22:09 -05:00
parent f8b6feb5eb
commit c2658d9c09
5 changed files with 42 additions and 10 deletions

View File

@@ -41,6 +41,7 @@ underscore_import_check = re.compile(r"(.)*i18n\s+import\s+_(.)*")
# We need this for cases where they have created their own _ function.
custom_underscore_check = re.compile(r"(.)*_\s*=\s*(.)*")
no_audit_log = re.compile(r"(.)*LOG\.audit(.)*")
no_print_statements = re.compile(r"\s*print\s*\(.+\).*")
# NOTE(jsbryant): When other oslo libraries switch over non-namespaced
# imports, we will need to add them to the regex below.
@@ -207,6 +208,18 @@ def check_unicode_usage(logical_line, noqa):
yield(0, msg)
def check_no_print_statements(logical_line, filename, noqa):
# The files in cinder/cmd do need to use 'print()' so
# we don't need to check those files. Other exemptions
# should use '# noqa' to avoid failing here.
if "cinder/cmd" not in filename and not noqa:
if re.match(no_print_statements, logical_line):
msg = ("C303: print() should not be used. "
"Please use LOG.[info|error|warning|exception|debug]. "
"If print() must be used, use '# noqa' to skip this check.")
yield(0, msg)
def factory(register):
register(no_vi_headers)
register(no_translate_debug_logs)
@@ -219,3 +232,4 @@ def factory(register):
register(check_datetime_now)
register(validate_log_translations)
register(check_unicode_usage)
register(check_no_print_statements)