PEP 12 – Sample reStructuredText PEP Template
- Author:
- David Goodger <goodger at python.org>, Barry Warsaw <barry at python.org>, Brett Cannon <brett at python.org>
- Status:
- Active
- Type:
- Process
- Created:
- 05-Aug-2002
- Post-History:
- 30-Aug-2002
备注
For those who have written a PEP before, there is a template (which is included as a file in the PEPs repository).
摘要
This PEP provides a boilerplate or sample template for creating your own reStructuredText PEPs. In conjunction with the content guidelines in PEP 1, this should make it easy for you to conform your own PEPs to the format outlined below.
注意:如果你通过网络阅读本 PEP,你应该首先抓取本 PEP 的文本(reStructuredText)源,以便完成以下步骤。 不要使用 html 文件作为你的模板!
The source for this (or any) PEP can be found in the PEPs repository, as well as via a link at the bottom of each PEP.
理论依据
如果你打算提交 PEP,你必须使用这个模板,并结合下面的格式指南,以确保你提交的 PEP 不会因为形式而被自动拒绝。
ReStructuredText为PEP作者提供了有用的功能和表现力,同时保持了源文本的易读性。经过处理的 HTML 形式使读者可以使用这些功能:实时超链接、风格化文本、表格、图像和自动目录等优点。
如何使用此模板
To use this template you must first decide whether your PEP is going to be an Informational or Standards Track PEP. Most PEPs are Standards Track because they propose a new feature for the Python language or standard library. When in doubt, read PEP 1 for details, or open a tracker issue on the PEPs repo to ask for assistance.
一旦你决定你的PEP是哪种类型,就按照下面的指示去做。
- 复制这个文件(是
.rst
文件,不 是 HTML!)并进行以下编辑。如果你还没有 PEP 号码分配,将新文件命名为pep-9999.rst
,如果你有,则命名为pep-NNN.rst
。欢迎有推送权限的人申请下一个可用的号码(忽略特殊区块 3000 和 8000,以及少量的特殊分配–目前是 666、754 和 801)并直接推送。 - 用 “PEP: 9999” 或 “PEP: NNNN” 替换 “PEP: 12” 头,以匹配文件名。请注意,文件名应该用零填充(例如
pep-0012.rst
),但文件头不应该(PEP: 12
)。 - 将标题标题改为你的 PEP 的标题。
- 改变作者头像,包括你的名字,以及你的电子邮件地址,可以选择。请务必认真遵守格式:你的名字必须出现在第一位,而且不能包含在括号里。你的电子邮件地址可以出现在第二位(也可以省略),如果出现,必须出现在角括号内。混淆你的电子邮件地址也是可以的”
- 如果作者中没有人是 Python 的核心开发者,请包括一个赞助商的标题,其中包括赞助你的 PEP 的核心开发者的名字。
- Add the direct URL of the PEP’s canonical discussion thread (on e.g. Python-Dev, Discourse, etc) under the Discussions-To header. If the thread will be created after the PEP is submitted as an official draft, it is okay to just list the venue name initially, but remember to update the PEP with the URL as soon as the PEP is successfully merged to the PEPs repository and you create the corresponding discussion thread. See PEP 1 for more details.
- 将状态头改为 “Draft”。
- 对于标准追踪 PEPs,将类型标题改为 “Standards Track”。
- 对于信息性 PEPs,将类型标题改为 “Informational”。
- 对于标准追踪 PEPs,如果你的功能取决于对其他正在开发的 PEP 的接受程度,请在 Type 头之后添加 Requires 头。其值应该是你所依赖的 PEP 的 PEP 编号。如果你所依赖的特性是在最终的 PEP 中描述的,就不要添加这个标头。
- 将 Created 标题改为今天的日期。一定要仔细遵守格式:必须是
dd-mmm-yyyy
格式,其中mmm
是 3 个英文字母的月份缩写,即 Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec 中的一个。 - For Standards Track PEPs, after the Created header, add a
Python-Version header and set the value to the next planned version
of Python, i.e. the one your new feature will hopefully make its
first appearance in. Do not use an alpha or beta release
designation here. Thus, if the last version of Python was 2.2 alpha
1 and you’re hoping to get your new feature into Python 2.2, set the
header to:
Python-Version: 2.2
- Leave Post-History alone for now; you’ll add dates and corresponding links
to this header each time you post your PEP to the designated discussion forum
(and update the Discussions-To header with said link, as above).
For each thread, use the date (in the
dd-mmm-yyy
format) as the linked text, and insert the URLs inline as anonymous reST hyperlinks, with commas in between each posting.If you posted threads for your PEP on August 14, 2001 and September 3, 2001, the Post-History header would look like, e.g.:
Post-History: `14-Aug-2001 <https://www.example.com/thread_1>`__, `03-Sept-2001 <https://www.example.com/thread_2>`__
You should add the new dates/links here as soon as you post a new discussion thread.
- 如果你的 PEP 淘汰了一个早期的 PEP,请添加一个 Replaces 头。这个头的值是你的新 PEP 所替代的 PEP的编号。 只有当较早的 PEP 处于 “final” 形式时,即要么接受,要么最终确定,要么拒绝,才会添加这个标头。如果你提交的是一个竞争性的想法,那么你就不是在替换一个旧的开放性 PEP。
- 现在为你的 PEP 写出你的摘要、理由和其他内容,用你自己的文字取代所有这些胡言乱语的内容。请确保遵守下面的格式指南,特别是禁止使用制表符和缩进的要求。参见下面的 “建议的章节”,以获得需要包括的章节模板。
- Update your Footnotes section, listing any footnotes and non-inline link targets referenced by the text.
- Run
./build.py
to ensure the PEP is rendered without errors, and check that the output inbuild/pep-9999.html
looks as you intend. - Create a pull request against the PEPs repository.
For reference, here are all of the possible header fields (everything
in brackets should either be replaced or have the field removed if
it has a leading *
marking it as optional and it does not apply to
your PEP):
PEP: [NNN]
Title: [...]
Author: [Full Name <email at example.com>]
Sponsor: *[Full Name <email at example.com>]
PEP-Delegate:
Discussions-To: [URL]
Status: Draft
Type: [Standards Track | Informational | Process]
Content-Type: text/x-rst
Requires: *[NNN]
Created: [DD-MMM-YYYY]
Python-Version: *[M.N]
Post-History: [`DD-MMM-YYYY <URL>`__]
Replaces: *[NNN]
Superseded-By: *[NNN]
Resolution:
ReStructuredText PEP 格式化要求
下面是一个针对 PEP 的 reStructuredText 语法的总结。为了简单明了,我们省略了很多细节。更多细节请参见下面的 Resources 。在整个例子中使用了 Literal blocks (其中没有进行标记处理),以说明纯文本标记
通用
Lines should usually not extend past column 79, excepting URLs and similar circumstances. Tab characters must never appear in the document at all.
节标题
PEP 的标题必须在第 0 栏开始,每个词的首字母必须像书名一样大写。首字母缩写应使用全大写。章节标题必须用下划线装饰,这是一个重复的标点符号,从第 0 栏开始,必须至少延伸到标题文本的右边缘(最少 4 个字符)。一级标题下划线为 “=”(等号),二级标题用 “-”(连字符),三级标题用 “’”(单引号或撇号)。 例如
First-Level Title
=================
Second-Level Title
------------------
Third-Level Title
'''''''''''''''''
如果你的 PEP 中有超过三层的章节,你可以为第一层和第二层插入下划线/下划线装饰的标题,如下
============================
First-Level Title (optional)
============================
-----------------------------
Second-Level Title (optional)
-----------------------------
Third-Level Title
=================
Fourth-Level Title
------------------
Fifth-Level Title
'''''''''''''''''
你的 PEP 中不应该有超过五级的章节。如果你有,你应该考虑重写它。
你必须在一节正文的最后一行和下一节标题之间使用两个空行。如果一个小节的标题紧随一个章节的标题之后,中间只需一个空行即可。
每一节的主体通常不缩进,尽管有些结构体确实使用缩进,如下所述。空行是用来分隔结构体的。
段落
段落是左对齐的文本块,由空行分隔。段落不缩进,除非它们是缩进结构的一部分(如引用块或列表项)。
行内标记
段落和其他文本块中的部分文本可以被定型。 例如
Text may be marked as *emphasized* (single asterisk markup,
typically shown in italics) or **strongly emphasized** (double
asterisks, typically boldface). ``Inline literals`` (using double
backquotes) are typically rendered in a monospaced typeface. No
further markup recognition is done within the double backquotes,
so they're safe for any kind of code snippets.
块引用
段落和其他文本块中的部分文本可以被定型。 例如
This is a paragraph.
This is a block quote.
A block quote may contain many paragraphs.
方块引号用于引用其他来源的扩展段落。区块引号可以嵌套在其他主体元素中。每个缩进级别使用 4 个空格。
Literal Blocks
Literal blocks are used for code samples and other preformatted text.
To indicate a literal block, preface the indented text block with
“::
” (two colons), or use the .. code-block::
directive.
Indent the text block by 4 spaces; the literal block continues until the end
of the indentation. For example:
This is a typical paragraph. A literal block follows.
::
for a in [5, 4, 3, 2, 1]: # this is program code, shown as-is
print(a)
print("it's...")
“::
” is also recognized at the end of any paragraph; if not immediately
preceded by whitespace, one colon will remain visible in the final output:
This is an example::
Literal block
By default, literal blocks will be syntax-highlighted as Python code.
For specific blocks that contain code or data in other languages/formats,
use the .. code-block:: language
directive, substituting the “short name”
of the appropriate Pygments lexer
(or text
to disable highlighting) for language
. For example:
.. code-block:: rst
An example of the ``rst`` lexer (i.e. *reStructuredText*).
For PEPs that predominantly contain literal blocks of a specific language,
use the .. highlight:: language
directive with the appropriate language
at the top of the PEP body (below the headers and above the Abstract).
All literal blocks will then be treated as that language,
unless specified otherwise in the specific .. code-block
. For example:
.. highlight:: c
Abstract
========
Here's some C code::
printf("Hello, World!\n");
Lists
Bullet list items begin with one of “-”, “*”, or “+” (hyphen, asterisk, or plus sign), followed by whitespace and the list item body. List item bodies must be left-aligned and indented relative to the bullet; the text immediately after the bullet determines the indentation. For example:
This paragraph is followed by a list.
* This is the first bullet list item. The blank line above the
first list item is required; blank lines between list items
(such as below this paragraph) are optional.
* This is the first paragraph in the second item in the list.
This is the second paragraph in the second item in the list.
The blank line above this paragraph is required. The left edge
of this paragraph lines up with the paragraph above, both
indented relative to the bullet.
- This is a sublist. The bullet lines up with the left edge of
the text blocks above. A sublist is a new list so requires a
blank line above and below.
* This is the third item of the main list.
This paragraph is not part of the list.
Enumerated (numbered) list items are similar, but use an enumerator instead of a bullet. Enumerators are numbers (1, 2, 3, …), letters (A, B, C, …; uppercase or lowercase), or Roman numerals (i, ii, iii, iv, …; uppercase or lowercase), formatted with a period suffix (“1.”, “2.”), parentheses (“(1)”, “(2)”), or a right-parenthesis suffix (“1)”, “2)”). For example:
1. As with bullet list items, the left edge of paragraphs must
align.
2. Each list item may contain multiple paragraphs, sublists, etc.
This is the second paragraph of the second list item.
a) Enumerated lists may be nested.
b) Blank lines may be omitted between list items.
Definition lists are written like this:
what
Definition lists associate a term with a definition.
how
The term is a one-line phrase, and the definition is one
or more paragraphs or body elements, indented relative to
the term.
Tables
Simple tables are easy and compact:
===== ===== =======
A B A and B
===== ===== =======
False False False
True False False
False True False
True True True
===== ===== =======
There must be at least two columns in a table (to differentiate from section titles). Column spans use underlines of hyphens (“Inputs” spans the first two columns):
===== ===== ======
Inputs Output
------------ ------
A B A or B
===== ===== ======
False False False
True False True
False True True
True True True
===== ===== ======
Text in a first-column cell starts a new row. No text in the first column indicates a continuation line; the rest of the cells may consist of multiple lines. For example:
===== =========================
col 1 col 2
===== =========================
1 Second column of row 1.
2 Second column of row 2.
Second line of paragraph.
3 - Second column of row 3.
- Second item in bullet
list (row 3, column 2).
===== =========================
Hyperlinks
When referencing an external web page in the body of a PEP, you should include the title of the page or a suitable description in the text, with either an inline hyperlink or a separate explicit target with the URL. Do not include bare URLs in the body text of the PEP, and use HTTPS links wherever available.
Hyperlink references use backquotes and a trailing underscore to mark
up the reference text; backquotes are optional if the reference text
is a single word. For example, to reference a hyperlink target named
Python website
, you would write:
In this paragraph, we refer to the `Python website`_.
If you intend to only reference a link once, and want to define it inline
with the text, insert the link into angle brackets (<>
) after the text
you want to link, but before the closing backtick, with a space between the
text and the opening backtick. You should also use a double-underscore after
the closing backtick instead of a single one, which makes it an anonymous
reference to avoid conflicting with other target names. For example:
Visit the `website <https://www.python.org/>`__ for more.
If you want to use one link multiple places with different linked text, or want to ensure you don’t have to update your link target names when changing the linked text, include the target name within angle brackets following the text to link, with an underscore after the target name but before the closing angle bracket (or the link will not work). For example:
For further examples, see the `documentation <pydocs_>`_.
An explicit target provides the URL. Put targets in the Footnotes section at the end of the PEP, or immediately after the paragraph with the reference. Hyperlink targets begin with two periods and a space (the “explicit markup start”), followed by a leading underscore, the reference text, a colon, and the URL.
.. _Python web site: https://www.python.org/
.. _pydocs: https://docs.python.org/
The reference text and the target text must match (although the match is case-insensitive and ignores differences in whitespace). Note that the underscore trails the reference text but precedes the target text. If you think of the underscore as a right-pointing arrow, it points away from the reference and toward the target.
Internal and PEP/RFC Links
The same mechanism as hyperlinks can be used for internal references. Every unique section title implicitly defines an internal hyperlink target. We can make a link to the Abstract section like this:
Here is a hyperlink reference to the `Abstract`_ section. The
backquotes are optional since the reference text is a single word;
we can also just write: Abstract_.
To refer to PEPs or RFCs, always use the :pep:
and :rfc:
roles,
never hardcoded URLs.
For example:
See :pep:`1` for more information on how to write a PEP,
and :pep:`the Hyperlink section of PEP 12 <12#hyperlinks>` for how to link.
This renders as:
See PEP 1 for more information on how to write a PEP, and the Hyperlink section of PEP 12 for how to link.
PEP numbers in the text are never padded, and there is a space (not a dash) between “PEP” or “RFC” and the number; the above roles will take care of that for you.
Footnotes
Footnote references consist of a left square bracket, a label, a right square bracket, and a trailing underscore. Instead of a number, use a label of the form “#word”, where “word” is a mnemonic consisting of alphanumerics plus internal hyphens, underscores, and periods (no whitespace or other characters are allowed). For example:
Refer to The TeXbook [#TeXbook]_ for more information.
which renders as
Refer to The TeXbook [1] for more information.
Whitespace must precede the footnote reference. Leave a space between the footnote reference and the preceding word.
Use footnotes for additional notes, explanations and caveats, as well as for references to books and other sources not readily available online. Native reST hyperlink targets or inline hyperlinks in the text should be used in preference to footnotes for including URLs to online resources.
Footnotes begin with “.. “ (the explicit markup start), followed by the footnote marker (no underscores), followed by the footnote body. For example:
.. [#TeXbook] Donald Knuth's *The TeXbook*, pages 195 and 196.
which renders as
Footnotes and footnote references will be numbered automatically, and the numbers will always match.
Images
If your PEP contains a diagram or other graphic, you may include it in the
processed output using the image
directive:
.. image:: diagram.png
Any browser-friendly graphics format is possible; PNG should be preferred for graphics, JPEG for photos and GIF for animations. Currently, SVG must be avoided due to compatibility issues with the PEP build system.
For accessibility and readers of the source text, you should include
a description of the image and any key information contained within
using the :alt:
option to the image
directive:
.. image:: dataflow.png
:alt: Data flows from the input module, through the "black box"
module, and finally into (and through) the output module.
Escaping Mechanism
reStructuredText uses backslashes (”\
”) to override the special
meaning given to markup characters and get the literal characters
themselves. To get a literal backslash, use an escaped backslash
(”\\
”). There are two contexts in which backslashes have no
special meaning: literal blocks and inline literals (see Inline
Markup above). In these contexts, no markup recognition is done,
and a single backslash represents a literal backslash, without having
to double up.
If you find that you need to use a backslash in your text, consider using inline literals or a literal block instead.
Canonical Documentation and Intersphinx
As PEP 1 describes,
PEPs are considered historical documents once marked Final,
and their canonical documentation/specification should be moved elsewhere.
To indicate this, use the canonical-docs
directive
or an appropriate subclass
(currently canonical-pypa-spec
for packaging standards).
Furthermore, you can use Intersphinx references to other Sphinx sites, currently the Python documentation and packaging.python.org, to easily cross-reference pages, sections and Python/C objects. This works with both the “canonical” directives and anywhere in your PEP.
Add the directive between the headers and the first section of the PEP (typically the Abstract) and pass as an argument an Intersphinx reference of the canonical doc/spec (or if the target is not on a Sphinx site, a reST hyperlink).
For example,
to create a banner pointing to the sqlite3
docs,
you would write the following:
.. canonical-doc:: :mod:`python:sqlite3`
which would generate the banner:
Or for a PyPA spec, such as the Core metadata specifications, you would use:
.. canonical-pypa-spec:: :ref:`packaging:core-metadata`
which renders as:
The argument accepts arbitrary reST, so you can include multiple linked docs/specs and name them whatever you like, and you can also include directive content that will be inserted into the text. The following advanced example:
.. canonical-doc:: the :ref:`python:sqlite3-connection-objects` and :exc:`python:~sqlite3.DataError` docs
Also, see the :ref:`Data Persistence docs <persistence>` for other examples.
would render as:
Habits to Avoid
Many programmers who are familiar with TeX often write quotation marks like this:
`single-quoted' or ``double-quoted''
Backquotes are significant in reStructuredText, so this practice should be avoided. For ordinary text, use ordinary ‘single-quotes’ or “double-quotes”. For inline literal text (see Inline Markup above), use double-backquotes:
``literal text: in here, anything goes!``
Suggested Sections
Various sections are found to be common across PEPs and are outlined in PEP 1. Those sections are provided here for convenience.
PEP: <REQUIRED: pep number>
Title: <REQUIRED: pep title>
Author: <REQUIRED: list of authors' real names and optionally, email addrs>
Sponsor: <real name of sponsor>
PEP-Delegate: <PEP delegate's real name>
Discussions-To: <REQUIRED: URL of current canonical discussion thread>
Status: <REQUIRED: Draft | Active | Accepted | Provisional | Deferred | Rejected | Withdrawn | Final | Superseded>
Type: <REQUIRED: Standards Track | Informational | Process>
Content-Type: text/x-rst
Requires: <pep numbers>
Created: <date created on, in dd-mmm-yyyy format>
Python-Version: <version number>
Post-History: <REQUIRED: dates, in dd-mmm-yyyy format, and corresponding links to PEP discussion threads>
Replaces: <pep number>
Superseded-By: <pep number>
Resolution: <url>
Abstract
========
[A short (~200 word) description of the technical issue being addressed.]
Motivation
==========
[Clearly explain why the existing language specification is inadequate to address the problem that the PEP solves.]
Rationale
=========
[Describe why particular design decisions were made.]
Specification
=============
[Describe the syntax and semantics of any new language feature.]
Backwards Compatibility
=======================
[Describe potential impact and severity on pre-existing code.]
Security Implications
=====================
[How could a malicious user take advantage of this new feature?]
How to Teach This
=================
[How to teach users, new and experienced, how to apply the PEP to their work.]
Reference Implementation
========================
[Link to any existing implementation and details about its state, e.g. proof-of-concept.]
Rejected Ideas
==============
[Why certain ideas that were brought while discussing this PEP were not ultimately pursued.]
Open Issues
===========
[Any points that are still being decided/discussed.]
Footnotes
=========
[A collection of footnotes cited in the PEP, and a place to list non-inline hyperlink targets.]
Copyright
=========
This document is placed in the public domain or under the
CC0-1.0-Universal license, whichever is more permissive.
Resources
Many other constructs and variations are possible, both those supported by basic Docutils and the extensions added by Sphinx.
A number of resources are available to learn more about them:
- Sphinx ReStructuredText Primer, a gentle but fairly detailed introduction.
- reStructuredText Markup Specification, the authoritative, comprehensive documentation of the basic reST syntax, directives, roles and more.
- Sphinx Roles and Sphinx Directives, the extended constructs added by the Sphinx documentation system used to render the PEPs to HTML.
If you have questions or require assistance with writing a PEP that the above
resources don’t address, ping @python/pep-editors
on GitHub, open an
issue on the PEPs repository
or reach out to a PEP editor directly.
Copyright
This document is placed in the public domain or under the CC0-1.0-Universal license, whichever is more permissive.
Source: https://github.com/python/peps/blob/main/pep-0012.rst
Last modified: 2022-08-03 03:48:56 GMT
Comments
A comment is an indented block of arbitrary text immediately following an explicit markup start: two periods and whitespace. Leave the “..” on a line by itself to ensure that the comment is not misinterpreted as another explicit markup construct. Comments are not visible in the processed document. For example: