()
| 18 | ).get_template(filename).render(context) |
| 19 | |
| 20 | def nep_metadata(): |
| 21 | ignore = ('nep-template.rst') |
| 22 | sources = sorted(glob.glob(r'nep-*.rst')) |
| 23 | sources = [s for s in sources if s not in ignore] |
| 24 | |
| 25 | meta_re = r':([a-zA-Z\-]*): (.*)' |
| 26 | |
| 27 | has_provisional = False |
| 28 | neps = {} |
| 29 | print('Loading metadata for:') |
| 30 | for source in sources: |
| 31 | print(f' - {source}') |
| 32 | nr = int(re.match(r'nep-([0-9]{4}).*\.rst', source).group(1)) |
| 33 | |
| 34 | with open(source) as f: |
| 35 | lines = f.readlines() |
| 36 | tags = [re.match(meta_re, line) for line in lines] |
| 37 | tags = [match.groups() for match in tags if match is not None] |
| 38 | tags = {tag[0]: tag[1] for tag in tags} |
| 39 | |
| 40 | # The title should be the first line after a line containing only |
| 41 | # * or = signs. |
| 42 | for i, line in enumerate(lines[:-1]): |
| 43 | chars = set(line.rstrip()) |
| 44 | if len(chars) == 1 and ("=" in chars or "*" in chars): |
| 45 | break |
| 46 | else: |
| 47 | raise RuntimeError("Unable to find NEP title.") |
| 48 | |
| 49 | tags['Title'] = lines[i + 1].strip() |
| 50 | tags['Filename'] = source |
| 51 | |
| 52 | if not tags['Title'].startswith(f'NEP {nr} — '): |
| 53 | raise RuntimeError( |
| 54 | f'Title for NEP {nr} does not start with "NEP {nr} — " ' |
| 55 | '(note that — here is a special, elongated dash). Got: ' |
| 56 | f' {tags["Title"]!r}') |
| 57 | |
| 58 | if tags['Status'] in ('Accepted', 'Rejected', 'Withdrawn'): |
| 59 | if 'Resolution' not in tags: |
| 60 | raise RuntimeError( |
| 61 | f'NEP {nr} is Accepted/Rejected/Withdrawn but ' |
| 62 | 'has no Resolution tag' |
| 63 | ) |
| 64 | if tags['Status'] == 'Provisional': |
| 65 | has_provisional = True |
| 66 | |
| 67 | neps[nr] = tags |
| 68 | |
| 69 | # Now that we have all of the NEP metadata, do some global consistency |
| 70 | # checks |
| 71 | |
| 72 | for nr, tags in neps.items(): |
| 73 | if tags['Status'] == 'Superseded': |
| 74 | if 'Replaced-By' not in tags: |
| 75 | raise RuntimeError( |
| 76 | f'NEP {nr} has been Superseded, but has no Replaced-By tag' |
| 77 | ) |
no test coverage detected
searching dependent graphs…