summaryrefslogtreecommitdiff
path: root/tasks/generate.py
blob: 69960231c3b7ba72b2e1458ab9235041935770fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import io

import invoke


@invoke.task
def authors(ctx):
    print("[generate.authors] Generating AUTHORS")

    # Get our list of authors
    print("[generate.authors] Collecting author names")

    # Note that it's necessary to use double quotes in the
    # --format"=%aN <%aE>" part of the command, as the Windows
    # shell doesn't recognise single quotes here.
    r = ctx.run('git log --use-mailmap --format"=%aN <%aE>"',
                encoding="utf-8", hide=True)

    authors = []
    seen_authors = set()
    for author in r.stdout.splitlines():
        author = author.strip()
        if author.lower() not in seen_authors:
            seen_authors.add(author.lower())
            authors.append(author)

    # Sort our list of Authors by their case insensitive name
    authors = sorted(authors, key=lambda x: x.lower())

    # Write our authors to the AUTHORS file
    print("[generate.authors] Writing AUTHORS")
    with io.open("AUTHORS.txt", "w", encoding="utf8") as fp:
        fp.write(u"\n".join(authors))
        fp.write(u"\n")


@invoke.task
def news(ctx, draft=False):
    print("[generate.news] Generating NEWS")

    args = []
    if draft:
        args.append("--draft")

    ctx.run("towncrier {}".format(" ".join(args)))