Skip to content

Handle pep files with .rst extensions. #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ PEP2HTML=pep2html.py

PYTHON=python

.SUFFIXES: .txt .html
.SUFFIXES: .txt .html .rst

.txt.html:
@$(PYTHON) $(PEP2HTML) $<

TARGETS=$(patsubst %.txt,%.html,$(wildcard pep-????.txt)) pep-0000.html
.rst.html:
@$(PYTHON) $(PEP2HTML) $<

TARGETS= $(patsubst %.rst,%.html,$(wildcard pep-????.rst)) $(patsubst %.txt,%.html,$(wildcard pep-????.txt)) pep-0000.html

all: pep-0000.txt $(TARGETS)

$(TARGETS): pep2html.py

pep-0000.txt: $(wildcard pep-????.txt) $(wildcard pep0/*.py)
pep-0000.txt: $(wildcard pep-????.txt) $(wildcard pep-????.rst) $(wildcard pep0/*.py)
$(PYTHON) genpepindex.py .

rss:
Expand Down
2 changes: 1 addition & 1 deletion genpepindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def main(argv):
abs_file_path = os.path.join(path, file_path)
if not os.path.isfile(abs_file_path):
continue
if file_path.startswith("pep-") and file_path.endswith(".txt"):
if file_path.startswith("pep-") and file_path.endswith((".txt", "rst")):
with codecs.open(abs_file_path, 'r', encoding='UTF-8') as pep_file:
try:
pep = PEP(pep_file)
Expand Down
12 changes: 7 additions & 5 deletions pep-0012.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ the text (reStructuredText) source of this PEP in order to complete
the steps below. **DO NOT USE THE HTML FILE AS YOUR TEMPLATE!**

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


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

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

- Replace the "PEP: 12" header with "PEP: XXX" since you don't yet have
a PEP number assignment.
- Replace the "PEP: 12" header with "PEP: XXX" since you don't yet
have a PEP number assignment.

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

Expand Down
30 changes: 16 additions & 14 deletions pep2html.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@
-h, --help
Print this help message and exit.

The optional arguments ``peps`` are either pep numbers or .txt files.
The optional arguments ``peps`` are either pep numbers, .rst or .txt files.
"""

from __future__ import print_function, unicode_literals

import sys
import os
import re
import cgi
import glob
import getopt
import errno
Expand Down Expand Up @@ -75,7 +74,7 @@
DTD = ('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"\n'
' "http://www.w3.org/TR/REC-html40/loose.dtd">')

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


def find_pep(pep_str):
"""Find the .txt file indicated by a cmd line argument"""
"""Find the .rst or .txt file indicated by a cmd line argument"""
if os.path.exists(pep_str):
return pep_str
num = int(pep_str)
rstpath = "pep-%04d.rst" % num
if os.path.exists(rstpath):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you forgot to pass num to rstpath here.

return rstpath
return "pep-%04d.txt" % num

def make_html(inpath, verbose=0):
Expand Down Expand Up @@ -449,7 +451,7 @@ def check_requirements():
PEP_TYPE_DISPATCH['text/x-rst'] = None
PEP_TYPE_MESSAGES['text/x-rst'] = (
'Docutils not present for "%(pep_type)s" PEP file %(inpath)s. '
'See README.txt for installation.')
'See README.rst for installation.')
else:
installed = [int(part) for part in docutils.__version__.split('.')]
required = [int(part) for part in REQUIRES['docutils'].split('.')]
Expand All @@ -458,7 +460,7 @@ def check_requirements():
PEP_TYPE_MESSAGES['text/x-rst'] = (
'Docutils must be reinstalled for "%%(pep_type)s" PEP '
'processing (%%(inpath)s). Version %s or better required; '
'%s present. See README.txt for installation.'
'%s present. See README.rst for installation.'
% (REQUIRES['docutils'], docutils.__version__))

def pep_type_error(inpath, pep_type):
Expand All @@ -469,7 +471,7 @@ def pep_type_error(inpath, pep_type):
def browse_file(pep):
import webbrowser
file = find_pep(pep)
if file.endswith(".txt"):
if file.startswith('pep-') and file.endswith((".txt", '.rst')):
file = file[:-3] + "html"
file = os.path.abspath(file)
url = "file:" + file
Expand All @@ -478,7 +480,7 @@ def browse_file(pep):
def browse_remote(pep):
import webbrowser
file = find_pep(pep)
if file.endswith(".txt"):
if file.startswith('pep-') and file.endswith((".txt", '.rst')):
file = file[:-3] + "html"
url = PEPDIRRUL + file
webbrowser.open(url)
Expand Down Expand Up @@ -520,32 +522,32 @@ def main(argv=None):
browse = 1

if args:
peptxt = []
pep_list = []
html = []
for pep in args:
file = find_pep(pep)
peptxt.append(file)
pep_list.append(file)
newfile = make_html(file, verbose=verbose)
if newfile:
html.append(newfile)
if browse and not update:
browse_file(pep)
else:
# do them all
peptxt = []
pep_list = []
html = []
files = glob.glob("pep-*.txt")
files = glob.glob("pep-*.txt") + glob.glob("pep-*.rst")
files.sort()
for file in files:
peptxt.append(file)
pep_list.append(file)
newfile = make_html(file, verbose=verbose)
if newfile:
html.append(newfile)
if browse and not update:
browse_file("0")

if update:
push_pep(html, peptxt, username, verbose, local=local)
push_pep(html, pep_list, username, verbose, local=local)
if browse:
if args:
for pep in args:
Expand Down