Doc improvements

This commit is contained in:
Jeff Epler 2020-09-06 21:28:59 -05:00
parent 295c579265
commit a46b1926f9
8 changed files with 170 additions and 69 deletions

1
.gitignore vendored
View file

@ -16,3 +16,4 @@ bundles
dist dist
**/*.egg-info **/*.egg-info
.vscode .vscode
docs/api

View file

@ -1,8 +0,0 @@
.. If you created a package, create one automodule per module in the package.
.. If your library file(s) are nested in a directory (e.g. /adafruit_foo/foo.py)
.. use this format as the module name: "adafruit_foo.foo"
.. automodule:: jepler_udecimal
:members:

View file

@ -0,0 +1,99 @@
{% if not obj.display %}
:orphan:
{% endif %}
:mod:`{{ obj.name }}`
======={{ "=" * obj.name|length }}
.. py:module:: {{ obj.name }}
{% if obj.docstring %}
.. autoapi-nested-parse::
{{ obj.docstring|prepare_docstring|indent(3) }}
{% endif %}
{% block subpackages %}
{% set visible_subpackages = obj.subpackages|selectattr("display")|list %}
{% if visible_subpackages %}
Subpackages
-----------
.. toctree::
:maxdepth: 1
{% for subpackage in visible_subpackages %}
{{ subpackage.short_name }}/index.rst
{% endfor %}
{% endif %}
{% endblock %}
{% block submodules %}
{% set visible_submodules = obj.submodules|selectattr("display")|list %}
{% if visible_submodules %}
Submodules
----------
.. toctree::
:maxdepth: 1
{% for submodule in visible_submodules %}
{{ submodule.short_name }}/index.rst
{% endfor %}
{% endif %}
{% endblock %}
{% block content %}
{% if obj.all is not none %}
{% set visible_children = obj.children|selectattr("short_name", "in", obj.all)|list %}
{% elif obj.type is equalto("package") %}
{% set visible_children = obj.children|selectattr("display")|list %}
{% else %}
{% set visible_children = obj.children|selectattr("display")|rejectattr("imported")|list %}
{% endif %}
{% if visible_children %}
{{ obj.type|title }} Contents
{{ "-" * obj.type|length }}---------
{% set visible_classes = visible_children|selectattr("type", "equalto", "class")|list %}
{% set visible_functions = visible_children|selectattr("type", "equalto", "function")|list %}
{% if "show-module-summary" in autoapi_options and (visible_classes or visible_functions) %}
{% block classes scoped %}
{% if visible_classes %}
Classes
~~~~~~~
.. autoapisummary::
{% for klass in visible_classes %}
{{ klass.id }}
{% endfor %}
{% endif %}
{% endblock %}
{% block functions scoped %}
{% if visible_functions %}
Functions
~~~~~~~~~
.. autoapisummary::
{% for function in visible_functions %}
{{ function.id }}
{% endfor %}
{% endif %}
{% endblock %}
{% endif %}
{% for obj_item in visible_children %}
{{ obj_item.rendered|indent(0) }}
{% endfor %}
{% endif %}
{% endblock %}

View file

