Summarize codebase key files.
(codebase, field='tallies', **kwargs)
| 319 | |
| 320 | |
| 321 | def tally_codebase_key_files(codebase, field='tallies', **kwargs): |
| 322 | """ |
| 323 | Summarize codebase key files. |
| 324 | """ |
| 325 | talliables = codebase.attributes.tallies.keys() |
| 326 | if TRACE: logger_debug('tallieables:', talliables) |
| 327 | |
| 328 | # TODO: we cannot summarize packages with "key files" for now |
| 329 | talliables = [k for k in talliables if k in TALLYABLE_ATTRS] |
| 330 | |
| 331 | # create one counter for each summarized attribute |
| 332 | talliable_values_by_key = dict([(key, []) for key in talliables]) |
| 333 | |
| 334 | # filter to get only key files |
| 335 | key_files = (res for res in codebase.walk(topdown=True) |
| 336 | if (res.is_file and res.is_top_level |
| 337 | and (res.is_readme or res.is_legal or res.is_manifest))) |
| 338 | |
| 339 | for resource in key_files: |
| 340 | for key, values in talliable_values_by_key.items(): |
| 341 | # note we assume things are stored as extra-data, not as direct |
| 342 | # Resource attributes |
| 343 | res_tallies = get_resource_tallies(resource, key=key, as_attribute=False) or [] |
| 344 | for tally in res_tallies: |
| 345 | # each tally is a mapping with value/count: we transform back to values |
| 346 | tally_value = tally.get('value') |
| 347 | if tally_value: |
| 348 | values.extend([tally_value] * tally['count']) |
| 349 | |
| 350 | tally_counters = [] |
| 351 | for key, values in talliable_values_by_key.items(): |
| 352 | if key not in TALLYABLE_ATTRS: |
| 353 | continue |
| 354 | tallied = tally_values(values, key) |
| 355 | tally_counters.append((key, tallied)) |
| 356 | |
| 357 | sorted_tallies = dict( |
| 358 | [(key, sorted_counter(counter)) for key, counter in tally_counters]) |
| 359 | |
| 360 | codebase.attributes.tallies_of_key_files = sorted_tallies |
| 361 | |
| 362 | if TRACE: logger_debug('codebase tallies_of_key_files:', sorted_tallies) |
| 363 | |
| 364 | |
| 365 | @post_scan_impl |
no test coverage detected