Skip to content

Commit

Permalink
Add consistency check for superseded NEPs
Browse files Browse the repository at this point in the history
A superseded NEP should have a Replaced-By header.  The replacing NEP
should have a Replaces header.  They should point to one another.
  • Loading branch information
stefanv committed Mar 22, 2018
1 parent ad014b9 commit d6730ee
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion doc/neps/tools/build_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def nep_metadata():
sources = sorted(glob.glob(r'nep-*.rst'))
sources = [s for s in sources if not s in ignore]

meta_re = r':([a-zA-Z]*): (.*)'
meta_re = r':([a-zA-Z\-]*): (.*)'

neps = {}
print('Loading metadata for:')
Expand All @@ -40,8 +40,44 @@ def nep_metadata():
tags['Title'] = lines[1].strip()
tags['Filename'] = source


if tags['Status'] in ('Accepted', 'Rejected', 'Withdrawn'):
if not 'Resolution' in tags:
raise RuntimeError(
f'NEP {nr} is Accepted/Rejected/Withdrawn but '
'has no Resolution tag'
)

neps[nr] = tags

# Now that we have all of the NEP metadata, do some global consistency
# checks

for nr, tags in neps.items():
if tags['Status'] == 'Superseded':
if not 'Replaced-By' in tags:
raise RuntimeError(
f'NEP {nr} has been Superseded, but has no Replaced-By tag'
)

replaced_by = int(tags['Replaced-By'])
replacement_nep = neps[replaced_by]

if not int(replacement_nep['Replaces']) == nr:
raise RuntimeError(
f'NEP {nr} is superseded by {replaced_by}, but that NEP has a '
f"Replaces tag of `{replacement_nep['Replaces']}`."
)

if 'Replaces' in tags:
replaced_nep = int(tags['Replaces'])
replaced_nep_tags = neps[replaced_nep]
if not replaced_nep_tags['Status'] == 'Superseded':
raise RuntimeError(
f'NEP {nr} replaces {replaced_nep}, but that NEP has not '
f'been set to Superseded'
)

return {'neps': neps}


Expand Down

0 comments on commit d6730ee

Please sign in to comment.