Python Enhancement Proposals

PEP 12 – Sample reStructuredText PEP Template

PEP
12
Title
reStructuredText PEP 模板样本
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

Contents

注解

对于那些以前写过 PEP 的人来说,有一个模板

摘要

本 PEP 为创建你自己的 reStructuredText PEP 提供了一个模板或示例模板。结合 PEP1 1 中的内容指南,这应该能让你很容易地使自己的 PEP 符合下面列出的格式。

注意:如果你通过网络阅读本 PEP,你应该首先抓取本 PEP 的文本(reStructuredText)源,以便完成以下步骤。 不要使用 html 文件作为你的模板!

这个(或任何)PEP 的来源可以在 PEPs 库中找到,可以在网上查看:https://github.com/python/peps/

理论依据

如果你打算提交 PEP,你必须使用这个模板,并结合下面的格式指南,以确保你提交的 PEP 不会因为形式而被自动拒绝。

ReStructuredText为PEP作者提供了有用的功能和表现力,同时保持了源文本的易读性。经过处理的 HTML 形式使读者可以使用这些功能:实时超链接、风格化文本、表格、图像和自动目录等优点。

如何使用此模板

要使用这个模板,你必须首先决定你的 PEP 是一个信息性的还是标准追踪性的 PEP。大多数 PEP 是标准追踪的,因为它们为 Python 语言或标准库提出了一个新特性。如果有疑问,请阅读 PEP 1 以了解细节,或者在 PEPs repo 上开一个跟踪问题以寻求帮助。

一旦你决定你的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 的核心开发者的名字。
  • 对于许多 PEPs,讨论将在 python-ideas@python.org 和/或 python-dev@python.org。如果有另一个邮件列表或公共论坛更适合讨论你的新特性,请在作者标题之后添加一个讨论-对象的标题。大多数信息性的 PEP 不需要讨论到标题。
  • 将状态头改为 “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 中的一个。
  • 对于标准追踪 PEPs,在 Created 标题之后,添加一个 Python-Version 标题,并将其值设置为 Python 的下一个计划版本,即你的新特性有希望在其中首次出现的版本。不要在这里使用 alpha 或 beta 版本的名称。因此,如果 Python 的最后一个版本是 2.2 alpha 1,而你希望把你的新特性放到 Python 2.2中,请把标题设置为
    Python-Version: 2.2
    
  • 暂时不要管 Post-History;你将在每次将你的 PEP 发布到指定的讨论区(见上面的 Discussions-To header)时在这个标题上添加日期。如果你在 2001 年 8 月 14 日和 2001 年 9 月 3 日将你的 PEP 发布到列表中,那么 Post-History 的标题将是
    Post-History: 14-Aug-2001, 03-Sept-2001
    

    你必须手动添加新的日期并提交它们(如果你没有推送权限,就用拉取请求)。

  • 如果你的 PEP 淘汰了一个早期的 PEP,请添加一个 Replaces 头。这个头的值是你的新 PEP 所替代的 PEP的编号。 只有当较早的 PEP 处于 “final” 形式时,即要么接受,要么最终确定,要么拒绝,才会添加这个标头。如果你提交的是一个竞争性的想法,那么你就不是在替换一个旧的开放性 PEP。
  • 现在为你的 PEP 写出你的摘要、理由和其他内容,用你自己的文字取代所有这些胡言乱语的内容。请确保遵守下面的格式指南,特别是禁止使用制表符和缩进的要求。参见下面的 “建议的章节”,以获得需要包括的章节模板。
  • 更新你的参考文献和版权部分。通常你会把你的 PEP 放入公共领域,在这种情况下,只需留下版权部分。另外,你也可以使用 公开出版许可证 5,但还是强烈建议使用公有领域。
  • 让这个文件结尾的 Emacs 句子单独存在,包括 formfeed 字符(”^L”,或 \f)。
  • 针对 https://github.com/python/peps 仓库创建一个拉取请求。

作为参考,以下是所有可能的头文件字段(括号内的所有字段都应该被替换掉,或者删除该字段,如果它有一个领先的 * 标记为可选字段,并且不适用于你的PEP)

PEP: [NNN]
Title: [...]
Author: [Full Name <email at example.com>]
Sponsor: *[Full Name <email at example.com>]
PEP-Delegate:
Discussions-To: *[...]
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]
Replaces: *[NNN]
Superseded-By: *[NNN]
Resolution:

ReStructuredText PEP 格式化要求

下面是一个针对 PEP 的 reStructuredText 语法的总结。为了简单明了,我们省略了很多细节。更多细节请参见下面的 Resources 。在整个例子中使用了 Literal blocks (其中没有进行标记处理),以说明纯文本标记

通用

