File: generate.py

package info (click to toggle)
httpie 3.2.4-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,904 kB
  • sloc: python: 13,760; xml: 162; makefile: 141; ruby: 79; sh: 32
file content (53 lines) | stat: -rw-r--r-- 1,110 bytes parent folder | download | duplicates (3)
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
46
47
48
49
50
51
52
53
"""
Generate snippets to copy-paste.
"""
import sys

from jinja2 import Template

from fetch import HERE, load_awesome_people

TPL_FILE = HERE / 'snippet.jinja2'

HTTPIE_TEAM = {
    'claudiatd',
    'jakubroztocil',
    'jkbr',
    'isidentical'
}

BOT_ACCOUNTS = {
    'dependabot-sr'
}

IGNORE_ACCOUNTS = HTTPIE_TEAM | BOT_ACCOUNTS


def generate_snippets(release: str) -> str:
    people = load_awesome_people()
    contributors = {
        name: details
        for name, details in people.items()
        if details['github'] not in IGNORE_ACCOUNTS
        and (release in details['committed'] or release in details['reported'])
    }

    template = Template(source=TPL_FILE.read_text(encoding='utf-8'))
    output = template.render(contributors=contributors, release=release)
    print(output)
    return 0


if __name__ == '__main__':
    ret = 1
    try:
        ret = generate_snippets(sys.argv[1])
    except (IndexError, TypeError):
        ret = 2
        print(f'''
Generate snippets for contributors to a release.

Usage:
    python {sys.argv[0]} {sys.argv[0]} <RELEASE>
''')
    sys.exit(ret)