Skip to content

Commit 1050d2d

Browse files
committed
Issue #26462: Doc: reduce literal_block warnings, fix syntax highlighting.
Patch by Julien Palard.
1 parent 87ec85f commit 1050d2d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+329
-128
lines changed

Doc/distutils/examples.rst

+9-3
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,9 @@ Let's take an example with a simple script::
245245

246246
setup(name='foobar')
247247

248-
Running the ``check`` command will display some warnings::
248+
Running the ``check`` command will display some warnings:
249+
250+
.. code-block:: shell-session
249251
250252
$ python setup.py check
251253
running check
@@ -274,7 +276,9 @@ For example, if the :file:`setup.py` script is changed like this::
274276
url='http://example.com', long_description=desc)
275277

276278
Where the long description is broken, ``check`` will be able to detect it
277-
by using the :mod:`docutils` parser::
279+
by using the :mod:`docutils` parser:
280+
281+
.. code-block:: shell-session
278282
279283
$ python setup.py check --restructuredtext
280284
running check
@@ -286,7 +290,9 @@ Reading the metadata
286290

287291
The :func:`distutils.core.setup` function provides a command-line interface
288292
that allows you to query the metadata fields of a project through the
289-
``setup.py`` script of a given project::
293+
``setup.py`` script of a given project:
294+
295+
.. code-block:: shell-session
290296
291297
$ python setup.py --name
292298
distribute

Doc/distutils/packageindex.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ in the root of the package besides :file:`setup.py`.
233233

234234
To prevent registering broken reStructuredText content, you can use the
235235
:program:`rst2html` program that is provided by the :mod:`docutils` package and
236-
check the ``long_description`` from the command line::
236+
check the ``long_description`` from the command line:
237+
238+
.. code-block:: shell-session
237239
238240
$ python setup.py --long-description | rst2html.py > output.html
239241

Doc/distutils/sourcedist.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ described above does not apply in this case.
133133

134134
The manifest template has one command per line, where each command specifies a
135135
set of files to include or exclude from the source distribution. For an
136-
example, again we turn to the Distutils' own manifest template::
136+
example, again we turn to the Distutils' own manifest template:
137+
138+
.. code-block:: none
137139
138140
include *.txt
139141
recursive-include examples *.txt *.py

Doc/extending/building.rst

+6-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ Since distutils also supports creation of binary packages, users don't
5555
necessarily need a compiler and distutils to install the extension.
5656
5757
A distutils package contains a driver script, :file:`setup.py`. This is a plain
58-
Python file, which, in the most simple case, could look like this::
58+
Python file, which, in the most simple case, could look like this:
59+
60+
.. code-block:: python3
5961
6062
from distutils.core import setup, Extension
6163
@@ -96,7 +98,9 @@ file, :file:`demo.c`.
9698

9799
In many cases, building an extension is more complex, since additional
98100
preprocessor defines and libraries may be needed. This is demonstrated in the
99-
example below. ::
101+
example below.
102+
103+
.. code-block:: python3
100104
101105
from distutils.core import setup, Extension
102106
@@ -161,4 +165,3 @@ commands can be used to do so. ::
161165
python setup.py bdist_wininst
162166
python setup.py bdist_rpm
163167
python setup.py bdist_dumb
164-

Doc/extending/embedding.rst

+13-7
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ script, such as:
155155
c = c + b
156156
return c
157157
158-
then the result should be::
158+
then the result should be:
159+
160+
.. code-block:: shell-session
159161
160162
$ call multiply multiply 3 2
161163
Will compute 3 times 2
@@ -289,16 +291,20 @@ available). This script has several options, of which the following will
289291
be directly useful to you:
290292

