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

Function language_tallies

src/summarycode/tallies.py:220–249  ·  view source on GitHub ↗

Populate a programming_language tallies list of mappings such as {value: "programming_language", count: "count of occurences"} sorted by decreasing count.

(resource, children, keep_details=False)

Source from the content-addressed store, hash-verified

218
219
220def language_tallies(resource, children, keep_details=False):
221 """
222 Populate a programming_language tallies list of mappings such as
223 {value: "programming_language", count: "count of occurences"}
224 sorted by decreasing count.
225 """
226 PROG_LANG = 'programming_language'
227 languages = []
228 prog_lang = getattr(resource, PROG_LANG , [])
229 if not prog_lang:
230 if resource.is_file:
231 # also count files with no detection
232 languages.append(None)
233 else:
234 languages.append(prog_lang)
235
236 # Collect direct children expression summaries
237 for child in children:
238 child_tallies = get_resource_tallies(child, key=PROG_LANG, as_attribute=keep_details) or []
239 for child_tally in child_tallies:
240 child_sum_val = child_tally.get('value')
241 if child_sum_val:
242 values = [child_sum_val] * child_tally['count']
243 languages.extend(values)
244
245 # summarize proper
246 languages_counter = tally_languages(languages)
247 tallied = sorted_counter(languages_counter)
248 set_resource_tallies(resource, key=PROG_LANG, value=tallied, as_attribute=keep_details)
249 return tallied
250
251
252def tally_languages(languages):

Callers

nothing calls this directly

Calls 6

get_resource_talliesFunction · 0.90
sorted_counterFunction · 0.90
set_resource_talliesFunction · 0.90
tally_languagesFunction · 0.85
getMethod · 0.65
appendMethod · 0.45

Tested by

no test coverage detected