8000 [MRG] MNT Tools for working with what's new (#11800) · xhluca/scikit-learn@e168bd7 · GitHub
[go: up one dir, main page]

Skip to content

Commit e168bd7

Browse files
jnothmanXing
authored andcommitted
[MRG] MNT Tools for working with what's new (scikit-learn#11800)
1 parent 172a1eb commit e168bd7

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

doc/developers/maintainer.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ For more information see https://github.com/scikit-learn/scikit-learn/wiki/How-t
1717

1818
1. Update docs:
1919

20+
- ``maint_tools/sort_whats_new.py`` can put what's new entries into
21+
sections.
22+
23+
- The ``maint_tools/whats_missing.sh`` script may be used to identify pull
24+
requests that were merged but likely missing from What's New.
25+
2026
- Edit the doc/whats_new.rst file to add release title and commit
2127
statistics. You can retrieve commit statistics with::
2228

maint_tools/sort_whats_new.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python
2+
# Sorts what's new entries with per-module headings.
3+
# Pass what's new entries on stdin.
4+
5+
import sys
6+
import re
7+
from collections import defaultdict
8+
9+
LABEL_ORDER = ['MajorFeature', 'Feature', 'Enhancement', 'Efficiency',
10+
'Fix', 'API']
11+
12+
13+
def entry_sort_key(s):
14+
if s.startswith('- |'):
15+
return LABEL_ORDER.index(s.split('|')[1])
16+
else:
17+
return -1
18+
19+
20+
# discard headings and other non-entry lines
21+
text = ''.join(l for l in sys.stdin
22+
if l.startswith('- ') or l.startswith(' '))
23+
24+
bucketed = defaultdict(list)
25+
26+
for entry in re.split('\n(?=- )', text.strip()):
27+
modules = re.findall(r':(?:func|meth|mod|class):'
28+
r'`(?:[^<`]*<|~)?(?:sklearn.)?([a-z]\w+)',
29+
entry)
30+
modules = set(modules)
31+
if len(modules) > 1:
32+
key = 'Multiple modules'
33+
elif modules:
34+
key = ':mod:`sklearn.%s`' % next(iter(modules))
35+
else:
36+
key = 'Miscellaneous'
37+
bucketed[key].append(entry)
38+
entry = entry.strip() + '\n'
39+
40+
everything = []
41+
for key, bucket in sorted(bucketed.items()):
42+
everything.append(key + '\n' + '.' * len(key))
43+
bucket.sort(key=entry_sort_key)
44+
everything.extend(bucket)
45+
print('\n\n'.join(everything))

maint_tools/whats_missing.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
# This script helps identify pull requests that were merged without a what's
3+
# new entry, where one would be appropriate.
4+
5+
if [ $# -ne 2 ]
6+
then
7+
echo "Usage: GITHUB_TOKEN=... $0 <prev_release_ref> <whats_new_version>" >&2
8+
exit 1
9+
fi
10+
from_branch=$1
11+
to_file=$2
12+
13+
logged_prs() {
14+
git log --oneline $from_branch..master sklearn/ |
15+
grep -wv -e CI -e DOC -e doc -e MNT -e MAINT -e BLD -e COSMIT -e EXA -e examples -e example -e minor -e STY -e Style -e docstring |
16+
grep -o '(#[0-9][0-9]\+)$' |
17+
grep -o '[0-9]\+'
18+
}
19+
20+
mentioned_issues() {
21+
cat doc/whats_new/v$to_file.rst |
22+
grep -o 'issue:`[0-9]\+`' |
23+
grep -o '[0-9]\+'
24+
}
25+
26+
get_closed_issues() {
27+
pr=$1
28+
url=https://api.github.com/repos/scikit-learn/scikit-learn/pulls/$pr
29+
python - $url <<EOF
30+
import json
31+
import sys
32+
import re
33+
import os
34+
from urllib import request
35+
36+
req = request.Request(sys.argv[1], headers={"Authorization": "token %s" % os.environ['GITHUB_TOKEN']})
37+
body = json.loads(request.urlopen(req).read().decode('utf8'))['body']
38+
body = re.sub('<!--.*?-->', '', body, flags=re.DOTALL)
39+
matches = re.findall(r'(?i)\\b(?:fix|fixes|resolve|resolves|close|closes) +(?:https?://github.com/scikit-learn/scikit-learn/(?:pull|issues)/|#)?([0-9]+)',
40+
body)
41+
print(' '.join(matches))
42+
EOF
43+
}
44+
45+
pr_numbers=$(diff <(logged_prs | sort) <(mentioned_issues | sort) |
46+
grep '<' |
47+
cut -c3- |
48+
grep -v -w -Ff <(git log --oneline $from_branch | grep -o '(#[0-9][0-9]\+)$' | grep -o '[0-9]\+') ) # drop things already released
49+
50+
filtered_pr_numbers=$(
51+
for pr in $pr_numbers
52+
do
53+
echo $pr $(get_closed_issues $pr)
54+
done |
55+
grep -v -wFf <(mentioned_issues) |
56+
cut -d' ' -f1
57+
)
58+
59+
echo $filtered_pr_numbers |
60+
sed 's/[^ ]*/--grep (#&)/g' |
61+
xargs git log

0 commit comments

Comments
 (0)
0