Skip to content

Commit a46b192

Browse files
committed
Doc improvements
1 parent 295c579 commit a46b192

File tree

8 files changed

+171
-70
lines changed

8 files changed

+171
-70
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ bundles
1616
dist
1717
**/*.egg-info
1818
.vscode
19+
docs/api

docs/api.rst

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
{% if not obj.display %}
2+
:orphan:
3+
4+
{% endif %}
5+
:mod:`{{ obj.name }}`
6+
======={{ "=" * obj.name|length }}
7+
8+
.. py:module:: {{ obj.name }}
9+
10+
{% if obj.docstring %}
11+
.. autoapi-nested-parse::
12+
13+
{{ obj.docstring|prepare_docstring|indent(3) }}
14+
15+
{% endif %}
16+
17+
{% block subpackages %}
18+
{% set visible_subpackages = obj.subpackages|selectattr("display")|list %}
19+
{% if visible_subpackages %}
20+
Subpackages
21+
-----------
22+
.. toctree::
23+
:maxdepth: 1
24+
25+
{% for subpackage in visible_subpackages %}
26+
{{ subpackage.short_name }}/index.rst
27+
{% endfor %}
28+
29+
30+
{% endif %}
31+
{% endblock %}
32+
{% block submodules %}
33+
{% set visible_submodules = obj.submodules|selectattr("display")|list %}
34+
{% if visible_submodules %}
35+
Submodules
36+
----------
37+
.. toctree::
38+
:maxdepth: 1
39+
40+
{% for submodule in visible_submodules %}
41+
{{ submodule.short_name }}/index.rst
42+
{% endfor %}
43+
44+
45+
{% endif %}
46+
{% endblock %}
47+
{% block content %}
48+
{% if obj.all is not none %}
49+
{% set visible_children = obj.children|selectattr("short_name", "in", obj.all)|list %}
50+
{% elif obj.type is equalto("package") %}
51+
{% set visible_children = obj.children|selectattr("display")|list %}
52+
{% else %}
53+
{% set visible_children = obj.children|selectattr("display")|rejectattr("imported")|list %}
54+
{% endif %}
55+
{% if visible_children %}
56+
{{ obj.type|title }} Contents
57+
{{ "-" * obj.type|length }}---------
58+
59+
60+
{% set visible_classes = visible_children|selectattr("type", "equalto", "class")|list %}
61+
{% set visible_functions = visible_children|selectattr("type", "equalto", "function")|list %}
62+
63+
{% if "show-module-summary" in autoapi_options and (visible_classes or visible_functions) %}
64+
65+
{% block classes scoped %}
66+
{% if visible_classes %}
67+
Classes
68+
~~~~~~~
69+
70+
.. autoapisummary::
71+
72+
{% for klass in visible_classes %}
73+
{{ klass.id }}
74+
{% endfor %}
75+
76+
77+
{% endif %}
78+
{% endblock %}
79+
80+
{% block functions scoped %}
81+
{% if visible_functions %}
82+
Functions
83+
~~~~~~~~~
84+
85+
.. autoapisummary::
86+
87+
{% for function in visible_functions %}
88+
{{ function.id }}
89+
{% endfor %}
90+
91+
92+
{% endif %}
93+
{% endblock %}
94+
{% endif %}
95+
{% for obj_item in visible_children %}
96+
{{ obj_item.rendered|indent(0) }}
97+
{% endfor %}
98+
{% endif %}
99+
{% endblock %}

docs/conf.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,26 @@
1515
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
1616
# ones.
1717
extensions = [
18-
"sphinx.ext.autodoc",
18+
"autoapi.extension",
1919
"sphinx.ext.intersphinx",
2020
"sphinx.ext.napoleon",
2121
"sphinx.ext.todo",
2222
]
2323

24-
# TODO: Please Read!
25-
# Uncomment the below if you use native CircuitPython modules such as
26-
# digitalio, micropython and busio. List the modules you use. Without it, the
27-
# autodoc module docs will fail to generate with a warning.
28-
# autodoc_mock_imports = ["digitalio", "busio"]
29-
24+
autoapi_keep_files = True
25+
autoapi_dirs = ["../jepler_udecimal"]
26+
autoapi_add_toctree_entry = True
27+
autoapi_options = [
28+
"members",
29+
"undoc-members",
30+
"show-inheritance",
31+
"special-members",
32+
"show-module-summary",
33+
]
34+
autoapi_python_class_content = "both"
35+
autoapi_python_use_implicit_namespaces = True
36+
autoapi_template_dir = "autoapi/templates"
37+
autoapi_root = "api"
3038

3139
intersphinx_mapping = {
3240
"python": ("https://docs.python.org/3.4", None),
@@ -71,6 +79,7 @@
7179
".DS_Store",
7280
".env",
7381
"CODE_OF_CONDUCT.md",
82+
"autoapi",
7483
]
7584

7685
# The reST default role (used for this markup: `text`) to use for all

docs/index.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ Table of Contents
88
:hidden:
99

1010
self
11+
api/index.rst
1112

1213
.. toctree::
1314
:caption: API Reference
14-
:maxdepth: 3
15-
16-
api
15+
:maxdepth: 4
1716

18-
.. toctree::
19-
:caption: Tutorials
17+
api/jepler_udecimal/index.rst
2018

2119
.. toctree::
2220
:caption: Other Links

docs/requirements.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
sphinx<4
2+
recommonmark==0.6.0
3+
sphinxcontrib-svg2pdfconverter==0.1.0
4+
astroid
5+
sphinx-autoapi
6+
isort
7+
black

jepler_udecimal/__init__.py

Lines changed: 34 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
CircuitPython as well as standard Python, though you should probably
2323
use the built in decimal module on standard Python.
2424
25+
It still requires a fairly beefy mcu to run. Importing jepler_udecimal
26+
on an nRF52840 uses about 52kB of heap.
27+
2528
* Author(s): jepler
2629
2730
Implementation Notes
@@ -37,9 +40,9 @@
3740
https://github.com/adafruit/circuitpython/releases
3841
3942
This is an implementation of decimal floating point arithmetic based on
40-
the [General Decimal Arithmetic Specification](http://speleotrove.com/decimal/decarith.html) and [IEEE standard 854-1987](http://en.wikipedia.org/wiki/IEEE_854-1987).
43+
the `General Decimal Arithmetic Specification <http://speleotrove.com/decimal/decarith.html>`_ and `IEEE standard 854-1987 <http://en.wikipedia.org/wiki/IEEE_854-1987>`_.
4144
42-
Decimal floating point has finite precision with arbitrarily large bounds.
45+
`Decimal` floating point has finite precision with arbitrarily large bounds.
4346
4447
The purpose of this module is to support arithmetic using familiar
4548
"schoolhouse" rules and to avoid some of the tricky representation
@@ -943,10 +946,12 @@ def __ge__(self, other, context=None):
943946
def compare(self, other, context=None):
944947
"""Compare self to other. Return a decimal value:
945948
949+
=============== === ==============
946950
a or b is a NaN ==> Decimal('NaN')
947951
a < b ==> Decimal('-1')
948952
a == b ==> Decimal('0')
949953
a > b ==> Decimal('1')
954+
=============== === ==============
950955
"""
951956
other = _convert_other(other, raiseit=True)
952957

@@ -3272,16 +3277,17 @@ def number_class(self, context=None):
32723277
"""Returns an indication of the class of self.
32733278
32743279
The class is one of the following strings:
3275-
sNaN
3276-
NaN
3277-
-Infinity
3278-
-Normal
3279-
-Subnormal
3280-
-Zero
3281-
+Zero
3282-
+Subnormal
3283-
+Normal
3284-
+Infinity
3280+
3281+
* sNaN
3282+
* NaN
3283+
* -Infinity
3284+
* -Normal
3285+
* -Subnormal
3286+
* -Zero
3287+
* +Zero
3288+
* +Subnormal
3289+
* +Normal
3290+
* +Infinity
32853291
"""
32863292
if self.is_snan():
32873293
return "sNaN"
@@ -4531,16 +4537,17 @@ def number_class(self, a):
45314537
"""Returns an indication of the class of the operand.
45324538
45334539
The class is one of the following strings:
4534-
-sNaN
4535-
-NaN
4536-
-Infinity
4537-
-Normal
4538-
-Subnormal
4539-
-Zero
4540-
+Zero
4541-
+Subnormal
4542-
+Normal
4543-
+Infinity
4540+
4541+
* -sNaN
4542+
* -NaN
4543+
* -Infinity
4544+
* -Normal
4545+
* -Subnormal
4546+
* -Zero
4547+
* +Zero
4548+
* +Subnormal
4549+
* +Normal
4550+
* +Infinity
45444551
45454552
>>> c = ExtendedContext.copy()
45464553
>>> c.Emin = -999
@@ -4595,26 +4602,11 @@ def plus(self, a):
45954602
return a.__pos__(context=self)
45964603

45974604
def power(self, a, b):
4598-
"""Raises a to the power of b, to modulo if given.
4599-
4600-
With two arguments, compute a**b. If a is negative then b
4601-
must be integral. The result will be inexact unless b is
4602-
integral and the result is finite and can be expressed exactly
4603-
in 'precision' digits.
4604-
4605-
With three arguments, compute (a**b) % modulo. For the
4606-
three argument form, the following restrictions on the
4607-
arguments hold:
4608-
4609-
- all three arguments must be integral
4610-
- b must be nonnegative
4611-
- at least one of a or b must be nonzero
4612-
- modulo must be nonzero and have at most 'precision' digits
4613-
4614-
The result of pow(a, b, modulo) is identical to the result
4615-
that would be obtained by computing (a**b) % modulo with
4616-
unbounded precision, but is computed more efficiently. It is
4617-
always exact.
4605+
"""Raises a to the power of b
4606+
4607+
If a is negative then b must be integral. The result will be inexact
4608+
unless b is integral and the result is finite and can be expressed
4609+
exactly in 'precision' digits.
46184610
46194611
>>> c = ExtendedContext.copy()
46204612
>>> c.Emin = -999

jepler_udecimal/utrig.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"""
1717
Trig functions using jepler_udecimal
1818
19-
Importing this module adds the relevant methods to the Decimal object.
19+
Importing this module adds the relevant methods to the `Decimal` object.
2020
2121
Generally speaking, these routines increase the precision by some amount,
2222
perform argument range reduction followed by evaluation of a taylor polynomial,
@@ -48,7 +48,7 @@
4848

4949
from . import Decimal, localcontext
5050

51-
__all__ = ["atan", "sin", "cos"]
51+
__all__ = ["acos", "asin", "atan", "cos", "sin", "tan"]
5252

5353
_point2 = Decimal(".2")
5454

@@ -190,9 +190,12 @@ def acos(x, context=None):
190190
return r
191191

192192

193-
Decimal.tan = tan
194-
Decimal.sin = sin
195-
Decimal.cos = cos
196-
Decimal.atan = atan
197-
Decimal.asin = asin
198-
Decimal.acos = acos
193+
# pylint: disable=using-constant-test
194+
# This stops a doc-building error in autoapi
195+
if 1:
196+
Decimal.tan = tan
197+
Decimal.sin = sin
198+
Decimal.cos = cos
199+
Decimal.atan = atan
200+
Decimal.asin = asin
201+
Decimal.acos = acos

0 commit comments

Comments
 (0)