Skip to content

Commit

Permalink
Partially reorganized docs
Browse files Browse the repository at this point in the history
- api is now split into 3 parts
- files are reorganized in folders

Additionally, some class members (Quantity, Unit, Measurement, Group, Context, System)
are excluded from the docs as they confuse sphinx.
  • Loading branch information
hgrecco committed Oct 27, 2022
1 parent 12db799 commit cf3d431
Show file tree
Hide file tree
Showing 30 changed files with 446 additions and 198 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions docs/advanced/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Advanced Guides
===============

Pint contains some useful and fun feature. You will find them here.

.. toctree::
:maxdepth: 2
:hidden:

performance
serialization
defining
wrapping
measurement
pitheorem
currencies
custom-registry-class
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.. _serialization:


Serialization
=============
Expand Down
File renamed without changes.
15 changes: 0 additions & 15 deletions docs/advanced_guides.rst

This file was deleted.

71 changes: 0 additions & 71 deletions docs/api.rst

This file was deleted.

65 changes: 65 additions & 0 deletions docs/api/base.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

Base API
========

.. currentmodule:: pint


Most important classes
----------------------

.. autoclass:: UnitRegistry
:members:
:exclude-members: Quantity, Unit, Measurement, Group, Context, System

.. autoclass:: Quantity
:members:

.. autoclass:: Unit
:members:

.. autoclass:: Measurement
:members:


Exceptions and warnings
-----------------------

.. autoexception:: PintError
:members:

.. autoexception:: DefinitionSyntaxError
:members:

.. autoexception:: LogarithmicUnitCalculusError
:members:

.. autoexception:: DimensionalityError
:members:

.. autoexception:: OffsetUnitCalculusError
:members:

.. autoexception:: RedefinitionError
:members:

.. autoexception:: UndefinedUnitError
:members:

.. autoexception:: UnitStrippedWarning
:members:


Sharing registry among packages
-------------------------------
,
.. autofunction:: get_application_registry
.. autofunction:: set_application_registry

Other functions
---------------

.. autofunction:: formatter
.. autofunction:: register_unit_format
.. autofunction:: pi_theorem
.. autoclass:: Context
40 changes: 40 additions & 0 deletions docs/api/common.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Common API
==========

.. automodule:: pint.babel_names
:members:

.. automodule:: pint.compat
:members:

.. automodule:: pint.converters
:members:

.. automodule:: pint.definitions
:members:

.. automodule:: pint.errors
:members:

.. automodule:: pint.formatting
:members:

.. automodule:: pint.matplotlib
:members:

.. automodule:: pint.pint_eval
:members:

.. automodule:: pint.registry
:members:
:exclude-members: Quantity, Unit, Measurement, Group, Context, System, UnitRegistry

.. automodule:: pint.registry_helpers
:members:

.. automodule:: pint.testing
:members:

.. automodule:: pint.util
:members:
:exclude-members: Unit
39 changes: 39 additions & 0 deletions docs/api/facets.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
API facets reference
====================


.. automodule:: pint.facets.plain
:members:
:exclude-members: Quantity, Unit, Measurement, Group, Context, System

.. automodule:: pint.facets.nonmultiplicative
:members:
:exclude-members: Quantity, Unit, Measurement, Group, Context, System

.. automodule:: pint.facets.formatting
:members:
:exclude-members: Quantity, Unit, Measurement, Group, Context, System

.. automodule:: pint.facets.numpy
:members:
:exclude-members: Quantity, Unit, Measurement, Group, Context, System

.. automodule:: pint.facets.dask
:members:
:exclude-members: Quantity, Unit, Measurement, Group, Context, System

.. automodule:: pint.facets.measurement
:members:
:exclude-members: Quantity, Unit, Measurement, Group, Context, System

.. automodule:: pint.facets.group
:members:
:exclude-members: Quantity, Unit, Measurement, Group, Context, System

