7
7
from fuzzywuzzy import fuzz , process
8
8
import subprocess as sp
9
9
10
- CREATORS_LAST_ORCID = '0000-0002-5312-6729' # This ORCID should go last
10
+ # These ORCIDs should go last
11
+ CREATORS_LAST = ['Gorgolewski, Krzysztof J.' , 'Ghosh, Satrajit' ]
11
12
# for entries not found in line-contributions
12
13
MISSING_ENTRIES = [
13
14
{"name" : "Varada, Jan" },
30
31
{"name" : "Lai, Jeff" }
31
32
]
32
33
33
-
34
- def fix_position (creators ):
35
- """Place Satra last."""
36
- # position first / last authors
37
- l_authr = None
38
-
39
- for info in creators :
40
- if 'orcid' in info and info ['orcid' ] == CREATORS_LAST_ORCID :
41
- l_authr = info
42
-
43
- if l_authr is None :
44
- raise AttributeError ('Missing important people' )
45
-
46
- creators .remove (l_authr )
47
- creators .append (l_authr )
48
- return creators
49
-
50
-
51
34
if __name__ == '__main__' :
52
35
contrib_file = Path ('line-contributors.txt' )
53
36
lines = []
54
37
if contrib_file .exists ():
55
38
print ('WARNING: Reusing existing line-contributors.txt file.' , file = sys .stderr )
56
39
lines = contrib_file .read_text ().splitlines ()
57
40
58
- if not lines and shutil .which ('git-line-summary' ):
41
+ git_line_summary_path = shutil .which ('git-line-summary' )
42
+ if not lines and git_line_summary_path :
59
43
print ("Running git-line-summary on nipype repo" )
60
- lines = sp .check_output (['git-line-summary' ]).decode ().splitlines ()
44
+ lines = sp .check_output ([git_line_summary_path ]).decode ().splitlines ()
61
45
contrib_file .write_text ('\n ' .join (lines ))
62
46
63
47
if not lines :
64
- raise RuntimeError ('Could not find line-contributors from git repository '
65
- '(hint: please install git-extras).' )
48
+ raise RuntimeError ("""\
49
+ Could not find line-contributors from git repository.%s""" % """ \
50
+ git-line-summary not found, please install git-extras. """ * (git_line_summary_path is None ))
66
51
67
52
data = [' ' .join (line .strip ().split ()[1 :- 1 ]) for line in lines if '%' in line ]
68
53
@@ -71,8 +56,10 @@ def fix_position(creators):
71
56
zenodo = json .loads (zenodo_file .read_text ())
72
57
zen_names = [' ' .join (val ['name' ].split (',' )[::- 1 ]).strip ()
73
58
for val in zenodo ['creators' ]]
59
+ total_names = len (zen_names ) + len (MISSING_ENTRIES )
74
60
75
61
name_matches = []
62
+ position = 1
76
63
for ele in data :
77
64
matches = process .extract (ele , zen_names , scorer = fuzz .token_sort_ratio ,
78
65
limit = 2 )
@@ -85,10 +72,21 @@ def fix_position(creators):
85
72
continue
86
73
87
74
if val not in name_matches :
75
+ if val ['name' ] not in CREATORS_LAST :
76
+ val ['position' ] = position
77
+ position += 1
78
+ else :
79
+ val ['position' ] = total_names + CREATORS_LAST .index (val ['name' ])
88
80
name_matches .append (val )
89
81
90
- for entry in MISSING_ENTRIES :
91
- name_matches .append (entry )
82
+ for missing in MISSING_ENTRIES :
83
+ missing ['position' ] = position
84
+ position += 1
85
+ name_matches .append (missing )
86
+
87
+ zenodo ['creators' ] = sorted (name_matches , key = lambda k : k ['position' ])
88
+ # Remove position
89
+ for creator in zenodo ['creators' ]:
90
+ del creator ['position' ]
92
91
93
- zenodo ['creators' ] = fix_position (name_matches )
94
- zenodo_file .write_text (json .dumps (zenodo , indent = 2 , sort_keys = True ))
92
+ zenodo_file .write_text ('%s\n ' % json .dumps (zenodo , indent = 2 , sort_keys = True ))
0 commit comments