Skip to content

Commit c7adf11

Browse files
authored
Merge pull request #32 from Carreau/rst-peps
Handle PEP files with `.rst` extensions
2 parents b409f87 + 68764e0 commit c7adf11

File tree

4 files changed

+30
-23
lines changed

4 files changed

+30
-23
lines changed

Makefile

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@ PEP2HTML=pep2html.py
77

88
PYTHON=python
99

10-
.SUFFIXES: .txt .html
10+
.SUFFIXES: .txt .html .rst
1111

1212
.txt.html:
1313
@$(PYTHON) $(PEP2HTML) $<
1414

15-
TARGETS=$(patsubst %.txt,%.html,$(wildcard pep-????.txt)) pep-0000.html
15+
.rst.html:
16+
@$(PYTHON) $(PEP2HTML) $<
17+
18+
TARGETS= $(patsubst %.rst,%.html,$(wildcard pep-????.rst)) $(patsubst %.txt,%.html,$(wildcard pep-????.txt)) pep-0000.html
1619

1720
all: pep-0000.txt $(TARGETS)
1821

1922
$(TARGETS): pep2html.py
2023

21-
pep-0000.txt: $(wildcard pep-????.txt) $(wildcard pep0/*.py)
24+
pep-0000.txt: $(wildcard pep-????.txt) $(wildcard pep-????.rst) $(wildcard pep0/*.py)
2225
$(PYTHON) genpepindex.py .
2326

2427
rss:

genpepindex.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def main(argv):
4141
abs_file_path = os.path.join(path, file_path)
4242
if not os.path.isfile(abs_file_path):
4343
continue
44-
if file_path.startswith("pep-") and file_path.endswith(".txt"):
44+
if file_path.startswith("pep-") and file_path.endswith((".txt", "rst")):
4545
with codecs.open(abs_file_path, 'r', encoding='UTF-8') as pep_file:
4646
try:
4747
pep = PEP(pep_file)

pep-0012.txt

+7-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ the text (reStructuredText) source of this PEP in order to complete
2424
the steps below. **DO NOT USE THE HTML FILE AS YOUR TEMPLATE!**
2525

2626
The source for this (or any) PEP can be found in the PEPs repository,
27-
viewable on the web at https://hg.python.org/peps/file/tip .
27+
viewable on the web at https://github.com/python/peps/ .
2828

2929

3030
Rationale
@@ -53,11 +53,13 @@ or contact the PEP editors <[email protected]>.
5353
Once you've decided which type of PEP yours is going to be, follow the
5454
directions below.
5555

56-
- Make a copy of this file (``.txt`` file, **not** HTML!) and perform
57-
the following edits.
56+
- Make a copy of this file (``.txt`` or ``.rst`` file, **not** HTML!)
57+
and perform the following edits. Prefer ``.rst`` extensions as this
58+
will allow PEPs to be rendered on GitHub. ``.txt`` extensions still
59+
exists for legacy reasons.
5860

59-
- Replace the "PEP: 12" header with "PEP: XXX" since you don't yet have
60-
a PEP number assignment.
61+
- Replace the "PEP: 12" header with "PEP: XXX" since you don't yet
62+
have a PEP number assignment.
6163

6264
- Change the Title header to the title of your PEP.
6365

pep2html.py

+16-14
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,14 @@
3131
-h, --help
3232
Print this help message and exit.
3333
34-
The optional arguments ``peps`` are either pep numbers or .txt files.
34+
The optional arguments ``peps`` are either pep numbers, .rst or .txt files.
3535
"""
3636

3737
from __future__ import print_function, unicode_literals
3838

3939
import sys
4040
import os
4141
import re
42-
import cgi
4342
import glob
4443
import getopt
4544
import errno
@@ -75,7 +74,7 @@
7574
DTD = ('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"\n'
7675
' "http://www.w3.org/TR/REC-html40/loose.dtd">')
7776

78-
fixpat = re.compile("((https?|ftp):[-_a-zA-Z0-9/.+~:?#$=&,]+)|(pep-\d+(.txt)?)|"
77+
fixpat = re.compile("((https?|ftp):[-_a-zA-Z0-9/.+~:?#$=&,]+)|(pep-\d+(.txt|.rst)?)|"
7978
"(RFC[- ]?(?P<rfcnum>\d+))|"
8079
"(PEP\s+(?P<pepnum>\d+))|"
8180
".")
@@ -367,10 +366,13 @@ def get_input_lines(inpath):
367366

368367

369368
def find_pep(pep_str):
370-
"""Find the .txt file indicated by a cmd line argument"""
369+
"""Find the .rst or .txt file indicated by a cmd line argument"""
371370
if os.path.exists(pep_str):
372371
return pep_str
373372
num = int(pep_str)
373+
rstpath = "pep-%04d.rst" % num
374+
if os.path.exists(rstpath):
375+
return rstpath
374376
return "pep-%04d.txt" % num
375377

376378
def make_html(inpath, verbose=0):
@@ -449,7 +451,7 @@ def check_requirements():
449451
PEP_TYPE_DISPATCH['text/x-rst'] = None
450452
PEP_TYPE_MESSAGES['text/x-rst'] = (
451453
'Docutils not present for "%(pep_type)s" PEP file %(inpath)s. '
452-
'See README.txt for installation.')
454+
'See README.rst for installation.')
453455
else:
454456
installed = [int(part) for part in docutils.__version__.split('.')]
455457
required = [int(part) for part in REQUIRES['docutils'].split('.')]
@@ -458,7 +460,7 @@ def check_requirements():
458460
PEP_TYPE_MESSAGES['text/x-rst'] = (
459461
'Docutils must be reinstalled for "%%(pep_type)s" PEP '
460462
'processing (%%(inpath)s). Version %s or better required; '
461-
'%s present. See README.txt for installation.'
463+
'%s present. See README.rst for installation.'
462464
% (REQUIRES['docutils'], docutils.__version__))
463465

464466
def pep_type_error(inpath, pep_type):
@@ -469,7 +471,7 @@ def pep_type_error(inpath, pep_type):
469471
def browse_file(pep):
470472
import webbrowser
471473
file = find_pep(pep)
472-
if file.endswith(".txt"):
474+
if file.startswith('pep-') and file.endswith((".txt", '.rst')):
473475
file = file[:-3] + "html"
474476
file = os.path.abspath(file)
475477
url = "file:" + file
@@ -478,7 +480,7 @@ def browse_file(pep):
478480
def browse_remote(pep):
479481
import webbrowser
480482
file = find_pep(pep)
481-
if file.endswith(".txt"):
483+
if file.startswith('pep-') and file.endswith((".txt", '.rst')):
482484
file = file[:-3] + "html"
483485
url = PEPDIRRUL + file
484486
webbrowser.open(url)
@@ -520,32 +522,32 @@ def main(argv=None):
520522
browse = 1
521523

522524
if args:
523-
peptxt = []
525+
pep_list = []
524526
html = []
525527
for pep in args:
526528
file = find_pep(pep)
527-
peptxt.append(file)
529+
pep_list.append(file)
528530
newfile = make_html(file, verbose=verbose)
529531
if newfile:
530532
html.append(newfile)
531533
if browse and not update:
532534
browse_file(pep)
533535
else:
534536
# do them all
535-
peptxt = []
537+
pep_list = []
536538
html = []
537-
files = glob.glob("pep-*.txt")
539+
files = glob.glob("pep-*.txt") + glob.glob("pep-*.rst")
538540
files.sort()
539541
for file in files:
540-
peptxt.append(file)
542+
pep_list.append(file)
541543
newfile = make_html(file, verbose=verbose)
542544
if newfile:
543545
html.append(newfile)
544546
if browse and not update:
545547
browse_file("0")
546548

547549
if update:
548-
push_pep(html, peptxt, username, verbose, local=local)
550+
push_pep(html, pep_list, username, verbose, local=local)
549551
if browse:
550552
if args:
551553
for pep in args:

0 commit comments

Comments
 (0)