2011-03-25 23:49:11 -04:00
|
|
|
#!/usr/bin/env python
|
2008-12-30 12:44:11 -05:00
|
|
|
"""Auto-generate PEP 0 (PEP index).
|
|
|
|
|
|
|
|
Generating the PEP index is a multi-step process. To begin, you must first
|
|
|
|
parse the PEP files themselves, which in and of itself takes a couple of steps:
|
|
|
|
|
|
|
|
1. Parse metadata.
|
|
|
|
2. Validate metadata.
|
|
|
|
|
|
|
|
With the PEP information collected, to create the index itself you must:
|
|
|
|
|
|
|
|
1. Output static text.
|
|
|
|
2. Format an entry for the PEP.
|
|
|
|
3. Output the PEP (both by category and numerical index).
|
|
|
|
|
|
|
|
"""
|
|
|
|
from __future__ import absolute_import, with_statement
|
2015-08-08 17:04:29 -04:00
|
|
|
from __future__ import print_function
|
2008-12-30 12:44:11 -05:00
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import codecs
|
|
|
|
|
|
|
|
from operator import attrgetter
|
|
|
|
|
|
|
|
from pep0.output import write_pep0
|
2009-01-04 20:12:53 -05:00
|
|
|
from pep0.pep import PEP, PEPError
|
2008-12-30 12:44:11 -05:00
|
|
|
|
|
|
|
|
|
|
|
def main(argv):
|
|
|
|
if not argv[1:]:
|
|
|
|
path = '.'
|
|
|
|
else:
|
|
|
|
path = argv[1]
|
|
|
|
|
|
|
|
peps = []
|
|
|
|
if os.path.isdir(path):
|
|
|
|
for file_path in os.listdir(path):
|
2010-09-27 16:49:32 -04:00
|
|
|
if file_path == 'pep-0000.txt':
|
|
|
|
continue
|
2008-12-30 12:44:11 -05:00
|
|
|
abs_file_path = os.path.join(path, file_path)
|
|
|
|
if not os.path.isfile(abs_file_path):
|
|
|
|
continue
|
2016-06-23 18:57:01 -04:00
|
|
|
if file_path.startswith("pep-") and file_path.endswith((".txt", "rst")):
|
2008-12-30 12:44:11 -05:00
|
|
|
with codecs.open(abs_file_path, 'r', encoding='UTF-8') as pep_file:
|
2009-01-04 20:12:53 -05:00
|
|
|
try:
|
2009-12-31 03:22:12 -05:00
|
|
|
pep = PEP(pep_file)
|
|
|
|
if pep.number != int(file_path[4:-4]):
|
|
|
|
raise PEPError('PEP number does not match file name',
|
|
|
|
file_path, pep.number)
|
|
|
|
peps.append(pep)
|
2015-08-08 17:04:29 -04:00
|
|
|
except PEPError as e:
|
2009-12-31 03:22:12 -05:00
|
|
|
errmsg = "Error processing PEP %s (%s), excluding:" % \
|
|
|
|
(e.number, e.filename)
|
2015-08-08 17:04:29 -04:00
|
|
|
print(errmsg, e, file=sys.stderr)
|
2009-01-04 20:12:53 -05:00
|
|
|
sys.exit(1)
|
2008-12-30 12:44:11 -05:00
|
|
|
peps.sort(key=attrgetter('number'))
|
|
|
|
elif os.path.isfile(path):
|
|
|
|
with open(path, 'r') as pep_file:
|
|
|
|
peps.append(PEP(pep_file))
|
|
|
|
else:
|
|
|
|
raise ValueError("argument must be a directory or file path")
|
|
|
|
|
2008-12-30 15:05:46 -05:00
|
|
|
with codecs.open('pep-0000.txt', 'w', encoding='UTF-8') as pep0_file:
|
2008-12-30 12:44:11 -05:00
|
|
|
write_pep0(peps, pep0_file)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main(sys.argv)
|