Debian Codegraph @

RELICENSE/authors.py

raw
1 #!/usr/bin/env python3
2 """Get the authors of the LGPL-licensed subset of pyzmq (Cython bindings)"""
3
4 import re
5 from collections import defaultdict
6 from itertools import chain
7 from os.path import abspath, dirname, join
8
9 import git
10
11 here = dirname(__file__)
12 root = dirname(abspath(here))
13 repo = git.Repo(root)
14
15 LAST_CORE_COMMIT = 'db1d4d2f2cdd97955a7db620e667a834920a938a'
16 PRE_CORE_COMMIT = 'd4e3453b012962fc9bf6ed621019b395f968340c'
17
18 EXCLUDED = {
19 # docstring only:
20 'c2db4af3c591aae99bf437a223d97b30ecbfcd38',
21 '7b1ac07a3bbffe70af3adcd663c0cbe6f2a724f7',
22 'ce97f46881168c4c05d7885dc48a430c520a9683',
23 '14c16a97ffa95bf645ab27bf5b06c3eabda30e5e',
24 # accidental swapfile
25 '93150feb4a80712c6a379f79d561fbc87405ade8',
26 }
27
28
29 def get_all_commits():
30 return chain(
31 repo.iter_commits('master', 'zmq/backend/cython'),
32 repo.iter_commits(LAST_CORE_COMMIT, 'zmq/core'),
33 repo.iter_commits(PRE_CORE_COMMIT, ['zmq/_zmq.*']),
34 )
35
36
37 mailmap = {}
38 email_names = {}
39
40 pat = re.compile(r'\<([^\>]+)\>')
41 with open(join(root, '.mailmap')) as f:
42 for line in f:
43 if not line.strip():
44 continue
45 dest, src = pat.findall(line)
46 mailmap[src] = dest
47 email_names[dest] = line[: line.index('<')].strip()
48
49 author_commits = defaultdict(list)
50
51 for commit in get_all_commits():
52 # exclude some specific commits (e.g. docstring typos)
53 if commit.hexsha in EXCLUDED:
54 continue
55 # exclude commits that only touch generated pxi files in backend/cython
56 backend_cython_files = {
57 f for f in commit.stats.files if f.startswith('zmq/backend/cython')
58 }
59 if backend_cython_files and backend_cython_files.issubset(
60 {
61 'zmq/backend/cython/constant_enums.pxi',
62 'zmq/backend/cython/constants.pxi',
63 }
64 ):
65 continue
66
67 email = commit.author.email
68 email = mailmap.get(email, email)
69 name = email_names.setdefault(email, commit.author.name)
70 author_commits[email].append(commit)
71
72
73 def sort_key(email_commits):
74 commits = email_commits[1]
75 return (len(commits), commits[0].authored_date)
76
77
78 for email, commits in sorted(author_commits.items(), key=sort_key, reverse=True):
79 if len(commits) <= 2:
80 msg = '{} ({})'.format(
81 ' '.join(c.hexsha[:12] for c in commits),
82 commits[0].authored_datetime.year,
83 )
84 else:
85 msg = f"{len(commits)} commits ({commits[-1].authored_datetime.year}-{commits[0].authored_datetime.year})"
86 print(f"- [ ] {email_names[email]} {email}: {msg}")