diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d0404d4..3fb4867 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,6 +39,16 @@ jobs: - run: python -m pip install black - run: black --check --diff . + docs: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v1 + - run: sudo apt-get install -y graphviz + - uses: actions/checkout@v2 + - run: git fetch --prune --unshallow + - run: python setup.py develop + - run: python setup.py build_sphinx -W + pytest: needs: - isort diff --git a/README.rst b/README.rst index 0961862..1fec310 100644 --- a/README.rst +++ b/README.rst @@ -4,6 +4,8 @@ Python measurement **High precision unit-aware measurement objects in Python.** +.. code-block:: python + >>> from measurement import measures >>> measures.Distance("12 megaparsec")["British yard"] Decimal('404948208659679393828910.8771') @@ -33,6 +35,8 @@ Using Measurement Objects You can import any of the above measures from `measurement.measures` and use it for easily handling measurements like so: +.. code-block:: python + >>> from measurement.measures import Mass >>> m = Mass(lb=135) # Represents 135 lbs >>> print(m) @@ -44,10 +48,12 @@ You can create a measurement unit using any compatible unit and can transform it into any compatible unit. See :doc:`measures` for information about which units are supported by which measures. -.. seealso:: +.. note:: Should you be planing to go to Mars, you might need to increase your `decimal precision`_, like so: + .. code-block:: python + >>> import decimal >>> decimal.getcontext().prec = 28 @@ -58,7 +64,9 @@ Guessing Measurements If you happen to be in a situation where you are processing a list of value/unit pairs (like you might find at the beginning of a recipe), you can -use the `guess` function to give you a measurement object.: +use the :func:`.guess` function to give you a measurement object.: + +.. code-block:: python >>> from measurement.utils import guess >>> m = guess(10, "mg") @@ -71,6 +79,8 @@ measures checked (or your own measurement classes, too) to make sure that your measurement is not mis-guessed, and you can do that by specifying the ``measures`` keyword argument: +.. code-block:: python + >>> from measurement.measures import Distance, Temperature, Volume >>> m = guess(24, "°F", measures=[Distance, Volume, Temperature]) >>> print(repr(m)) diff --git a/docs/measures.rst b/docs/measures.rst index 782072b..f78cf21 100644 --- a/docs/measures.rst +++ b/docs/measures.rst @@ -75,3 +75,11 @@ Supported Measures and Units :members: :undoc-members: :imported-members: + +Units +----- + +.. automodule:: measurement.utils + :members: + :undoc-members: + :imported-members: