6
6
from fuzzywuzzy import fuzz , process
7
7
8
8
# These ORCIDs should go last
9
- CREATORS_LAST = [' Rokem, Ariel' , ' Esteban, Oscar' ]
10
- CONTRIBUTORS_LAST = [' Poldrack, Russell A.' ]
9
+ CREATORS_LAST = [" Rokem, Ariel" , " Esteban, Oscar" ]
10
+ CONTRIBUTORS_LAST = [" Poldrack, Russell A." ]
11
11
12
12
13
13
def sort_contributors (entries , git_lines , exclude = None , last = None ):
14
14
"""Return a list of author dictionaries, ordered by contribution."""
15
15
last = last or []
16
- sorted_authors = sorted (entries , key = lambda i : i [' name' ])
16
+ sorted_authors = sorted (entries , key = lambda i : i [" name" ])
17
17
18
- first_last = [' ' .join (val ['name' ].split (',' )[::- 1 ]).strip ()
19
- for val in sorted_authors ]
20
- first_last_excl = [' ' .join (val ['name' ].split (',' )[::- 1 ]).strip ()
21
- for val in exclude or []]
18
+ first_last = [
19
+ " " .join (val ["name" ].split ("," )[::- 1 ]).strip () for val in sorted_authors
20
+ ]
21
+ first_last_excl = [
22
+ " " .join (val ["name" ].split ("," )[::- 1 ]).strip () for val in exclude or []
23
+ ]
22
24
23
25
unmatched = []
24
26
author_matches = []
25
27
position = 1
26
28
for ele in git_lines :
27
- matches = process .extract (ele , first_last , scorer = fuzz .token_sort_ratio ,
28
- limit = 2 )
29
+ matches = process .extract (
30
+ ele , first_last , scorer = fuzz .token_sort_ratio , limit = 2
31
+ )
29
32
# matches is a list [('First match', % Match), ('Second match', % Match)]
30
33
if matches [0 ][1 ] > 80 :
31
34
val = sorted_authors [first_last .index (matches [0 ][0 ])]
@@ -36,86 +39,97 @@ def sort_contributors(entries, git_lines, exclude=None, last=None):
36
39
continue
37
40
38
41
if val not in author_matches :
39
- val [' position' ] = position
42
+ val [" position" ] = position
40
43
author_matches .append (val )
41
44
position += 1
42
45
43
- names = {' ' .join (val [' name' ].split (',' )[::- 1 ]).strip () for val in author_matches }
46
+ names = {" " .join (val [" name" ].split ("," )[::- 1 ]).strip () for val in author_matches }
44
47
for missing_name in first_last :
45
48
if missing_name not in names :
46
49
missing = sorted_authors [first_last .index (missing_name )]
47
- missing [' position' ] = position
50
+ missing [" position" ] = position
48
51
author_matches .append (missing )
49
52
position += 1
50
53
51
- all_names = [val [' name' ] for val in author_matches ]
54
+ all_names = [val [" name" ] for val in author_matches ]
52
55
for last_author in last :
53
- author_matches [all_names .index (last_author )][' position' ] = position
56
+ author_matches [all_names .index (last_author )][" position" ] = position
54
57
position += 1
55
58
56
- author_matches = sorted (author_matches , key = lambda k : k [' position' ])
59
+ author_matches = sorted (author_matches , key = lambda k : k [" position" ])
57
60
58
61
return author_matches , unmatched
59
62
60
63
61
- def get_git_lines (fname = ' line-contributors.txt' ):
64
+ def get_git_lines (fname = " line-contributors.txt" ):
62
65
"""Run git-line-summary."""
63
66
import shutil
64
67
import subprocess as sp
68
+
65
69
contrib_file = Path (fname )
66
70
67
71
lines = []
68
72
if contrib_file .exists ():
69
- print (' WARNING: Reusing existing line-contributors.txt file.' , file = sys .stderr )
73
+ print (" WARNING: Reusing existing line-contributors.txt file." , file = sys .stderr )
70
74
lines = contrib_file .read_text ().splitlines ()
71
75
72
- git_line_summary_path = shutil .which (' git-line-summary' )
76
+ git_line_summary_path = shutil .which (" git-line-summary" )
73
77
if not lines and git_line_summary_path :
74
78
print ("Running git-line-summary on repo" )
75
79
lines = sp .check_output ([git_line_summary_path ]).decode ().splitlines ()
76
80
lines = [l for l in lines if "Not Committed Yet" not in l ]
77
- contrib_file .write_text (' \n ' .join (lines ))
81
+ contrib_file .write_text (" \n " .join (lines ))
78
82
79
83
if not lines :
80
- raise RuntimeError ("""\
81
- Could not find line-contributors from git repository.%s""" % """ \
82
- git-line-summary not found, please install git-extras. """ * (git_line_summary_path is None ))
83
- return [' ' .join (line .strip ().split ()[1 :- 1 ]) for line in lines if '%' in line ]
84
+ raise RuntimeError (
85
+ """\
86
+ Could not find line-contributors from git repository.%s"""
87
+ % """ \
88
+ git-line-summary not found, please install git-extras. """
89
+ * (git_line_summary_path is None )
90
+ )
91
+ return [" " .join (line .strip ().split ()[1 :- 1 ]) for line in lines if "%" in line ]
84
92
85
93
86
- if __name__ == ' __main__' :
94
+ if __name__ == " __main__" :
87
95
data = get_git_lines ()
88
96
89
- zenodo_file = Path (' .zenodo.json' )
97
+ zenodo_file = Path (" .zenodo.json" )
90
98
zenodo = json .loads (zenodo_file .read_text ())
91
99
92
- creators = json .loads (Path (' .maint/developers.json' ).read_text ())
100
+ creators = json .loads (Path (" .maint/developers.json" ).read_text ())
93
101
zen_creators , miss_creators = sort_contributors (
94
- creators , data ,
95
- exclude = json .loads (Path ('.maint/former.json' ).read_text ()),
96
- last = CREATORS_LAST )
97
- contributors = json .loads (Path ('.maint/contributors.json' ).read_text ())
102
+ creators ,
103
+ data ,
104
+ exclude = json .loads (Path (".maint/former.json" ).read_text ()),
105
+ last = CREATORS_LAST ,
106
+ )
107
+ contributors = json .loads (Path (".maint/contributors.json" ).read_text ())
98
108
zen_contributors , miss_contributors = sort_contributors (
99
- contributors , data ,
100
- exclude = json .loads (Path ('.maint/former.json' ).read_text ()),
101
- last = CONTRIBUTORS_LAST )
102
- zenodo ['creators' ] = zen_creators
103
- zenodo ['contributors' ] = zen_contributors
104
-
105
- print ("Some people made commits, but are missing in .maint/ "
106
- "files: %s." % ', ' .join (set (miss_creators ).intersection (miss_contributors )),
107
- file = sys .stderr )
109
+ contributors ,
110
+ data ,
111
+ exclude = json .loads (Path (".maint/former.json" ).read_text ()),
112
+ last = CONTRIBUTORS_LAST ,
113
+ )
114
+ zenodo ["creators" ] = zen_creators
115
+ zenodo ["contributors" ] = zen_contributors
116
+
117
+ print (
118
+ "Some people made commits, but are missing in .maint/ "
119
+ "files: %s." % ", " .join (set (miss_creators ).intersection (miss_contributors )),
120
+ file = sys .stderr ,
121
+ )
108
122
109
123
# Remove position
110
- for creator in zenodo [' creators' ]:
111
- del creator [' position' ]
112
- if isinstance (creator [' affiliation' ], list ):
113
- creator [' affiliation' ] = creator [' affiliation' ][0 ]
114
-
115
- for creator in zenodo [' contributors' ]:
116
- creator [' type' ] = ' Researcher'
117
- del creator [' position' ]
118
- if isinstance (creator [' affiliation' ], list ):
119
- creator [' affiliation' ] = creator [' affiliation' ][0 ]
120
-
121
- zenodo_file .write_text (' %s\n ' % json .dumps (zenodo , indent = 2 ))
124
+ for creator in zenodo [" creators" ]:
125
+ del creator [" position" ]
126
+ if isinstance (creator [" affiliation" ], list ):
127
+ creator [" affiliation" ] = creator [" affiliation" ][0 ]
128
+
129
+ for creator in zenodo [" contributors" ]:
130
+ creator [" type" ] = " Researcher"
131
+ del creator [" position" ]
132
+ if isinstance (creator [" affiliation" ], list ):
133
+ creator [" affiliation" ] = creator [" affiliation" ][0 ]
134
+
135
+ zenodo_file .write_text (" %s\n " % json .dumps (zenodo , indent = 2 ))
0 commit comments