generate.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import io
  2. import invoke
  3. @invoke.task
  4. def authors(ctx):
  5. print("[generate.authors] Generating AUTHORS")
  6. # Get our list of authors
  7. print("[generate.authors] Collecting author names")
  8. # Note that it's necessary to use double quotes in the
  9. # --format"=%aN <%aE>" part of the command, as the Windows
  10. # shell doesn't recognise single quotes here.
  11. r = ctx.run('git log --use-mailmap --format"=%aN <%aE>"',
  12. encoding="utf-8", hide=True)
  13. authors = []
  14. seen_authors = set()
  15. for author in r.stdout.splitlines():
  16. author = author.strip()
  17. if author.lower() not in seen_authors:
  18. seen_authors.add(author.lower())
  19. authors.append(author)
  20. # Sort our list of Authors by their case insensitive name
  21. authors = sorted(authors, key=lambda x: x.lower())
  22. # Write our authors to the AUTHORS file
  23. print("[generate.authors] Writing AUTHORS")
  24. with io.open("AUTHORS.txt", "w", encoding="utf8") as fp:
  25. fp.write(u"\n".join(authors))
  26. fp.write(u"\n")
  27. @invoke.task
  28. def news(ctx, draft=False):
  29. print("[generate.news] Generating NEWS")
  30. args = []
  31. if draft:
  32. args.append("--draft")
  33. ctx.run("towncrier {}".format(" ".join(args)))