Return a list of declared holders from a codebase using the holders detected from key files. A declared holder is a copyright holder present in the key files who has the highest amount of refrences throughout the codebase.
(codebase, holders_tallies)
| 157 | |
| 158 | |
| 159 | def get_declared_holders(codebase, holders_tallies): |
| 160 | """ |
| 161 | Return a list of declared holders from a codebase using the holders |
| 162 | detected from key files. |
| 163 | |
| 164 | A declared holder is a copyright holder present in the key files who has the |
| 165 | highest amount of refrences throughout the codebase. |
| 166 | """ |
| 167 | entry_by_holders = { |
| 168 | fingerprints.generate(entry['value']): entry for entry in holders_tallies if entry['value'] |
| 169 | } |
| 170 | key_file_holders = get_field_values_from_codebase_resources( |
| 171 | codebase, 'holders', key_files_only=True |
| 172 | ) |
| 173 | entry_by_key_file_holders = { |
| 174 | fingerprints.generate(canonical_holder(entry['holder'])): entry |
| 175 | for entry in key_file_holders |
| 176 | if entry['holder'] |
| 177 | } |
| 178 | unique_key_file_holders = unique(entry_by_key_file_holders.keys()) |
| 179 | unique_key_file_holders_entries = [ |
| 180 | entry_by_holders[holder] for holder in unique_key_file_holders |
| 181 | ] |
| 182 | |
| 183 | holder_by_counts = defaultdict(list) |
| 184 | for holder_entry in unique_key_file_holders_entries: |
| 185 | count = holder_entry.get('count') |
| 186 | if count: |
| 187 | holder = holder_entry.get('value') |
| 188 | holder_by_counts[count].append(holder) |
| 189 | |
| 190 | declared_holders = [] |
| 191 | if holder_by_counts: |
| 192 | highest_count = max(holder_by_counts) |
| 193 | declared_holders = holder_by_counts[highest_count] |
| 194 | |
| 195 | # If we could not determine a holder, then we return a list of all the |
| 196 | # unique key file holders |
| 197 | if not declared_holders: |
| 198 | declared_holders = [entry['value'] for entry in unique_key_file_holders_entries] |
| 199 | |
| 200 | return declared_holders |
| 201 | |
| 202 | |
| 203 | def get_primary_language(programming_language_tallies): |
no test coverage detected