()
| 215 | |
| 216 | |
| 217 | def update_citations(): |
| 218 | authors_from_git = get_authors_from_git() |
| 219 | existing_authors = get_authors_from_cff_file() |
| 220 | |
| 221 | known_authors = [a for a in authors_from_git if a in KNOWN_AUTHORS] |
| 222 | human_authors = {a: e for a, e in authors_from_git.items() if not is_nonhuman(a)} |
| 223 | authors_to_search_for = { |
| 224 | a: e for a, e in human_authors.items() if a not in known_authors |
| 225 | } |
| 226 | |
| 227 | unrecognised_authors = { |
| 228 | a: e |
| 229 | for a, e in authors_to_search_for.items() |
| 230 | if not author_found_in_existing_authors(a, existing_authors) |
| 231 | } |
| 232 | |
| 233 | if not unrecognised_authors: |
| 234 | return |
| 235 | |
| 236 | for author, email in unrecognised_authors.items(): |
| 237 | print(f"{author} (email(s): {email})") |
| 238 | |
| 239 | while True: |
| 240 | reply = ( |
| 241 | input("\nThe above authors were not recognised. Add to citations? [y/N] ") |
| 242 | .lower() |
| 243 | .strip() |
| 244 | ) |
| 245 | if not reply or reply[0] == "n": |
| 246 | return |
| 247 | if reply[0] == "y": |
| 248 | break |
| 249 | |
| 250 | new_authors = [] |
| 251 | for author in unrecognised_authors: |
| 252 | if " " not in author: |
| 253 | # This is just a GitHub handle, skip |
| 254 | continue |
| 255 | first_name, last_name = author.rsplit(maxsplit=1) |
| 256 | new_authors.append({"family-names": last_name, "given-names": first_name}) |
| 257 | |
| 258 | print(f"Adding new authors:\n{new_authors}") |
| 259 | |
| 260 | yaml_file = parse_cff_file() |
| 261 | yaml_file["authors"].extend(new_authors) |
| 262 | |
| 263 | # Try to preserve indentation and quotes as much as possible |
| 264 | yaml = YAML() |
| 265 | yaml.indent(mapping=2, sequence=4, offset=2) |
| 266 | yaml.preserve_quotes = True |
| 267 | with open(CITATION_FILE, "w", encoding="UTF-8") as f: |
| 268 | yaml.dump(yaml_file, f) |
| 269 | |
| 270 | |
| 271 | if __name__ == "__main__": |
no test coverage detected