Debian Codegraph @

docs/peps/pep-0256.rst

raw
1 PEP: 256
2 Title: Docstring Processing System Framework
3 Version: $Revision: 9906 $
4 Last-Modified: $Date: 2024-08-15 10:43:38 +0200 (Do, 15. Aug 2024) $
5 Author: David Goodger <[email protected]>
6 Discussions-To: <[email protected]>
7 Status: Rejected
8 Type: Standards Track
9 Content-Type: text/x-rst
10 Created: 01-Jun-2001
11 Post-History: 13-Jun-2001
12
13
14 Rejection Notice
15 ================
16
17 This proposal seems to have run out of steam.
18
19
20 Abstract
21 ========
22
23 Python lends itself to inline documentation. With its built-in
24 docstring syntax, a limited form of `Literate Programming`_ is easy to
25 do in Python. However, there are no satisfactory standard tools for
26 extracting and processing Python docstrings. The lack of a standard
27 toolset is a significant gap in Python's infrastructure; this PEP aims
28 to fill the gap.
29
30 The issues surrounding docstring processing have been contentious and
31 difficult to resolve. This PEP proposes a generic Docstring
32 Processing System (DPS) framework, which separates out the components
33 (program and conceptual), enabling the resolution of individual issues
34 either through consensus (one solution) or through divergence (many).
35 It promotes standard interfaces which will allow a variety of plug-in
36 components (input context readers, markup parsers, and output format
37 writers) to be used.
38
39 The concepts of a DPS framework are presented independently of
40 implementation details.
41
42
43 Road Map to the Docstring PEPs
44 ==============================
45
46 There are many aspects to docstring processing. The "Docstring PEPs"
47 have broken up the issues in order to deal with each of them in
48 isolation, or as close as possible. The individual aspects and
49 associated PEPs are as follows:
50
51 * Docstring syntax. PEP 287, "reStructuredText Docstring Format"
52 [#PEP-287]_, proposes a syntax for Python docstrings, PEPs, and
53 other uses.
54
55 * Docstring semantics consist of at least two aspects:
56
57 - Conventions: the high-level structure of docstrings. Dealt with
58 in PEP 257, "Docstring Conventions" [#PEP-257]_.
59
60 - Methodology: rules for the informational content of docstrings.
61 Not addressed.
62
63 * Processing mechanisms. This PEP (PEP 256) outlines the high-level
64 issues and specification of an abstract docstring processing system
65 (DPS). PEP 258, "Docutils Design Specification" [#PEP-258]_, is an
66 overview of the design and implementation of one DPS under
67 development.
68
69 * Output styles: developers want the documentation generated from
70 their source code to look good, and there are many different ideas
71 about what that means. PEP 258 touches on "Stylist Transforms".
72 This aspect of docstring processing has yet to be fully explored.
73
74 By separating out the issues, we can form consensus more easily
75 (smaller fights ;-), and accept divergence more readily.
76
77
78 Rationale
79 =========
80
81 There are standard inline documentation systems for some other
82 languages. For example, Perl has POD_ ("Plain Old Documentation") and
83 Java has Javadoc_, but neither of these mesh with the Pythonic way.
84 POD syntax is very explicit, but takes after Perl in terms of
85 readability. Javadoc is HTML-centric; except for "``@field``" tags,
86 raw HTML is used for markup. There are also general tools such as
87 Autoduck_ and Web_ (Tangle & Weave), useful for multiple languages.
88
89 There have been many attempts to write auto-documentation systems
90 for Python (not an exhaustive list):
91
92 - Marc-Andre Lemburg's doc.py_
93
94 - Daniel Larsson's pythondoc_ & gendoc_
95
96 - Doug Hellmann's HappyDoc_
97
98 - Laurence Tratt's Crystal (no longer available on the web)
99
100 - Ka-Ping Yee's pydoc_ (pydoc.py is now part of the Python standard
101 library; see below)
102
103 - Tony Ibbs' docutils_ (Tony has donated this name to the `Docutils
104 project`_)
105
106 - Edward Loper's STminus_ formalization and related efforts
107
108 These systems, each with different goals, have had varying degrees of
109 success. A problem with many of the above systems was over-ambition
110 combined with inflexibility. They provided a self-contained set of
111 components: a docstring extraction system, a markup parser, an
112 internal processing system and one or more output format writers with
113 a fixed style. Inevitably, one or more aspects of each system had
114 serious shortcomings, and they were not easily extended or modified,
115 preventing them from being adopted as standard tools.
116
117 It has become clear (to this author, at least) that the "all or
118 nothing" approach cannot succeed, since no monolithic self-contained
119 system could possibly be agreed upon by all interested parties. A
120 modular component approach designed for extension, where components
121 may be multiply implemented, may be the only chance for success.
122 Standard inter-component APIs will make the DPS components
123 comprehensible without requiring detailed knowledge of the whole,
124 lowering the barrier for contributions, and ultimately resulting in a
125 rich and varied system.
126
127 Each of the components of a docstring processing system should be
128 developed independently. A "best of breed" system should be chosen,
129 either merged from existing systems, and/or developed anew. This
130 system should be included in Python's standard library.
131
132
133 PyDoc & Other Existing Systems
134 ------------------------------
135
136 PyDoc became part of the Python standard library as of release 2.1.
137 It extracts and displays docstrings from within the Python interactive
138 interpreter, from the shell command line, and from a GUI window into a
139 web browser (HTML). Although a very useful tool, PyDoc has several
140 deficiencies, including:
141
142 - In the case of the GUI/HTML, except for some heuristic hyperlinking
143 of identifier names, no formatting of the docstrings is done. They
144 are presented within ``<p><small><tt>`` tags to avoid unwanted line
145 wrapping. Unfortunately, the result is not attractive.
146
147 - PyDoc extracts docstrings and structural information (class
148 identifiers, method signatures, etc.) from imported module objects.
149 There are security issues involved with importing untrusted code.
150 Also, information from the source is lost when importing, such as
151 comments, "additional docstrings" (string literals in non-docstring
152 contexts; see PEP 258 [#PEP-258]_), and the order of definitions.
153
154 The functionality proposed in this PEP could be added to or used by
155 PyDoc when serving HTML pages. The proposed docstring processing
156 system's functionality is much more than PyDoc needs in its current
157 form. Either an independent tool will be developed (which PyDoc may
158 or may not use), or PyDoc could be expanded to encompass this
159 functionality and *become* the docstring processing system (or one
160 such system). That decision is beyond the scope of this PEP.
161
162 Similarly for other existing docstring processing systems, their
163 authors may or may not choose compatibility with this framework.
164 However, if this framework is accepted and adopted as the Python
165 standard, compatibility will become an important consideration in
166 these systems' future.
167
168
169 Specification
170 =============
171
172 The docstring processing system framework is broken up as follows:
173
174 1. Docstring conventions. Documents issues such as:
175
176 - What should be documented where.
177
178 - First line is a one-line synopsis.
179
180 PEP 257 [#PEP-257]_ documents some of these issues.
181
182 2. Docstring processing system design specification. Documents
183 issues such as:
184
185 - High-level spec: what a DPS does.
186
187 - Command-line interface for executable script.
188
189 - System Python API.
190
191 - Docstring extraction rules.
192
193 - Readers, which encapsulate the input context.
194
195 - Parsers.
196
197 - Document tree: the intermediate internal data structure. The
198 output of the Parser and Reader, and the input to the Writer all
199 share the same data structure.
200
201 - Transforms, which modify the document tree.
202
203 - Writers for output formats.
204
205 - Distributors, which handle output management (one file, many
206 files, or objects in memory).
207
208 These issues are applicable to any docstring processing system
209 implementation. PEP 258 [#PEP-258]_ documents these issues.
210
211 3. Docstring processing system implementation.
212
213 4. Input markup specifications: docstring syntax. PEP 287 [#PEP-287]_
214 proposes a standard syntax.
215
216 5. Input parser implementations.
217
218 6. Input context readers ("modes": Python source code, PEP, standalone
219 text file, email, etc.) and implementations.
220
221 7. Stylists: certain input context readers may have associated
222 stylists which allow for a variety of output document styles.
223
224 8. Output formats (HTML, XML, TeX, DocBook, info, etc.) and writer
225 implementations.
226
227 Components 1, 2/3/5, and 4 are the subject of individual companion
228 PEPs. If there is another implementation of the framework or
229 syntax/parser, additional PEPs may be required. Multiple
230 implementations of each of components 6 and 7 will be required; the
231 PEP mechanism may be overkill for these components.
232
233
234 Project Web Site
235 ================
236
237 A SourceForge project has been set up for this work at
238 https://docutils.sourceforge.io/.
239
240
241 References and Footnotes
242 ========================
243
244 .. [#PEP-287] PEP 287, reStructuredText Docstring Format, Goodger
245 (http://www.python.org/peps/pep-0287.html)
246
247 .. [#PEP-257] PEP 257, Docstring Conventions, Goodger, Van Rossum
248 (http://www.python.org/peps/pep-0257.html)
249
250 .. [#PEP-258] PEP 258, Docutils Design Specification, Goodger
251 (http://www.python.org/peps/pep-0258.html)
252
253 .. _Literate Programming: http://www.literateprogramming.com/
254
255 .. _POD: http://perldoc.perl.org/perlpod.html
256
257 .. _Javadoc: http://java.sun.com/j2se/javadoc/
258
259 .. _Autoduck:
260 http://www.helpmaster.com/hlp-developmentaids-autoduck.htm
261
262 .. _Web: http://www-cs-faculty.stanford.edu/~knuth/cweb.html
263
264 .. _doc.py:
265 http://www.egenix.com/files/python/SoftwareDescriptions.html#doc.py
266
267 .. _pythondoc:
268 .. _gendoc: http://starship.python.net/crew/danilo/pythondoc/
269
270 .. _HappyDoc: http://happydoc.sourceforge.net/
271
272 .. _pydoc: http://www.python.org/doc/current/lib/module-pydoc.html
273
274 .. _docutils: http://www.tibsnjoan.co.uk/docutils.html
275
276 .. _Docutils project: https://docutils.sourceforge.io/
277
278 .. _STMinus: http://www.cis.upenn.edu/~edloper/pydoc/
279
280 .. _Python Doc-SIG: http://www.python.org/sigs/doc-sig/
281
282
283 Copyright
284 =========
285
286 This document has been placed in the public domain.
287
288
289 Acknowledgements
290 ================
291
292 This document borrows ideas from the archives of the `Python
293 Doc-SIG`_. Thanks to all members past & present.
294
295
296 .. Emacs settings
297
298 Local Variables:
299 mode: indented-text
300 mode: rst
301 indent-tabs-mode: nil
302 sentence-end-double-space: t
303 fill-column: 70
304 End: