MCPcopy Create free account
hub / github.com/numpy/numpy / nep_metadata

Function nep_metadata

doc/neps/tools/build_index.py:19–102  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 1

build_index.pyFile · 0.85

Calls 5

printFunction · 0.85
openFunction · 0.85
rstripMethod · 0.80
stripMethod · 0.80
startswithMethod · 0.80

Tested by

no test coverage detected