Implement a proxy checker class.

Add a proxy checker class for local checks that doesn't do anything,
but instead registers a command option that allows for local, in-tree
checks.

Change-Id: I3f7567639ae47cc422c84f319f1b607ad193d901
Reviewed-on: https://review.openstack.org/28220
Reviewed-by: James E. Blair <corvus@inaugust.com>
Reviewed-by: Giampaolo Lauria <lauria@us.ibm.com>
Reviewed-by: Sean Dague <sean@dague.net>
Approved: Joe Gordon <jogo@cloudscaling.com>
Reviewed-by: Joe Gordon <jogo@cloudscaling.com>
Tested-by: Jenkins
This commit is contained in:
Monty Taylor 2013-05-03 18:58:12 -04:00 committed by Jenkins
parent 78cb53f086
commit c5b07cad12
3 changed files with 63 additions and 0 deletions

View File

@ -301,3 +301,24 @@ and how to split up commits into a series of changes, consult the
project wiki:
http://wiki.openstack.org/GitCommitMessages
Local Checks
============
hacking supports having local changes in a source tree. They can be configured
to run in two different ways. They can be registered individually, or with
a factory function.
For individual registration, put a comma separated list of pep8 compatible
check functions into the hacking section of tox.ini. Like
[hacking]
local-check = nova.tests.hacking.bad_code_is_terrible
Alternately, you can specify the location of a callable that will be called
at registration time and will be passed the registration function. The callable
should expect to call the passed in function on everything if wants to
register. Such as:
[hacking]
local-check-factory = nova.tests.hacking.factory

View File

@ -21,6 +21,7 @@
Built as a sets of pep8 checks using flake8.
"""
import ConfigParser
import gettext
import imp
import logging
@ -31,6 +32,9 @@ import sys
import tokenize
import traceback
import d2to1.util
import pep8
# Don't need this for testing
logging.disable('LOG')
@ -560,6 +564,9 @@ class GlobalCheck(object):
for r in ret:
yield ret
def run_once(self):
pass
class GitCheck(GlobalCheck):
@ -634,3 +641,37 @@ class OnceGitCheckCommitTitleLength(GitCheck):
"H802: git commit title ('%s') should be under 50 chars"
% title.strip(),
self.name)
class ProxyChecks(GlobalCheck):
"""Provide a mechanism for locally defined checks."""
name = 'ProxyChecker'
def __init__(self, tree, *args):
pass
@classmethod
def add_options(cls, parser):
# Abusing this method because of when it gets called
if not os.path.exists('tox.ini'):
return
tox_ini = ConfigParser.RawConfigParser()
tox_ini.read('tox.ini')
if not tox_ini.has_section('hacking'):
return
# We're looking for local checks, so we need to include the local
# dir in the search path
sys.path.append('.')
if tox_ini.has_option('hacking', 'local-check'):
for check_path in set(
tox_ini.get('hacking', 'local-check').split(",")):
if check_path.strip():
checker = d2to1.util.resolve_name(check_path)
pep8.register_check(checker)
if tox_ini.has_option('hacking', 'local-check-factory'):
factory = d2to1.util.resolve_name(
tox_ini.get('hacking', 'local-check-factory'))
factory(pep8.register_check)
sys.path.pop()

View File

@ -26,6 +26,7 @@ setup-hooks =
[entry_points]
flake8.extension =
H000 = hacking.core:ProxyChecks
H101 = hacking.core:hacking_todo_format
H201 = hacking.core:hacking_except_format
H202 = hacking.core:hacking_except_format_assert