291293
* ``pythonX.Y-config --cflags`` will give you the recommended flags when
292-
compiling::
294+
compiling:
295+
296+
.. code-block:: shell-session
293297
294-
$ /opt/bin/python3.4-config --cflags
295-
-I/opt/include/python3.4m -I/opt/include/python3.4m -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes
298+
$ /opt/bin/python3.4-config --cflags
299+
-I/opt/include/python3.4m -I/opt/include/python3.4m -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes
296300
297301
* ``pythonX.Y-config --ldflags`` will give you the recommended flags when
298-
linking::
302+
linking:
303+
304+
.. code-block:: shell-session
299305
300-
$ /opt/bin/python3.4-config --ldflags
301-
-L/opt/lib/python3.4/config-3.4m -lpthread -ldl -lutil -lm -lpython3.4m -Xlinker -export-dynamic
306+
$ /opt/bin/python3.4-config --ldflags
307+
-L/opt/lib/python3.4/config-3.4m -lpthread -ldl -lutil -lm -lpython3.4m -Xlinker -export-dynamic
302308
303309
.. note::
304310
To avoid confusion between several Python installations (and especially

Doc/extending/extending.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,9 @@ the format string is empty, it returns ``None``; if it contains exactly one
792792
format unit, it returns whatever object is described by that format unit. To
793793
force it to return a tuple of size 0 or one, parenthesize the format string.
794794

795-
Examples (to the left the call, to the right the resulting Python value)::
795+
Examples (to the left the call, to the right the resulting Python value):
796+
797+
.. code-block:: none
796798
797799
Py_BuildValue("") None
798800
Py_BuildValue("i", 123) 123
@@ -1348,4 +1350,3 @@ code distribution).
13481350
13491351
.. [#] These guarantees don't hold when you use the "old" style calling convention ---
13501352
this is still found in much existing code.
1351-

Doc/extending/newtypes.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ That's it! All that remains is to build it; put the above code in a file called
209209
setup(name="noddy", version="1.0",
210210
ext_modules=[Extension("noddy", ["noddy.c"])])
211211

212-
in a file called :file:`setup.py`; then typing ::
212+
in a file called :file:`setup.py`; then typing
213+
214+
.. code-block:: shell-session
213215
214216
$ python setup.py build
215217
@@ -1513,4 +1515,3 @@ might be something like the following::
15131515
.. [#] Even in the third version, we aren't guaranteed to avoid cycles. Instances of
15141516
string subclasses are allowed and string subclasses could allow cycles even if
15151517
normal strings don't.
1516-

Doc/faq/extending.rst

+12-4
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ this object to :data:`sys.stdout` and :data:`sys.stderr`. Call print_error, or
146146
just allow the standard traceback mechanism to work. Then, the output will go
147147
wherever your ``write()`` method sends it.
148148

149-
The easiest way to do this is to use the :class:`io.StringIO` class::
149+
The easiest way to do this is to use the :class:`io.StringIO` class:
150+
151+
.. code-block:: pycon
150152
151153
>>> import io, sys
152154
>>> sys.stdout = io.StringIO()
@@ -156,7 +158,9 @@ The easiest way to do this is to use the :class:`io.StringIO` class::
156158
foo
157159
hello world!
158160
159-
A custom object to do the same would look like this::
161+
A custom object to do the same would look like this:
162+
163+
.. code-block:: pycon
160164
161165
>>> import io, sys
162166
>>> class StdoutCatcher(io.TextIOBase):
@@ -222,11 +226,15 @@ How do I debug an extension?
222226
When using GDB with dynamically loaded extensions, you can't set a breakpoint in
223227
your extension until your extension is loaded.
224228

225-
In your ``.gdbinit`` file (or interactively), add the command::
229+
In your ``.gdbinit`` file (or interactively), add the command:
230+
231+
.. code-block:: none
226232
227233
br _PyImport_LoadDynamicModule
228234
229-
Then, when you run GDB::
235+
Then, when you run GDB:
236+
237+
.. code-block:: shell-session
230238
231239
$ gdb /local/bin/python
232240
gdb) run myscript.py

Doc/howto/clinic.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ Let's dive in!
152152
For my example I'm using ``_pickle.Pickler.dump()``.
153153

154154
2. If the call to the ``PyArg_Parse`` function uses any of the
155-
following format units::
155+
following format units:
156+
157+
.. code-block:: none
156158
157159
O&
158160
O!

Doc/howto/logging-cookbook.rst

+15-5
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,9 @@ An example of using these two classes follows (imports omitted)::
377377
root.warning('Look out!')
378378
listener.stop()
379379

380-
which, when run, will produce::
380+
which, when run, will produce:
381+
382+
.. code-block:: none
381383
382384
MainThread: Look out!
383385
@@ -1860,7 +1862,9 @@ script, ``chowntest.py``::
18601862
logger = logging.getLogger('mylogger')
18611863
logger.debug('A debug message')
18621864

1863-
To run this, you will probably need to run as ``root``::
1865+
To run this, you will probably need to run as ``root``:
1866+
1867+
.. code-block:: shell-session
18641868
18651869
$ sudo python3.3 chowntest.py
18661870
$ cat chowntest.log
@@ -2485,7 +2489,9 @@ via ``stderr`` and once via ``stdout``). After the ``with`` statement's
24852489
completion, the status is as it was before so message #6 appears (like message
24862490
#1) whereas message #7 doesn't (just like message #2).
24872491

2488-
If we run the resulting script, the result is as follows::
2492+
If we run the resulting script, the result is as follows:
2493+
2494+
.. code-block:: shell-session
24892495
24902496
$ python logctx.py
24912497
1. This should appear just once on stderr.
@@ -2495,12 +2501,16 @@ If we run the resulting script, the result is as follows::
24952501
6. This should appear just once on stderr.
24962502
24972503
If we run it again, but pipe ``stderr`` to ``/dev/null``, we see the following,
2498-
which is the only message written to ``stdout``::
2504+
which is the only message written to ``stdout``:
2505+
2506+
.. code-block:: shell-session
24992507
25002508
$ python logctx.py 2>/dev/null
25012509
5. This should appear twice - once on stderr and once on stdout.
25022510
2503-
Once again, but piping ``stdout`` to ``/dev/null``, we get::
2511+
Once again, but piping ``stdout`` to ``/dev/null``, we get:
2512+
2513+
.. code-block:: shell-session
25042514
25052515
$ python logctx.py >/dev/null
25062516
1. This should appear just once on stderr.

Doc/howto/logging.rst

+12-5
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ A very simple example is::
106106
logging.warning('Watch out!') # will print a message to the console
107107
logging.info('I told you so') # will not print anything
108108

109-
If you type these lines into a script and run it, you'll see::
109+
If you type these lines into a script and run it, you'll see:
110+
111+
.. code-block:: none
110112
111113
WARNING:root:Watch out!
112114
@@ -230,7 +232,9 @@ append the variable data as arguments. For example::
230232
import logging
231233
logging.warning('%s before you %s', 'Look', 'leap!')
232234

233-
will display::
235+
will display:
236+
237+
.. code-block:: none
234238
235239
WARNING:root:Look before you leap!
236240
@@ -594,7 +598,9 @@ logger, a console handler, and a simple formatter using Python code::
594598
logger.error('error message')
595599
logger.critical('critical message')
596600

597-
Running this module from the command line produces the following output::
601+
Running this module from the command line produces the following output:
602+
603+
.. code-block:: shell-session
598604
599605
$ python simple_logging_module.py
600606
2005-03-19 15:10:26,618 - simple_example - DEBUG - debug message
@@ -653,7 +659,9 @@ Here is the logging.conf file::
653659
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
654660
datefmt=
655661

656-
The output is nearly identical to that of the non-config-file-based example::
662+
The output is nearly identical to that of the non-config-file-based example:
663+
664+
.. code-block:: shell-session
657665
658666
$ python simple_logging_config.py
659667
2005-03-19 15:38:55,977 - simpleExample - DEBUG - debug message
@@ -1073,4 +1081,3 @@ take up any memory.
10731081
Useful handlers included with the logging module.
10741082

10751083
:ref:`A logging cookbook <logging-cookbook>`
1076-

Doc/howto/regex.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ of the RE by repeating them or changing their meaning. Much of this document is
7474
devoted to discussing various metacharacters and what they do.
7575

7676
Here's a complete list of the metacharacters; their meanings will be discussed
77-
in the rest of this HOWTO. ::
77+
in the rest of this HOWTO.
78+
79+
.. code-block:: none
7880
7981
. ^ $ * + ? { } [ ] \ | ( )
8082

Doc/howto/unicode.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,9 @@ program::
613613
print(os.listdir(b'.'))
614614
print(os.listdir('.'))
615615

616-
will produce the following output::
616+
will produce the following output:
617+
618+
.. code-block:: shell-session
617619
618620
amk:~$ python t.py
619621
[b'filename\xe4\x94\x80abc', ...]

Doc/library/2to3.rst

+21-7
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,18 @@ Here is a sample Python 2.x source file, :file:`example.py`::
3333
name = raw_input()
3434
greet(name)
3535

36-
It can be converted to Python 3.x code via 2to3 on the command line::
36+
It can be converted to Python 3.x code via 2to3 on the command line:
37+
38+
.. code-block:: shell-session
3739
3840
$ 2to3 example.py
3941
4042
A diff against the original source file is printed. 2to3 can also write the
4143
needed modifications right back to the source file. (A backup of the original
4244
file is made unless :option:`-n` is also given.) Writing the changes back is
43-
enabled with the :option:`-w` flag::
45+
enabled with the :option:`-w` flag:
46+
47+
.. code-block:: shell-session
4448
4549
$ 2to3 -w example.py
4650
@@ -57,17 +61,23 @@ Comments and exact indentation are preserved throughout the translation process.
5761
By default, 2to3 runs a set of :ref:`predefined fixers <2to3-fixers>`. The
5862
:option:`!-l` flag lists all available fixers. An explicit set of fixers to run
5963
can be given with :option:`-f`. Likewise the :option:`!-x` explicitly disables a
60-
fixer. The following example runs only the ``imports`` and ``has_key`` fixers::
64+
fixer. The following example runs only the ``imports`` and ``has_key`` fixers:
65+
66+
.. code-block:: shell-session
6167
6268
$ 2to3 -f imports -f has_key example.py
6369
64-
This command runs every fixer except the ``apply`` fixer::
70+
This command runs every fixer except the ``apply`` fixer:
71+
72+
.. code-block:: shell-session
6573
6674
$ 2to3 -x apply example.py
6775
6876
Some fixers are *explicit*, meaning they aren't run by default and must be
6977
listed on the command line to be run. Here, in addition to the default fixers,
70-
the ``idioms`` fixer is run::
78+
the ``idioms`` fixer is run:
79+
80+
.. code-block:: shell-session
7181
7282
$ 2to3 -f all -f idioms example.py
7383
@@ -113,7 +123,9 @@ This option implies the :option:`-w` flag as it would not make sense otherwise.
113123

114124
The :option:`--add-suffix` option specifies a string to append to all output
115125
filenames. The :option:`-n` flag is required when specifying this as backups
116-
are not necessary when writing to different filenames. Example::
126+
are not necessary when writing to different filenames. Example:
127+
128+
.. code-block:: shell-session
117129
118130
$ 2to3 -n -W --add-suffix=3 example.py
119131
@@ -122,7 +134,9 @@ Will cause a converted file named ``example.py3`` to be written.
122134
.. versionadded:: 3.2.3
123135
The :option:`--add-suffix` option was added.
124136

125-
To translate an entire project from one directory tree to another use::
137+
To translate an entire project from one directory tree to another use:
138+
139+
.. code-block:: shell-session
126140
127141
$ 2to3 --output-dir=python3-version/mycode -W -n python2-version/mycode
128142

0 commit comments

Comments
 (0)