你必须遵守 Emacs 的惯例,在每句话的末尾加两个空格。你应该把你的段落填到第 70 栏,但在任何情况下,你的行都不能超过第 79 栏。如果你的代码样本超过了第 79 栏,你应该重写。

Tab 字符绝对不能出现在文件中。PEP 应该包括本 PEP 底部举例的标准 Emacs 句子。

节标题

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 or preformatted ASCII art. To indicate a literal block, preface the indented text block with “::” (two colons). The literal block continues until the end of the indentation. Indent the text block by 4 spaces. 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..."
    # a literal block continues until the indentation ends

The paragraph containing only “::” will be completely removed from the output; no empty paragraph will remain. “::” is also recognized at the end of any paragraph. If immediately preceded by whitespace, both colons will be removed from the output. When text immediately precedes the “::”, one colon will be removed from the output, leaving only one colon visible (i.e., “::” will be replaced by “:”). For example, one colon will remain visible here:

Paragraph::

    Literal block

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).
=====  =========================

Footnotes

Footnote references consist of a left square bracket, a number, a right square bracket, and a trailing underscore:

This sentence ends with a footnote reference [1]_.

Whitespace must precede the footnote reference. Leave a space between the footnote reference and the preceding word.

When referring to another PEP, include the PEP number in the body text, such as “PEP 1”. The title may optionally appear. Add a footnote reference following the title. For example:

Refer to PEP 1 [2]_ for more information.

Add a footnote that includes the PEP’s title and author. It may optionally include the explicit URL on a separate line, but only in the References section. Footnotes begin with “.. ” (the explicit markup start), followed by the footnote marker (no underscores), followed by the footnote body. For example:

References
==========

.. [2] PEP 1, "PEP Purpose and Guidelines", Warsaw, Hylton
   (http://www.python.org/dev/peps/pep-0001)

If you decide to provide an explicit URL for a PEP, please use this as the URL template:

http://www.python.org/dev/peps/pep-xxxx

PEP numbers in URLs must be padded with zeros from the left, so as to be exactly 4 characters wide; however, PEP numbers in the text are never padded.

During the course of developing your PEP, you may have to add, remove, and rearrange footnote references, possibly resulting in mismatched references, obsolete footnotes, and confusion. Auto-numbered footnotes allow more freedom. 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 PEP 1 [#PEP-1]_ for more information.

References
==========

.. [#PEP-1] PEP 1, "PEP Purpose and Guidelines", Warsaw, Hylton

   http://www.python.org/dev/peps/pep-0001

Footnotes and footnote references will be numbered automatically, and the numbers will always match. Once a PEP is finalized, auto-numbered labels should be replaced by numbers for simplicity.

Images

If your PEP contains a diagram, you may include it in the processed output using the “image” directive:

.. image:: diagram.png

Any browser-friendly graphics format is possible: .png, .jpeg, .gif, .tiff, etc.

Since this image will not be visible to readers of the PEP in source text form, you should consider including a description or ASCII art alternative, using a comment (below).

Comments

A comment block 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 the benefit of those reading your PEP in source form, please consider including a descriptions of or ASCII art alternatives to any images you include. For example:

.. image:: dataflow.png

..
   Data flows from the input module, through the "black box"
   module, and finally into (and through) the output module.

The Emacs stanza at the bottom of this document is inside a comment.

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.

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 1. Those sections are provided here for convenience.

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.]


References
==========

[A collection of URLs used as references through the PEP.]


Copyright
=========

This document is placed in the public domain or under the
CC0-1.0-Universal license, whichever is more permissive.



..
   Local Variables:
   mode: indented-text
   indent-tabs-mode: nil
   sentence-end-double-space: t
   fill-column: 70
   coding: utf-8
   End:

Resources

Many other constructs and variations are possible. For more details about the reStructuredText markup, in increasing order of thoroughness, please see:

The processing of reStructuredText PEPs is done using Docutils 2. If you have a question or require assistance with reStructuredText or Docutils, please post a message 3 to the Docutils-users mailing list 4. The Docutils project web site 2 has more information.

References

1 (1, 2)
PEP 1, PEP Purpose and Guidelines, Warsaw, Hylton (http://www.python.org/dev/peps/pep-0001)
2 (1, 2)
http://docutils.sourceforge.net/
3
mailto:docutils-users@lists.sourceforge.net?subject=PEPs
4
http://docutils.sf.net/docs/user/mailing-lists.html#docutils-users
5
http://www.opencontent.org/openpub/
6
http://docutils.sourceforge.net/docs/rst/quickstart.html
7
http://docutils.sourceforge.net/docs/rst/quickref.html
8
http://docutils.sourceforge.net/spec/rst/reStructuredText.html

Source: https://github.com/python/peps/blob/master/pep-0012.rst

Last modified: 2021-03-22 21:00:22 GMT