Skip to content

Commit

Permalink
Fix readme for PyPi and add dist check to CI suite
Browse files Browse the repository at this point in the history
  • Loading branch information
codingjoe committed Apr 18, 2020
1 parent b1d391f commit b6e1c9f
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 80 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ jobs:
- run: python setup.py develop
- run: python setup.py build_sphinx -W

dist:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v1
- run: python -m pip install --upgrade pip setuptools wheel twine readme-renderer
- uses: actions/checkout@v2
- run: python setup.py sdist bdist_wheel
- run: python -m twine check dist/*

pytest:
needs:
- isort
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: PyPi Release
name: Release

on: [release]

jobs:
build:

PyPi:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
- uses: actions/checkout@v2
- name: Install dependencies
run: python -m pip install --upgrade pip setuptools wheel twine
- name: Build dist packages
Expand Down
76 changes: 0 additions & 76 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,79 +18,3 @@ supports use cases all the way from quantum mechanics to astrophysics.
`ReadTheDocs <https://python-measurement.readthedocs.org/>`_.
- Please post issues on
`Github <https://github.com/coddingtonbear/python-measurement/issues>`_.

Installation
============

You can install the latest version of the package with Pip::

python3 -m pip install measurement

Usage
=====

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)
135 lb
>>> print(m["long ton"])
0.06027063971456692913385826772
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.

.. 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
.. _decimal precision: https://docs.python.org/3.8/library/decimal.html

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 :func:`.guess` function to give you a measurement object.:

.. code-block:: python
>>> from measurement.utils import guess
>>> m = guess(10, "mg")
>>> print(repr(m))
Mass(gram="0.010")
By default, this will check all built-in measures, and will return the first
measure having an appropriate unit. You may want to constrain the list of
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))
Temperature(fahrenheit="24.00000000000000000000000008")
If no match is found, a :class:`ValueError` exception will be raised.

.. note::
It is absolutely possible for this to misguess due to common measurement
abbreviations overlapping -- for example, both Temperature and Energy
accept the argument ``c`` for representing degrees celsius and calories
respectively. It is advisible that you constrain the list of measurements
to check to ones that you would consider appropriate for your input data.
78 changes: 77 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.. include:: ../README.rst

Contents:
**Contents:**

.. toctree::
:maxdepth: 2
Expand All @@ -9,6 +9,82 @@ Contents:
measures
custom_measures

Installation
============

You can install the latest version of the package with Pip::

python3 -m pip install measurement

Usage
=====

Using Measurement Objects
-------------------------

You can import any of the above measures from :mod:`.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)
135 lb
>>> print(m["long ton"])
0.06027063971456692913385826772
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::
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
.. _decimal precision: https://docs.python.org/3.8/library/decimal.html

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 :func:`.guess` function to give you a measurement object.:

.. code-block:: python
>>> from measurement.utils import guess
>>> m = guess(10, "mg")
>>> print(repr(m))
Mass(gram="0.010")
By default, this will check all built-in measures, and will return the first
measure having an appropriate unit. You may want to constrain the list of
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))
Temperature(fahrenheit="24.00000000000000000000000008")
If no match is found, a :class:`ValueError` exception will be raised.

.. note::
It is absolutely possible for this to misguess due to common measurement
abbreviations overlapping -- for example, both Temperature and Energy
accept the argument ``c`` for representing degrees celsius and calories
respectively. It is advisible that you constrain the list of measurements
to check to ones that you would consider appropriate for your input data.


Indices and tables
==================
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ author = Adam Coddington
author_email = me@adamcoddington.net
description = Easily use and manipulate unit-aware measurements in Python
long_description = file: README.rst
long_description_content_type = text/x-rst
url = http://github.com/coddingtonbear/python-measurement
license = MIT
license_file = LICENSE
Expand Down

0 comments on commit b6e1c9f

Please sign in to comment.