.. automodule:: pint.facets.system
:members:
:exclude-members: Quantity, Unit, Measurement, Group, Context, System

.. automodule:: pint.facets.context
:members:
:exclude-members: Quantity, Unit, Measurement, Group, Context, System
10 changes: 10 additions & 0 deletions docs/api/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
API reference
==============

.. toctree::
:maxdepth: 1
:hidden:

base
common
facets
12 changes: 7 additions & 5 deletions docs/dev/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,16 @@ Extension Packages
------------------

Pint naturally integrates with other libraries in the scientific Python ecosystem, and
a small number of
`extension/compatibility packages<numpy.html#Compatibility-Packages>`_ have arisen to
aid in compatibility between certain packages. Pint's rule of thumb for integration
a small _`ecosystem` have arisen to aid in compatibility between certain packages
allowing to build an

Pint's rule of thumb for integration
features that work best as an extension package versus direct inclusion in Pint is:

* Extension (separate packages)

* Duck array types that wrap Pint (come above Pint in
`the type casting hierarchy<numpy.html#Technical-Commentary>`_)
* Duck array types that wrap Pint (come above Pint
in :ref:`the type casting hierarchy <_numpy#technical-commentary>`

* Uses features independent/on top of the libraries

Expand Down Expand Up @@ -143,3 +144,4 @@ features that work best as an extension package versus direct inclusion in Pint
.. _flake8: https://flake8.pycqa.org/en/latest/
.. _pytest: https://docs.pytest.org/en/stable/
.. _sphinx: https://www.sphinx-doc.org/en/master/
.. _`extension/compatibility packages`:
File renamed without changes.
File renamed without changes.
7 changes: 4 additions & 3 deletions docs/getting_started.rst → docs/getting/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ That's all! You can check that Pint is correctly installed by starting up python
:maxdepth: 2
:hidden:

user/overview
user/tutorial
user/faq
overview
tutorial
pint-in-your-projects
faq
File renamed without changes.
70 changes: 70 additions & 0 deletions docs/getting/pint-in-your-projects.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
.. _pint_in_your_projects:

Using Pint in your projects
===========================

Having a shared registry
------------------------

If you use Pint in multiple modules within your Python package, you normally
want to avoid creating multiple instances of the unit registry.
The best way to do this is by instantiating the registry in a single place. For
example, you can add the following code to your package ``__init__.py``

.. doctest::

>>> from pint import UnitRegistry
>>> ureg = UnitRegistry()
>>> Q_ = ureg.Quantity


Then in ``yourmodule.py`` the code would be

.. code-block:: python
from . import ureg, Q_
length = 10 * ureg.meter
my_speed = Q_(20, 'm/s')
If you are pickling and unpickling Quantities within your project, you should
also define the registry as the application registry

.. code-block:: python
from pint import UnitRegistry, set_application_registry
ureg = UnitRegistry()
set_application_registry(ureg)
.. warning:: There are no global units in Pint. All units belong to a registry and
you can have multiple registries instantiated at the same time. However, you
are not supposed to operate between quantities that belong to different registries.
Never do things like this:

.. doctest::

>>> q1 = 10 * UnitRegistry().meter
>>> q2 = 10 * UnitRegistry().meter
>>> q1 + q2
Traceback (most recent call last):
...
ValueError: Cannot operate with Quantity and Quantity of different registries.
>>> id(q1._REGISTRY) == id(q2._REGISTRY)
False


Keeping up to date with Pint development
----------------------------------------

While we work hard to avoid breaking code using Pint, sometimes it
happens. To help you track how Pint is evolving it is recommended
that you run a daily or weekly job against pint master branch.

For example, this is how xarray_ is doing it:

If a new version of Pint breaks your code, please open an issue_ to
let us know.

.. _xarray: https://github.com/pydata/xarray/blob/main/.github/workflows/upstream-dev-ci.yaml
.. _issue: https://github.com/hgrecco/pint/issues
Loading

0 comments on commit cf3d431

Please sign in to comment.