@ -15,18 +15,26 @@ sys.path.insert(0, os.path.abspath(".."))
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones. # ones.
extensions = [ extensions = [
"sphinx.ext.autodoc", "autoapi.extension",
"sphinx.ext.intersphinx", "sphinx.ext.intersphinx",
"sphinx.ext.napoleon", "sphinx.ext.napoleon",
"sphinx.ext.todo", "sphinx.ext.todo",
] ]
# TODO: Please Read! autoapi_keep_files = True
# Uncomment the below if you use native CircuitPython modules such as autoapi_dirs = ["../jepler_udecimal"]
# digitalio, micropython and busio. List the modules you use. Without it, the autoapi_add_toctree_entry = True
# autodoc module docs will fail to generate with a warning. autoapi_options = [
# autodoc_mock_imports = ["digitalio", "busio"] "members",
"undoc-members",
"show-inheritance",
"special-members",
"show-module-summary",
]
autoapi_python_class_content = "both"
autoapi_python_use_implicit_namespaces = True
autoapi_template_dir = "autoapi/templates"
autoapi_root = "api"
intersphinx_mapping = { intersphinx_mapping = {
"python": ("https://docs.python.org/3.4", None), "python": ("https://docs.python.org/3.4", None),
@ -71,6 +79,7 @@ exclude_patterns = [
".DS_Store", ".DS_Store",
".env", ".env",
"CODE_OF_CONDUCT.md", "CODE_OF_CONDUCT.md",
"autoapi",
] ]
# The reST default role (used for this markup: `text`) to use for all # The reST default role (used for this markup: `text`) to use for all

View file

@ -8,15 +8,13 @@ Table of Contents
:hidden: :hidden:
self self
api/index.rst
.. toctree:: .. toctree::
:caption: API Reference :caption: API Reference
:maxdepth: 3 :maxdepth: 4
api api/jepler_udecimal/index.rst
.. toctree::
:caption: Tutorials
.. toctree:: .. toctree::
:caption: Other Links :caption: Other Links

7
docs/requirements.txt Normal file
View file

@ -0,0 +1,7 @@
sphinx<4
recommonmark==0.6.0
sphinxcontrib-svg2pdfconverter==0.1.0
astroid
sphinx-autoapi
isort
black

View file

@ -22,6 +22,9 @@ Reduced version of the decimal library for CircuitPython. It runs on
CircuitPython as well as standard Python, though you should probably CircuitPython as well as standard Python, though you should probably
use the built in decimal module on standard Python. use the built in decimal module on standard Python.
It still requires a fairly beefy mcu to run. Importing jepler_udecimal
on an nRF52840 uses about 52kB of heap.
* Author(s): jepler * Author(s): jepler
Implementation Notes Implementation Notes
@ -37,9 +40,9 @@ https://git.yzena.com/gavin/bc/src/branch/master/gen/lib.bc
https://github.com/adafruit/circuitpython/releases https://github.com/adafruit/circuitpython/releases
This is an implementation of decimal floating point arithmetic based on This is an implementation of decimal floating point arithmetic based on
the [General Decimal Arithmetic Specification](http://speleotrove.com/decimal/decarith.html) and [IEEE standard 854-1987](http://en.wikipedia.org/wiki/IEEE_854-1987). the `General Decimal Arithmetic Specification <http://speleotrove.com/decimal/decarith.html>`_ and `IEEE standard 854-1987 <http://en.wikipedia.org/wiki/IEEE_854-1987>`_.
Decimal floating point has finite precision with arbitrarily large bounds. `Decimal` floating point has finite precision with arbitrarily large bounds.
The purpose of this module is to support arithmetic using familiar The purpose of this module is to support arithmetic using familiar
"schoolhouse" rules and to avoid some of the tricky representation "schoolhouse" rules and to avoid some of the tricky representation
@ -943,10 +946,12 @@ class Decimal(object):
def compare(self, other, context=None): def compare(self, other, context=None):
"""Compare self to other. Return a decimal value: """Compare self to other. Return a decimal value:
=============== === ==============
a or b is a NaN ==> Decimal('NaN') a or b is a NaN ==> Decimal('NaN')
a < b ==> Decimal('-1') a < b ==> Decimal('-1')
a == b ==> Decimal('0') a == b ==> Decimal('0')
a > b ==> Decimal('1') a > b ==> Decimal('1')
=============== === ==============
""" """
other = _convert_other(other, raiseit=True) other = _convert_other(other, raiseit=True)
@ -3272,16 +3277,17 @@ class Decimal(object):
"""Returns an indication of the class of self. """Returns an indication of the class of self.
The class is one of the following strings: The class is one of the following strings:
sNaN
NaN * sNaN
-Infinity * NaN
-Normal * -Infinity
-Subnormal * -Normal
-Zero * -Subnormal
+Zero * -Zero
+Subnormal * +Zero
+Normal * +Subnormal
+Infinity * +Normal
* +Infinity
""" """
if self.is_snan(): if self.is_snan():
return "sNaN" return "sNaN"
@ -4531,16 +4537,17 @@ class Context(object):
"""Returns an indication of the class of the operand. """Returns an indication of the class of the operand.
The class is one of the following strings: The class is one of the following strings:
-sNaN
-NaN * -sNaN
-Infinity * -NaN
-Normal * -Infinity
-Subnormal * -Normal
-Zero * -Subnormal
+Zero * -Zero
+Subnormal * +Zero
+Normal * +Subnormal
+Infinity * +Normal
* +Infinity
>>> c = ExtendedContext.copy() >>> c = ExtendedContext.copy()
>>> c.Emin = -999 >>> c.Emin = -999
@ -4595,26 +4602,11 @@ class Context(object):
return a.__pos__(context=self) return a.__pos__(context=self)
def power(self, a, b): def power(self, a, b):
"""Raises a to the power of b, to modulo if given. """Raises a to the power of b
With two arguments, compute a**b. If a is negative then b If a is negative then b must be integral. The result will be inexact
must be integral. The result will be inexact unless b is unless b is integral and the result is finite and can be expressed
integral and the result is finite and can be expressed exactly exactly in 'precision' digits.
in 'precision' digits.
With three arguments, compute (a**b) % modulo. For the
three argument form, the following restrictions on the
arguments hold:
- all three arguments must be integral
- b must be nonnegative
- at least one of a or b must be nonzero
- modulo must be nonzero and have at most 'precision' digits
The result of pow(a, b, modulo) is identical to the result
that would be obtained by computing (a**b) % modulo with
unbounded precision, but is computed more efficiently. It is
always exact.
>>> c = ExtendedContext.copy() >>> c = ExtendedContext.copy()
>>> c.Emin = -999 >>> c.Emin = -999

View file

@ -16,7 +16,7 @@
""" """
Trig functions using jepler_udecimal Trig functions using jepler_udecimal
Importing this module adds the relevant methods to the Decimal object. Importing this module adds the relevant methods to the `Decimal` object.
Generally speaking, these routines increase the precision by some amount, Generally speaking, these routines increase the precision by some amount,
perform argument range reduction followed by evaluation of a taylor polynomial, perform argument range reduction followed by evaluation of a taylor polynomial,
@ -48,7 +48,7 @@ Decimal('0.5646424733950353572009454457')
from . import Decimal, localcontext from . import Decimal, localcontext
__all__ = ["atan", "sin", "cos"] __all__ = ["acos", "asin", "atan", "cos", "sin", "tan"]
_point2 = Decimal(".2") _point2 = Decimal(".2")
@ -190,9 +190,12 @@ def acos(x, context=None):
return r return r
Decimal.tan = tan # pylint: disable=using-constant-test
Decimal.sin = sin # This stops a doc-building error in autoapi
Decimal.cos = cos if 1:
Decimal.atan = atan Decimal.tan = tan
Decimal.asin = asin Decimal.sin = sin
Decimal.acos = acos Decimal.cos = cos
Decimal.atan = atan
Decimal.asin = asin
Decimal.acos = acos