7
IRRELEVANT_MODULES = ['cr_common', 'cr_tests', 'cr_skeleton']
10
def narrow_down_modules(modules):
12
Get a list of file names or module names and filter out
13
the ones we know are irrelevant.
16
for module in modules:
17
module_name = os.path.basename(module).replace('.py', '')
18
if module_name not in IRRELEVANT_MODULES and \
19
module_name.startswith('cr_'):
20
relevant_modules += [module]
21
return relevant_modules
26
Here we have a look at all the modules in the
27
clickreviews package and filter out a few which
30
Basically we look at all the ones which are
31
derived from cr_common, where we can later on
32
instantiate a *Review* object and run the
36
all_modules = [name for _, name, _ in
37
pkgutil.iter_modules(clickreviews.__path__)]
38
return narrow_down_modules(all_modules)
41
def find_main_class(module_name):
43
This function will find the Click*Review class in
46
module = imp.load_source(module_name,
47
'%s/%s.py' % (clickreviews.__path__[0],
50
classes = inspect.getmembers(module, inspect.isclass)
51
find_main_class = lambda a: a[0].startswith('Click') and \
52
not a[0].endswith('Exception') and \
53
a[1].__module__ == module_name
54
main_class = list(filter(find_main_class, classes))
55
init_object = getattr(module, main_class[0][0])
59
def init_main_class(module_name, click_file):
61
This function will instantiate the main Click*Review
62
class of a given module and instantiate it with the
63
location of the .click file we want to inspect.
66
init_object = find_main_class(module_name)
67
return init_object(click_file)