MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / run_codebase_plugins

Function run_codebase_plugins

src/scancode/cli.py:1111–1169  ·  view source on GitHub ↗

Run the list of `stage` `plugins` on `codebase` and return True on success and False otherwise. Display errors and messages based on the `stage_msg` and `plugin_msg` string templates and the `quiet` and `verbose` flags. Kwargs are passed down when calling the process_codebase me

(
    stage,
    plugins,
    codebase,
    stage_msg='',
    plugin_msg='',
    quiet=False,
    verbose=False,
    kwargs=None,
    echo_func=echo_stderr,
)

Source from the content-addressed store, hash-verified

1109
1110
1111def run_codebase_plugins(
1112 stage,
1113 plugins,
1114 codebase,
1115 stage_msg='',
1116 plugin_msg='',
1117 quiet=False,
1118 verbose=False,
1119 kwargs=None,
1120 echo_func=echo_stderr,
1121):
1122 """
1123 Run the list of `stage` `plugins` on `codebase` and return True on success and
1124 False otherwise.
1125 Display errors and messages based on the `stage_msg` and
1126 `plugin_msg` string templates and the `quiet` and `verbose` flags.
1127 Kwargs are passed down when calling the process_codebase method of each
1128 plugin.
1129 """
1130 kwargs = kwargs or {}
1131
1132 stage_start = time()
1133 if verbose and plugins:
1134 echo_func(stage_msg % locals(), fg='green')
1135
1136 # Sort plugins by run_order, from low to high
1137 sorted_plugins = sorted(plugins, key=lambda x: x.run_order)
1138
1139 success = True
1140 # TODO: add progress indicator
1141 for plugin in sorted_plugins:
1142 name = plugin.name
1143 plugin_start = time()
1144
1145 if verbose:
1146 echo_func(plugin_msg % locals(), fg='green')
1147
1148 try:
1149 if TRACE_DEEP:
1150 from pprint import pformat
1151 logger_debug('run_codebase_plugins: kwargs passed to %(stage)s:%(name)s' % locals())
1152 logger_debug(pformat(sorted(kwargs.items())))
1153 logger_debug()
1154
1155 plugin.process_codebase(codebase, **kwargs)
1156
1157 except Exception as _e:
1158 msg = 'ERROR: failed to run %(stage)s plugin: %(name)s:' % locals()
1159 echo_func(msg, fg='red')
1160 tb = traceback.format_exc()
1161 echo_func(tb)
1162 codebase.errors.append(msg + '\n' + tb)
1163 success = False
1164
1165 timing_key = '%(stage)s:%(name)s' % locals()
1166 codebase.timings[timing_key] = time() - plugin_start
1167
1168 codebase.timings[stage] = time() - stage_start

Callers 2

run_scanFunction · 0.85
run_scannersFunction · 0.85

Calls 4

echo_funcFunction · 0.85
logger_debugFunction · 0.70
process_codebaseMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected