forked from scikit-learn/scikit-learn
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsort_whats_new.py
executable file
·45 lines (36 loc) · 1.22 KB
/
sort_whats_new.py
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
#!/usr/bin/env python
# Sorts what's new entries with per-module headings.
# Pass what's new entries on stdin.
import sys
import re
from collections import defaultdict
LABEL_ORDER = ['MajorFeature', 'Feature', 'Enhancement', 'Efficiency',
'Fix', 'API']
def entry_sort_key(s):
if s.startswith('- |'):
return LABEL_ORDER.index(s.split('|')[1])
else:
return -1
# discard headings and other non-entry lines
text = ''.join(l for l in sys.stdin
if l.startswith('- ') or l.startswith(' '))
bucketed = defaultdict(list)
for entry in re.split('\n(?=- )', text.strip()):
modules = re.findall(r':(?:func|meth|mod|class):'
r'`(?:[^<`]*<|~)?(?:sklearn.)?([a-z]\w+)',
entry)
modules = set(modules)
if len(modules) > 1:
key = 'Multiple modules'
elif modules:
key = ':mod:`sklearn.%s`' % next(iter(modules))
else:
key = 'Miscellaneous'
bucketed[key].append(entry)
entry = entry.strip() + '\n'
everything = []
for key, bucket in sorted(bucketed.items()):
everything.append(key + '\n' + '.' * len(key))
bucket.sort(key=entry_sort_key)
everything.extend(bucket)
print('\n\n'.join(everything))