annotate scripts/contributors.py @ 7752:b2dbab2b34bc

fix(refactor): multiple fixups using ruff linter; more testing. Converting to using the ruff linter and its rulesets. Fixed a number of issues. admin.py: sort imports use immutable tuples as default value markers for parameters where a None value is valid. reduced some loops to list comprehensions for performance used ternary to simplify some if statements named some variables to make them less magic (e.g. _default_savepoint_setting = 1000) fixed some tests for argument counts < 2 becomes != 2 so 3 is an error. moved exception handlers outside of loops for performance where exception handler will abort loop anyway. renamed variables called 'id' or 'dir' as they shadow builtin commands. fix translations of form _("string %s" % value) -> _("string %s") % value so translation will be looked up with the key before substitution. end dicts, tuples with a trailing comma to reduce missing comma errors if modified simplified sorted(list(self.setting.keys())) to sorted(self.setting.keys()) as sorted consumes whole list. in if conditions put compared variable on left and threshold condition on right. (no yoda conditions) multiple noqa: suppression removed unneeded noqa as lint rulesets are a bit different do_get - refactor output printing logic: Use fast return if not special formatting is requested; use isinstance with a tuple rather than two isinstance calls; cleaned up flow and removed comments on algorithm as it can be easily read from the code. do_filter, do_find - refactor output printing logic. Reduce duplicate code. do_find - renamed variable 'value' that was set inside a loop. The loop index variable was also named 'value'. do_pragma - added hint to use list subcommand if setting was not found. Replaced condition 'type(x) is bool' with 'isinstance(x, bool)' for various types. test_admin.py added testing for do_list better test coverage for do_get includes: -S and -d for multilinks, error case for -d with non-link. better testing for do_find including all output modes better testing for do_filter including all output modes fixed expected output for do_pragma that now includes hint to use pragma list if setting not found.
author John Rouillard <rouilj@ieee.org>
date Fri, 01 Mar 2024 14:53:18 -0500
parents 519cc743bf5a
children 4919435ac231
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4822
e162fb7353df contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
1 """
e162fb7353df contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
2 Get Mercurial history data and output list of contributors with years.
e162fb7353df contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
3
e162fb7353df contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
4 Public domain work by:
e162fb7353df contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
5
e162fb7353df contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
6 anatoly techtonik <techtonik@gmail.com>
e162fb7353df contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
7
e162fb7353df contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
8 """
e162fb7353df contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
9
5487
ce171c81d823 Use print_function import everywhere using print.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5414
diff changeset
10 from __future__ import print_function
4822
e162fb7353df contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
11 from subprocess import check_output
e162fb7353df contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
12
e162fb7353df contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
13 # --- output settings
e162fb7353df contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
14 contributors_by_year = True
e162fb7353df contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
15 years_for_contributors = True
e162fb7353df contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
16 verbose = True
e162fb7353df contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
17 # /--
e162fb7353df contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
18
4827
f1c7f99e6fc0 contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents: 4826
diff changeset
19 # --- project specific configuration
f1c7f99e6fc0 contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents: 4826
diff changeset
20 ALIASES = {
f1c7f99e6fc0 contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents: 4826
diff changeset
21 'Richard Jones <richard@mechanicalcat.net>':
f1c7f99e6fc0 contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents: 4826
diff changeset
22 ['richard',
f1c7f99e6fc0 contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents: 4826
diff changeset
23 'Richard Jones <richard@users.sourceforge.net>'],
f1c7f99e6fc0 contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents: 4826
diff changeset
24 'Bernhard Reiter <bernhard@intevation.de>':
f1c7f99e6fc0 contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents: 4826
diff changeset
25 ['Bernhard Reiter <ber@users.sourceforge.net>',
f1c7f99e6fc0 contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents: 4826
diff changeset
26 'Bernhard Reiter <Bernhard.Reiter@intevation.de>'],
f1c7f99e6fc0 contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents: 4826
diff changeset
27 'Ralf Schlatterbeck <rsc@runtux.com>':
f1c7f99e6fc0 contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents: 4826
diff changeset
28 ['Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>'],
f1c7f99e6fc0 contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents: 4826
diff changeset
29 'Stefan Seefeld <stefan@seefeld.name>':
f1c7f99e6fc0 contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents: 4826
diff changeset
30 ['Stefan Seefeld <stefan@users.sourceforge.net>'],
7051
519cc743bf5a Make contributers.py work.
John Rouillard <rouilj@ieee.org>
parents: 5487
diff changeset
31 'John Rouillard <rouilj@ieee.org>':
519cc743bf5a Make contributers.py work.
John Rouillard <rouilj@ieee.org>
parents: 5487
diff changeset
32 ['rouilj@uland', 'rouilj']
519cc743bf5a Make contributers.py work.
John Rouillard <rouilj@ieee.org>
parents: 5487
diff changeset
33
4827
f1c7f99e6fc0 contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents: 4826
diff changeset
34 }
4828
64daaa4bf816 contributors.py: Exclude robots and change sorting so that
anatoly techtonik <techtonik@gmail.com>
parents: 4827
diff changeset
35 ROBOTS = ['No Author <no-author@users.sourceforge.net>']
4827
f1c7f99e6fc0 contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents: 4826
diff changeset
36 # /--
4822
e162fb7353df contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
37
e162fb7353df contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
38
4824
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
39 def compress(years):
4823
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
40 """
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
41 Given a list of years like [2003, 2004, 2007],
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
42 compress it into string like '2003-2004, 2007'
4824
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
43
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
44 >>> compress([2002])
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
45 '2002'
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
46 >>> compress([2003, 2002])
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
47 '2002-2003'
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
48 >>> compress([2009, 2004, 2005, 2006, 2007])
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
49 '2004-2007, 2009'
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
50 >>> compress([2001, 2003, 2004, 2005])
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
51 '2001, 2003-2005'
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
52 >>> compress([2009, 2011])
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
53 '2009, 2011'
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
54 >>> compress([2009, 2010, 2011, 2006, 2007])
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
55 '2006-2007, 2009-2011'
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
56 >>> compress([2002, 2003, 2004, 2005, 2006, 2009, 2012])
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
57 '2002-2006, 2009, 2012'
4823
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
58 """
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
59 years = sorted(years)
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
60 # compress years into string
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
61 comma = ', '
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
62 yearstr = ''
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
63 for i in range(0,len(years)-1):
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
64 if years[i+1]-years[i] == 1:
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
65 if not yearstr or yearstr.endswith(comma):
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
66 yearstr += '%s' % years[i]
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
67 if yearstr.endswith('-'):
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
68 pass
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
69 else:
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
70 yearstr += '-'
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
71 else:
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
72 yearstr += '%s, ' % years[i]
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
73
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
74 if len(years) == 1:
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
75 yearstr += str(years[0])
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
76 else:
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
77 yearstr += '%s' % years[-1]
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
78 return yearstr
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
79
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
80
4824
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
81 if __name__ == '__main__':
7051
519cc743bf5a Make contributers.py work.
John Rouillard <rouilj@ieee.org>
parents: 5487
diff changeset
82
519cc743bf5a Make contributers.py work.
John Rouillard <rouilj@ieee.org>
parents: 5487
diff changeset
83 command = 'hg log --template "{date(date,\\"%Y\\")},{author}\\n"'
519cc743bf5a Make contributers.py work.
John Rouillard <rouilj@ieee.org>
parents: 5487
diff changeset
84
4824
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
85 if verbose:
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
86 print("Getting HG log...")
7051
519cc743bf5a Make contributers.py work.
John Rouillard <rouilj@ieee.org>
parents: 5487
diff changeset
87 print("Using: ", command)
519cc743bf5a Make contributers.py work.
John Rouillard <rouilj@ieee.org>
parents: 5487
diff changeset
88
519cc743bf5a Make contributers.py work.
John Rouillard <rouilj@ieee.org>
parents: 5487
diff changeset
89 authorship = check_output(command, shell=True)
4824
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
90 # authorship are strings like
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
91 # 2003,Richard Jones <richard@users.sourceforge.net>
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
92 # ...
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
93
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
94 if verbose:
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
95 print("Splitting...")
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
96 # transform to a list of tuples
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
97 authorship = [line.split(',', 1) for line in authorship.splitlines()]
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
98
4822
e162fb7353df contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
99 if verbose:
4824
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
100 print("Sorting...")
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
101 years = {} # year -> set(author1, author2, ...)
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
102 names = {} # author -> set(years)
4827
f1c7f99e6fc0 contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents: 4826
diff changeset
103 for year, author in authorship:
4828
64daaa4bf816 contributors.py: Exclude robots and change sorting so that
anatoly techtonik <techtonik@gmail.com>
parents: 4827
diff changeset
104 if author in ROBOTS:
64daaa4bf816 contributors.py: Exclude robots and change sorting so that
anatoly techtonik <techtonik@gmail.com>
parents: 4827
diff changeset
105 continue
4827
f1c7f99e6fc0 contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents: 4826
diff changeset
106 # process aliases
f1c7f99e6fc0 contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents: 4826
diff changeset
107 for name, aliases in ALIASES.items():
f1c7f99e6fc0 contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents: 4826
diff changeset
108 if author in aliases:
f1c7f99e6fc0 contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents: 4826
diff changeset
109 author = name
f1c7f99e6fc0 contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents: 4826
diff changeset
110 break
4828
64daaa4bf816 contributors.py: Exclude robots and change sorting so that
anatoly techtonik <techtonik@gmail.com>
parents: 4827
diff changeset
111 author = author.replace('<', '(')
64daaa4bf816 contributors.py: Exclude robots and change sorting so that
anatoly techtonik <techtonik@gmail.com>
parents: 4827
diff changeset
112 author = author.replace('>', ')')
4824
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
113 # years
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
114 if not year in years:
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
115 years[year] = set()
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
116 years[year].add(author)
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
117 # names
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
118 if not author in names:
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
119 names[author] = set()
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
120 names[author].add(int(year))
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
121
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
122
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
123 if contributors_by_year:
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
124 if verbose:
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
125 print("Contributors by year...")
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
126 print('')
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
127 for year in sorted(years, reverse=True):
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
128 print(year)
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
129 for author in sorted(years[year]):
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
130 print(" " + author)
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
131 print('')
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
132
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
133 if years_for_contributors:
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
134 if verbose:
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
135 print("Years for each contributor...")
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
136 print('')
4825
b3bf0aa48368 contributors.py: Sort contributors by last contributor's year (newest first)
anatoly techtonik <techtonik@gmail.com>
parents: 4824
diff changeset
137
b3bf0aa48368 contributors.py: Sort contributors by last contributor's year (newest first)
anatoly techtonik <techtonik@gmail.com>
parents: 4824
diff changeset
138 def last_year(name):
4826
7c765b6fc44b contributors.py: Improve sorting, output string instead of list
anatoly techtonik <techtonik@gmail.com>
parents: 4825
diff changeset
139 """Return year of the latest contribution for a given name"""
7c765b6fc44b contributors.py: Improve sorting, output string instead of list
anatoly techtonik <techtonik@gmail.com>
parents: 4825
diff changeset
140 return sorted(list(names[name]))[-1]
7c765b6fc44b contributors.py: Improve sorting, output string instead of list
anatoly techtonik <techtonik@gmail.com>
parents: 4825
diff changeset
141
7c765b6fc44b contributors.py: Improve sorting, output string instead of list
anatoly techtonik <techtonik@gmail.com>
parents: 4825
diff changeset
142 def first_year(name):
7c765b6fc44b contributors.py: Improve sorting, output string instead of list
anatoly techtonik <techtonik@gmail.com>
parents: 4825
diff changeset
143 """Return year of the first contribution"""
7c765b6fc44b contributors.py: Improve sorting, output string instead of list
anatoly techtonik <techtonik@gmail.com>
parents: 4825
diff changeset
144 return sorted(list(names[name]))[0]
7c765b6fc44b contributors.py: Improve sorting, output string instead of list
anatoly techtonik <techtonik@gmail.com>
parents: 4825
diff changeset
145
5414
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 4828
diff changeset
146 def year_key(name):
4826
7c765b6fc44b contributors.py: Improve sorting, output string instead of list
anatoly techtonik <techtonik@gmail.com>
parents: 4825
diff changeset
147 """
5414
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 4828
diff changeset
148 Year key function. First sort by latest contribution year (desc).
4828
64daaa4bf816 contributors.py: Exclude robots and change sorting so that
anatoly techtonik <techtonik@gmail.com>
parents: 4827
diff changeset
149 If it matches, compare first contribution year (asc). This ensures that
64daaa4bf816 contributors.py: Exclude robots and change sorting so that
anatoly techtonik <techtonik@gmail.com>
parents: 4827
diff changeset
150 the most recent and long-term contributors are at the top.
4826
7c765b6fc44b contributors.py: Improve sorting, output string instead of list
anatoly techtonik <techtonik@gmail.com>
parents: 4825
diff changeset
151 """
5414
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 4828
diff changeset
152 return (last_year(name), -first_year(name))
4825
b3bf0aa48368 contributors.py: Sort contributors by last contributor's year (newest first)
anatoly techtonik <techtonik@gmail.com>
parents: 4824
diff changeset
153
4828
64daaa4bf816 contributors.py: Exclude robots and change sorting so that
anatoly techtonik <techtonik@gmail.com>
parents: 4827
diff changeset
154 print("Copyright (c)")
5414
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 4828
diff changeset
155 for author in sorted(list(names), key=year_key, reverse=True):
4824
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
156 years = list(names[author])
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
157 yearstr = compress(years)
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
158
4825
b3bf0aa48368 contributors.py: Sort contributors by last contributor's year (newest first)
anatoly techtonik <techtonik@gmail.com>
parents: 4824
diff changeset
159 if 0: #DEBUG
4824
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
160 print(years, yearstr, author)
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
161 else:
4828
64daaa4bf816 contributors.py: Exclude robots and change sorting so that
anatoly techtonik <techtonik@gmail.com>
parents: 4827
diff changeset
162 print(" %s %s" % (yearstr, author))
4824
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
163 print('')

Roundup Issue Tracker: http://roundup-tracker.org/