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

Skip to content

Link to the correct PEP source file. #1195

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
Nov 15, 2017
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: 8 additions & 1 deletion peps/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,14 @@ def convert_pep_page(pep_number, content):

data['content'] = str(pep_content)

source_link = "https://github.com/python/peps/blob/master/pep-{0}.txt".format(pep_number)
pep_ext = '.txt'
pep_rst_source = os.path.join(settings.PEP_REPO_PATH,
'pep-{}.rst'.format(pep_number))
if os.path.exists(pep_rst_source):
pep_ext = '.rst'
Copy link

Choose a reason for hiding this comment

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

That's an OK solution for just .txt or .rst.
Wouldn't it be possible to write a generic test, by looking for a glob pattern pep-{}.* and selecting the extension from that?
Because if the documentation system goes to .md or whatever new extension, the website code would again have to be changed here!

Copy link
Member

Choose a reason for hiding this comment

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

I'm pretty sure we aren't going to support another documentation format (especially Markdown) within the Python organization. Plus, we are going to move all PEP infrastructure to RtD so YAGNI :)

Copy link

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

And if we ever did, we'd probably move generation of the source link inside pep2html.py in the PEP's repo (we were even considering that as an option this time).

Copy link

Choose a reason for hiding this comment

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

OK @ncoghlan, I see.


source_link = 'https://github.com/python/peps/blob/master/pep-{}{}'.format(
pep_number, pep_ext)
data['content'] += """Source: <a href="{0}">{0}</a>""".format(source_link)
return data

Expand Down
53 changes: 53 additions & 0 deletions peps/tests/fake_pep_repo/pep-0012.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!--
This HTML is auto-generated. DO NOT EDIT THIS FILE! If you are writing a new
PEP, see http://www.python.org/dev/peps/pep-0001 for instructions and links
to templates. DO NOT USE THIS HTML FILE AS YOUR TEMPLATE!
-->
<table class="rfc2822 docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">PEP:</th><td class="field-body">12</td>
</tr>
<tr class="field"><th class="field-name">Title:</th><td class="field-body">Sample reStructuredText PEP Template</td>
</tr>
<tr class="field"><th class="field-name">Author:</th><td class="field-body">David Goodger &lt;goodger&#32;&#97;t&#32;python.org&gt;,
Barry Warsaw &lt;barry&#32;&#97;t&#32;python.org&gt;</td>
</tr>
<tr class="field"><th class="field-name">Status:</th><td class="field-body">Active</td>
</tr>
<tr class="field"><th class="field-name">Type:</th><td class="field-body">Process</td>
</tr>
<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>
</tr>
<tr class="field"><th class="field-name">Created:</th><td class="field-body">05-Aug-2002</td>
</tr>
<tr class="field"><th class="field-name">Post-History:</th><td class="field-body">30-Aug-2002</td>
</tr>
</tbody>
</table>
<hr />
<div class="contents topic" id="contents">
<p class="topic-title first">Contents</p>
<ul class="simple">
<li><a class="reference internal" href="#abstract" id="id2">Abstract</a></li>
<li><a class="reference internal" href="#copyright" id="id3">Copyright</a></li>
</ul>
</div>
<div class="section" id="abstract">
<h1><a class="toc-backref" href="#id2">Abstract</a></h1>
<p>This PEP provides a boilerplate or sample template for creating your
own reStructuredText PEPs.</p>
</div>
<div class="section" id="copyright">
<h1><a class="toc-backref" href="#id3">Copyright</a></h1>
<p>This document has been placed in the public domain.</p>
<!-- Local Variables:
mode: indented-text
indent-tabs-mode: nil
sentence-end-double-space: t
fill-column: 70
coding: utf-8
End: -->
</div>

33 changes: 33 additions & 0 deletions peps/tests/fake_pep_repo/pep-0012.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
PEP: 12
Title: Sample reStructuredText PEP Template
Author: David Goodger <[email protected]>,
Barry Warsaw <[email protected]>
Status: Active
Type: Process
Content-Type: text/x-rst
Created: 05-Aug-2002
Post-History: 30-Aug-2002


Abstract
========

This PEP provides a boilerplate or sample template for creating your
own reStructuredText PEPs.


Copyright
=========

This document has been placed in the public domain.



..
Local Variables:
mode: indented-text
indent-tabs-mode: nil
sentence-end-double-space: t
fill-column: 70
coding: utf-8
End:
10 changes: 10 additions & 0 deletions peps/tests/test_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ def test_source_link(self):
pep.content.rendered
)

@override_settings(PEP_REPO_PATH=FAKE_PEP_REPO)
def test_source_link_rst(self):
pep = get_pep_page('0012')
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to make the content of the PEP shorter?

self.assertEqual(pep.title, 'PEP 12 -- Sample reStructuredText PEP Template')
self.assertIn(
'Source: <a href="https://github.com/python/peps/blob/master/'
'pep-0012.rst">https://github.com/python/peps/blob/master/pep-0012.rst</a>',
pep.content.rendered
)

@override_settings(PEP_REPO_PATH=FAKE_PEP_REPO)
def test_invalid_pep_number(self):
with captured_stdout() as stdout:
Expand Down