Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b89f75f

Browse files
authored
Link to the correct PEP source file. (GH-1195)
Some PEPs are using the .rst extension, and many are in .txt. The source link assumed that all the PEPs are using the .txt extension. With this change, it will use the correct file extension. Fixes python/peps#431
1 parent e17bb48 commit b89f75f

File tree

4 files changed

+104
-1
lines changed

4 files changed

+104
-1
lines changed

peps/converters.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,14 @@ def convert_pep_page(pep_number, content):
181181

182182
data['content'] = str(pep_content)
183183

184-
source_link = "https://github.com/python/peps/blob/master/pep-{0}.txt".format(pep_number)
184+
pep_ext = '.txt'
185+
pep_rst_source = os.path.join(settings.PEP_REPO_PATH,
186+
'pep-{}.rst'.format(pep_number))
187+
if os.path.exists(pep_rst_source):
188+
pep_ext = '.rst'
189+
190+
source_link = 'https://github.com/python/peps/blob/master/pep-{}{}'.format(
191+
pep_number, pep_ext)
185192
data['content'] += """Source: <a href="{0}">{0}</a>""".format(source_link)
186193
return data
187194

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!--
2+
This HTML is auto-generated. DO NOT EDIT THIS FILE! If you are writing a new
3+
PEP, see http://www.python.org/dev/peps/pep-0001 for instructions and links
4+
to templates. DO NOT USE THIS HTML FILE AS YOUR TEMPLATE!
5+
-->
6+
<table class="rfc2822 docutils field-list" frame="void" rules="none">
7+
<col class="field-name" />
8+
<col class="field-body" />
9+
<tbody valign="top">
10+
<tr class="field"><th class="field-name">PEP:</th><td class="field-body">12</td>
11+
</tr>
12+
<tr class="field"><th class="field-name">Title:</th><td class="field-body">Sample reStructuredText PEP Template</td>
13+
</tr>
14+
<tr class="field"><th class="field-name">Author:</th><td class="field-body">David Goodger &lt;goodger&#32;&#97;t&#32;python.org&gt;,
15+
Barry Warsaw &lt;barry&#32;&#97;t&#32;python.org&gt;</td>
16+
</tr>
17+
<tr class="field"><th class="field-name">Status:</th><td class="field-body">Active</td>
18+
</tr>
19+
<tr class="field"><th class="field-name">Type:</th><td class="field-body">Process</td>
20+
</tr>
21+
<tr class="field"><th class="field-name">Content-Type:</th><td class="field-body"><a class="reference external" href="/dev/peps/pep-0012">text/x-rst</a></td>
22+
</tr>
23+
<tr class="field"><th class="field-name">Created:</th><td class="field-body">05-Aug-2002</td>
24+
</tr>
25+
<tr class="field"><th class="field-name">Post-History:</th><td class="field-body">30-Aug-2002</td>
26+
</tr>
27+
</tbody>
28+
</table>
29+
<hr />
30+
<div class="contents topic" id="contents">
31+
<p class="topic-title first">Contents</p>
32+
<ul class="simple">
33+
<li><a class="reference internal" href="#abstract" id="id2">Abstract</a></li>
34+
<li><a class="reference internal" href="#copyright" id="id3">Copyright</a></li>
35+
</ul>
36+
</div>
37+
<div class="section" id="abstract">
38+
<h1><a class="toc-backref" href="#id2">Abstract</a></h1>
39+
<p>This PEP provides a boilerplate or sample template for creating your
40+
own reStructuredText PEPs.</p>
41+
</div>
42+
<div class="section" id="copyright">
43+
<h1><a class="toc-backref" href="#id3">Copyright</a></h1>
44+
<p>This document has been placed in the public domain.</p>
45+
<!-- Local Variables:
46+
mode: indented-text
47+
indent-tabs-mode: nil
48+
sentence-end-double-space: t
49+
fill-column: 70
50+
coding: utf-8
51+
End: -->
52+
</div>
53+

peps/tests/fake_pep_repo/pep-0012.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
PEP: 12
2+
Title: Sample reStructuredText PEP Template
3+
Author: David Goodger <[email protected]>,
4+
Barry Warsaw <[email protected]>
5+
Status: Active
6+
Type: Process
7+
Content-Type: text/x-rst
8+
Created: 05-Aug-2002
9+
Post-History: 30-Aug-2002
10+
11+
12+
Abstract
13+
========
14+
15+
This PEP provides a boilerplate or sample template for creating your
16+
own reStructuredText PEPs.
17+
18+
19+
Copyright
20+
=========
21+
22+
This document has been placed in the public domain.
23+
24+
25+
26+
..
27+
Local Variables:
28+
mode: indented-text
29+
indent-tabs-mode: nil
30+
sentence-end-double-space: t
31+
fill-column: 70
32+
coding: utf-8
33+
End:

peps/tests/test_converters.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ def test_source_link(self):
2424
pep.content.rendered
2525
)
2626

27+
@override_settings(PEP_REPO_PATH=FAKE_PEP_REPO)
28+
def test_source_link_rst(self):
29+
pep = get_pep_page('0012')
30+
self.assertEqual(pep.title, 'PEP 12 -- Sample reStructuredText PEP Template')
31+
self.assertIn(
32+
'Source: <a href="https://github.com/python/peps/blob/master/'
33+
'pep-0012.rst">https://github.com/python/peps/blob/master/pep-0012.rst</a>',
34+
pep.content.rendered
35+
)
36+
2737
@override_settings(PEP_REPO_PATH=FAKE_PEP_REPO)
2838
def test_invalid_pep_number(self):
2939
with captured_stdout() as stdout:

0 commit comments

Comments
 (0)