Last active
August 29, 2015 13:57
-
-
Save jsexauer/9926623 to your computer and use it in GitHub Desktop.
Interface with git to figure out commit and hint at PR that caused a line from grin to appear.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Take a girn output and find the commits and PRs that caused that code | |
to be added. | |
""" | |
# Find all PRs that brought in future warnings | |
# for https://github.com/pydata/pandas/issues/6641 | |
# Make sure you have a copy of all the PRs in your upstream | |
# See: | |
# http://stackoverflow.com/questions/17818167/find-a-pull-request-on-github-where-a-commit-was-originally-created | |
import git | |
repo = git.Repo(r"D:\Projects\pandas") | |
assert not repo.is_dirty | |
token = 'FutureWarning' | |
pep8_storm = ['66fc98f0', 'f36591e4', 'ef7c55e2', 'afbde4d7'] | |
# Output from grin command | |
grin = r""" | |
.\doc\source\release.rst: | |
162 : ``FutureWarning`` is raised to alert that the old ``rows`` and ``cols`` arguments | |
167 : :meth:`DataFrame.dropna`. A ``FutureWarning`` is raised to alert that the old | |
172 : ``FutureWarning`` is raised to alert that the old ``cols`` arguments | |
1385 : - set FutureWarning to require data_source, and to replace year/month with | |
4192 : `combineFirst` to `combine_first`. Will print `FutureWarning`. | |
4293 : `FutureWarning` added. | |
4295 : **fillna**, `FutureWarning` added to **fill** | |
4296 : - Renamed **DataFrame.getXS** to **xs**, `FutureWarning` added | |
.\doc\source\v0.14.0.txt: | |
336 : ``FutureWarning`` is raised to alert that the old ``rows`` and ``cols`` arguments | |
341 : :meth:`DataFrame.dropna`. A ``FutureWarning`` is raised to alert that the old | |
346 : ``FutureWarning`` is raised to alert that the old ``cols`` arguments | |
.\doc\source\v0.7.0.txt: | |
237 : ``FutureWarning`` | |
.\doc\sphinxext\numpydoc\linkcode.py: | |
20 : FutureWarning, stacklevel=1) | |
.\doc\sphinxext\numpydoc\plot_directive.py: | |
92 : FutureWarning, stacklevel=2) | |
.\pandas\core\common.py: | |
2740 : warnings.warn("load is deprecated, use read_pickle", FutureWarning) | |
2756 : warnings.warn("save is deprecated, use obj.to_pickle", FutureWarning) | |
.\pandas\core\daterange.py: | |
24 : FutureWarning) | |
.\pandas\core\datetools.py: | |
55 : FutureWarning) | |
.\pandas\core\format.py: | |
369 : FutureWarning) | |
442 : FutureWarning) | |
2143 : "being renamed to 'accuracy'", FutureWarning) | |
.\pandas\core\frame.py: | |
1133 : FutureWarning) | |
1283 : "effect", FutureWarning) | |
1287 : FutureWarning) | |
1292 : FutureWarning) | |
1342 : "effect", FutureWarning) | |
1346 : FutureWarning) | |
1388 : "effect", FutureWarning) | |
1392 : FutureWarning) | |
2837 : FutureWarning) | |
.\pandas\core\generic.py: | |
960 : warnings.warn("save is deprecated, use to_pickle", FutureWarning) | |
967 : warnings.warn("load is deprecated, use pd.read_pickle", FutureWarning) | |
.\pandas\core\series.py: | |
910 : warnings.warn("nanRep is deprecated, use na_rep", FutureWarning) | |
1770 : FutureWarning) | |
.\pandas\io\data.py: | |
344 : "instead.", FutureWarning) | |
588 : " data_source) instead", FutureWarning) | |
811 : " instead", FutureWarning) | |
848 : warnings.warn("get_forward_data() is deprecated", FutureWarning) | |
.\pandas\io\excel.py: | |
103 : "removed in a future version", FutureWarning) | |
.\pandas\io\html.py: | |
830 : warnings.warn("infer_types will have no effect in 0.14", FutureWarning) | |
.\pandas\io\pytables.py: | |
691 : FutureWarning) | |
1124 : warnings.warn(format_deprecate_doc, FutureWarning) | |
.\pandas\io\tests\test_data.py: | |
311 : with assert_produces_warning(FutureWarning): | |
.\pandas\io\tests\test_excel.py: | |
401 : with tm.assert_produces_warning(FutureWarning): | |
.\pandas\io\tests\test_html.py: | |
145 : with tm.assert_produces_warning(FutureWarning): | |
148 : with tm.assert_produces_warning(FutureWarning): | |
243 : with tm.assert_produces_warning(FutureWarning): | |
246 : with tm.assert_produces_warning(FutureWarning): | |
258 : with tm.assert_produces_warning(FutureWarning): | |
261 : with tm.assert_produces_warning(FutureWarning): | |
266 : with tm.assert_produces_warning(FutureWarning): | |
593 : with tm.assert_produces_warning(FutureWarning): | |
649 : with tm.assert_produces_warning(FutureWarning): | |
.\pandas\io\tests\test_parsers.py: | |
62 : warnings.filterwarnings(action='ignore', category=FutureWarning) | |
.\pandas\io\tests\test_pytables.py: | |
127 : warnings.filterwarnings(action='ignore', category=FutureWarning) | |
.\pandas\sparse\tests\test_sparse.py: | |
41 : warnings.filterwarnings(action='ignore', category=FutureWarning) | |
.\pandas\stats\moments.py: | |
301 : warnings.warn("rolling_corr_pairwise is deprecated, use rolling_corr(..., pairwise=True)", FutureWarning) | |
554 : FutureWarning) | |
957 : warnings.warn("expanding_corr_pairwise is deprecated, use expanding_corr(..., pairwise=True)", FutureWarning) | |
.\pandas\tests\test_format.py: | |
78 : category=FutureWarning, | |
.\pandas\tests\test_frame.py: | |
1887 : warnings.filterwarnings(action='ignore', category=FutureWarning) | |
4323 : category=FutureWarning, | |
5443 : with tm.assert_produces_warning(FutureWarning): | |
6961 : with tm.assert_produces_warning(FutureWarning): | |
7110 : with tm.assert_produces_warning(FutureWarning): | |
.\pandas\tests\test_generic.py: | |
51 : warnings.filterwarnings(action='ignore', category=FutureWarning) | |
.\pandas\tests\test_index.py: | |
2112 : category=FutureWarning, | |
.\pandas\tests\test_indexing.py: | |
98 : warnings.filterwarnings(action='ignore', category=FutureWarning) | |
.\pandas\tests\test_multilevel.py: | |
29 : warnings.filterwarnings(action='ignore', category=FutureWarning) | |
.\pandas\tests\test_panel.py: | |
824 : warnings.filterwarnings(action='ignore', category=FutureWarning) | |
2010 : warnings.filterwarnings(action='ignore', category=FutureWarning) | |
.\pandas\tests\test_series.py: | |
329 : warnings.filterwarnings(action='ignore', category=FutureWarning) | |
.\pandas\tools\tests\test_pivot.py: | |
61 : with tm.assert_produces_warning(FutureWarning): | |
.\pandas\tseries\frequencies.py: | |
247 : " attribute of DatetimeIndex", FutureWarning) | |
.\pandas\tseries\index.py: | |
180 : FutureWarning) | |
.\pandas\util\decorators.py: | |
13 : FutureWarning) | |
39 : FutureWarning: cols is deprecated, use columns instead | |
40 : warnings.warn(msg, FutureWarning) | |
53 : warnings.warn(msg, FutureWarning) | |
.\vb_suite\measure_memory_consumption.py: | |
25 : warnings.filterwarnings('ignore', category=FutureWarning) | |
.\vb_suite\perf_HEAD.py: | |
92 : warnings.filterwarnings('ignore', category=FutureWarning) | |
.\vb_suite\test_perf.py: | |
601 : warnings.filterwarnings('ignore',category=FutureWarning) | |
""" | |
_file = '' | |
_file_blame = '' | |
for grin_line in grin.split('\n'): | |
if grin_line in ('', '\n'): | |
continue | |
if grin_line.startswith('.' + '\\'): | |
# This line describe which file these changes are in | |
_file = grin_line.split(':')[0] | |
_file_blame = '\n' + repo.git.blame(_file) # Prefix \n because no line 0 | |
_file_blame = _file_blame.split('\n') | |
print '='*80 | |
print grin_line | |
else: | |
# This line describes a line with expected token | |
special_msg = '' | |
line_num, code = grin_line.split(':',1) | |
line_num = int(line_num) | |
assert _file_blame[line_num].find(code) > -1 | |
commit = _file_blame[line_num][:8] | |
if commit in pep8_storm: | |
# Navigate around the pep 8 storm | |
# Find the commit before the pep8 storm | |
special_msg = ' (from before pep8 storm)' | |
prev_commit = repo.commit(commit).parents[0].id_abbrev | |
new_blame = repo.git.blame(_file, prev_commit) | |
new_blame = '\n' + new_blame | |
new_blame = new_blame.split('\n') | |
eps = 0 | |
while True: | |
try: | |
if token in new_blame[line_num+eps]: | |
commit = new_blame[line_num+eps][:8] | |
break | |
if token in new_blame[line_num-eps]: | |
commit = new_blame[line_num-eps][:8] | |
break | |
eps += 1 | |
if eps > 7: | |
special = ' **ERROR: Unable to navigate out of pep8 storm' | |
break | |
except IndexError: | |
special = ' **ERROR: Unable to navigate out of pep8 storm' | |
break | |
branch = repo.git.describe(commit, all=True, contains=True) | |
commit_msg = repo.commit(commit).message.replace('\n',' ') | |
if len(commit_msg) > 80: | |
commit_msg = commit_msg[:68] + '...' + commit_msg[-9:] | |
print grin_line | |
print ' > {} in {} {}'.format(commit, branch, special_msg) | |
print ' > "{}"'.format(commit_msg) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment