From 4012c124e1fbe6cfaa119b8e32b9d9caa7436fb5 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Thu, 23 Jun 2016 15:57:01 -0700 Subject: [PATCH] Handle pep files with `.rst` extensions. --- Makefile | 9 ++++++--- genpepindex.py | 2 +- pep2html.py | 30 ++++++++++++++++-------------- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 511b47710..484302c5c 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/genpepindex.py b/genpepindex.py index 39f05758a..d21ac1d46 100755 --- a/genpepindex.py +++ b/genpepindex.py @@ -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) diff --git a/pep2html.py b/pep2html.py index 791e60758..ef6aa975d 100755 --- a/pep2html.py +++ b/pep2html.py @@ -31,7 +31,7 @@ Options: -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 @@ -39,7 +39,6 @@ from __future__ import print_function, unicode_literals import sys import os import re -import cgi import glob import getopt import errno @@ -75,7 +74,7 @@ to templates. DO NOT USE THIS HTML FILE AS YOUR TEMPLATE! 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\d+))|" "(PEP\s+(?P\d+))|" ".") @@ -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): + return rstpath return "pep-%04d.txt" % num def make_html(inpath, verbose=0): @@ -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('.')] @@ -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): @@ -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 @@ -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) @@ -520,11 +522,11 @@ 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) @@ -532,12 +534,12 @@ def main(argv=None): 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) @@ -545,7 +547,7 @@ def main(argv=None): 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: