Skip to content

Commit 985abec

Browse files
committed
Add syntax highlighting for code/command blocks in README.
1 parent d5c66af commit 985abec

File tree

1 file changed

+63
-21
lines changed

1 file changed

+63
-21
lines changed

README.rst

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,31 @@ The library allows users to work with congruence classes (including finite field
2828

2929
Installation and Usage
3030
----------------------
31-
This library is available as a `package on PyPI <https://pypi.org/project/modulo>`__::
31+
This library is available as a `package on PyPI <https://pypi.org/project/modulo>`__:
32+
33+
.. code-block:: bash
3234
3335
python -m pip install modulo
3436
35-
The library can be imported in the usual way::
37+
The library can be imported in the usual way:
38+
39+
.. code-block:: python
3640
3741
from modulo import modulo
3842
3943
Examples
4044
^^^^^^^^
41-
This library makes it possible to work with `congruence classes <https://en.wikipedia.org/wiki/Congruence_relation>`__ (and sets of congruence classes such as finite fields) as objects. A congruence class is defined using a representative integer and a modulus::
45+
This library makes it possible to work with `congruence classes <https://en.wikipedia.org/wiki/Congruence_relation>`__ (and sets of congruence classes such as finite fields) as objects. A congruence class is defined using a representative integer and a modulus:
46+
47+
.. code-block:: python
4248
4349
>>> from modulo import modulo
4450
>>> modulo(3, 7)
4551
modulo(3, 7)
4652
47-
Built-in operators can be used to perform modular addition, modular subtraction, and modular negation of congruence classes::
53+
Built-in operators can be used to perform modular addition, modular subtraction, and modular negation of congruence classes:
54+
55+
.. code-block:: python
4856
4957
>>> modulo(3, 7) + modulo(5, 7)
5058
modulo(1, 7)
@@ -53,7 +61,9 @@ Built-in operators can be used to perform modular addition, modular subtraction,
5361
>>> -modulo(5, 7)
5462
modulo(2, 7)
5563
56-
Modular multiplication, division, inversion, and exponentiation are also supported (when they are defined)::
64+
Modular multiplication, division, inversion, and exponentiation are also supported (when they are defined):
65+
66+
.. code-block:: python
5767
5868
>>> modulo(3, 7) * modulo(5, 7)
5969
modulo(1, 7)
@@ -64,14 +74,18 @@ Modular multiplication, division, inversion, and exponentiation are also support
6474
>>> modulo(5, 7) ** (-1)
6575
modulo(3, 7)
6676
67-
Individual congruence classes can be compared with one another according to their least nonnegative residues (and, thus, can also be sorted)::
77+
Individual congruence classes can be compared with one another according to their least nonnegative residues (and, thus, can also be sorted):
78+
79+
.. code-block:: python
6880
6981
>>> mod(2, 7) < mod(3, 7)
7082
True
7183
>>> list(sorted([mod(2, 3), mod(1, 3), mod(0, 3)]))
7284
[modulo(0, 3), modulo(1, 3), modulo(2, 3)]
7385
74-
The membership operation is supported between integers and congruence classes::
86+
The membership operation is supported between integers and congruence classes:
87+
88+
.. code-block:: python
7589
7690
>>> 3 in mod(3, 7)
7791
True
@@ -83,7 +97,9 @@ The membership operation is supported between integers and congruence classes::
8397
.. |len| replace:: ``len``
8498
.. _len: https://docs.python.org/3/library/functions.html#len
8599

86-
A set of congruence classes such as a finite field can also be defined. The built-in length function |len|_ and the membership operator are supported::
100+
A set of congruence classes such as a finite field can also be defined. The built-in length function |len|_ and the membership operator are supported:
101+
102+
.. code-block:: python
87103
88104
>>> len(modulo(7))
89105
7
@@ -93,15 +109,19 @@ A set of congruence classes such as a finite field can also be defined. The buil
93109
.. |int| replace:: ``int``
94110
.. _int: https://docs.python.org/3/library/functions.html#int
95111

96-
The built-in |int|_ function can be used to retrieve the least nonnegative residue of a congruence class and the built-in |len|_ function can be used to retrieve the modulus of a congruence class or set of congruence classes (this is the recommended approach)::
112+
The built-in |int|_ function can be used to retrieve the least nonnegative residue of a congruence class and the built-in |len|_ function can be used to retrieve the modulus of a congruence class or set of congruence classes (this is the recommended approach):
113+
114+
.. code-block:: python
97115
98116
>>> c = modulo(3, 7)
99117
>>> int(c)
100118
3
101119
>>> len(c)
102120
7
103121
104-
Congruence classes and sets of congruence classes are also hashable (making it possible to use them as dictionary keys and as set members) and iterable::
122+
Congruence classes and sets of congruence classes are also hashable (making it possible to use them as dictionary keys and as set members) and iterable:
123+
124+
.. code-block:: python
105125
106126
>>> len({mod(0, 3), mod(1, 3), mod(2, 3)})
107127
3
@@ -111,14 +131,18 @@ Congruence classes and sets of congruence classes are also hashable (making it p
111131
>>> list(islice(mod(3, 7), 5))
112132
[3, 10, 17, 24, 31]
113133
114-
The `Chinese remainder theorem <https://en.wikipedia.org/wiki/Chinese_remainder_theorem>`__ can be applied to construct the intersection of two congruence classes as a congruence class (when it is possible to do so)::
134+
The `Chinese remainder theorem <https://en.wikipedia.org/wiki/Chinese_remainder_theorem>`__ can be applied to construct the intersection of two congruence classes as a congruence class (when it is possible to do so):
135+
136+
.. code-block:: python
115137
116138
>>> mod(23, 100) & mod(31, 49)
117139
modulo(423, 4900)
118140
>>> mod(2, 10) & mod(4, 20) is None
119141
True
120142
121-
Some familiar forms of notation for referring to congruence classes (and sets thereof) are also supported::
143+
Some familiar forms of notation for referring to congruence classes (and sets thereof) are also supported:
144+
145+
.. code-block:: python
122146
123147
>>> Z/(23*Z)
124148
modulo(23)
@@ -129,30 +153,40 @@ Some familiar forms of notation for referring to congruence classes (and sets th
129153
130154
Development
131155
-----------
132-
All installation and development dependencies are fully specified in ``pyproject.toml``. The ``project.optional-dependencies`` object is used to `specify optional requirements <https://peps.python.org/pep-0621>`__ for various development tasks. This makes it possible to specify additional options (such as ``docs``, ``lint``, and so on) when performing installation using `pip <https://pypi.org/project/pip>`__::
156+
All installation and development dependencies are fully specified in ``pyproject.toml``. The ``project.optional-dependencies`` object is used to `specify optional requirements <https://peps.python.org/pep-0621>`__ for various development tasks. This makes it possible to specify additional options (such as ``docs``, ``lint``, and so on) when performing installation using `pip <https://pypi.org/project/pip>`__:
157+
158+
.. code-block:: bash
133159
134160
python -m pip install .[docs,lint]
135161
136162
Documentation
137163
^^^^^^^^^^^^^
138-
The documentation can be generated automatically from the source files using `Sphinx <https://www.sphinx-doc.org>`__::
164+
The documentation can be generated automatically from the source files using `Sphinx <https://www.sphinx-doc.org>`__:
165+
166+
.. code-block:: bash
139167
140168
python -m pip install .[docs]
141169
cd docs
142170
sphinx-apidoc -f -E --templatedir=_templates -o _source .. && make html
143171
144172
Testing and Conventions
145173
^^^^^^^^^^^^^^^^^^^^^^^
146-
All unit tests are executed and their coverage is measured when using `pytest <https://docs.pytest.org>`__ (see the ``pyproject.toml`` file for configuration details)::
174+
All unit tests are executed and their coverage is measured when using `pytest <https://docs.pytest.org>`__ (see the ``pyproject.toml`` file for configuration details):
175+
176+
.. code-block:: bash
147177
148178
python -m pip install .[test]
149179
python -m pytest
150180
151-
Alternatively, all unit tests are included in the module itself and can be executed using `doctest <https://docs.python.org/3/library/doctest.html>`__::
181+
Alternatively, all unit tests are included in the module itself and can be executed using `doctest <https://docs.python.org/3/library/doctest.html>`__:
182+
183+
.. code-block:: bash
152184
153185
python src/modulo/modulo.py -v
154186
155-
Style conventions are enforced using `Pylint <https://pylint.readthedocs.io>`__::
187+
Style conventions are enforced using `Pylint <https://pylint.readthedocs.io>`__:
188+
189+
.. code-block:: bash
156190
157191
python -m pip install .[lint]
158192
python -m pylint src/modulo
@@ -167,20 +201,28 @@ Beginning with version 0.2.0, the version number format for this library and the
167201

168202
Publishing
169203
^^^^^^^^^^
170-
This library can be published as a `package on PyPI <https://pypi.org/project/modulo>`__ by a package maintainer. First, install the dependencies required for packaging and publishing::
204+
This library can be published as a `package on PyPI <https://pypi.org/project/modulo>`__ by a package maintainer. First, install the dependencies required for packaging and publishing:
205+
206+
.. code-block:: bash
171207
172208
python -m pip install .[publish]
173209
174-
Ensure that the correct version number appears in ``pyproject.toml``, and that any links in this README document to the Read the Docs documentation of this package (or its dependencies) have appropriate version numbers. Also ensure that the Read the Docs project for this library has an `automation rule <https://docs.readthedocs.io/en/stable/automation-rules.html>`__ that activates and sets as the default all tagged versions. Create and push a tag for this version (replacing ``?.?.?`` with the version number)::
210+
Ensure that the correct version number appears in ``pyproject.toml``, and that any links in this README document to the Read the Docs documentation of this package (or its dependencies) have appropriate version numbers. Also ensure that the Read the Docs project for this library has an `automation rule <https://docs.readthedocs.io/en/stable/automation-rules.html>`__ that activates and sets as the default all tagged versions. Create and push a tag for this version (replacing ``?.?.?`` with the version number):
211+
212+
.. code-block:: bash
175213
176214
git tag ?.?.?
177215
git push origin ?.?.?
178216
179-
Remove any old build/distribution files. Then, package the source into a distribution archive::
217+
Remove any old build/distribution files. Then, package the source into a distribution archive:
218+
219+
.. code-block:: bash
180220
181221
rm -rf build dist src/*.egg-info
182222
python -m build --sdist --wheel .
183223
184-
Finally, upload the package distribution archive to `PyPI <https://pypi.org>`__::
224+
Finally, upload the package distribution archive to `PyPI <https://pypi.org>`__:
225+
226+
.. code-block:: bash
185227
186228
python -m twine upload dist/*

0 commit comments

Comments
 (0)