[Python-modules-commits] [python-measurement] 01/05: importing python-measurement_1.8.0.orig.tar.gz
Michael Fladischer
fladi at moszumanska.debian.org
Wed May 18 15:01:30 UTC 2016
This is an automated email from the git hooks/post-receive script.
fladi pushed a commit to branch master
in repository python-measurement.
commit 720be6a64cf803dede03f8b23becf939326b4863
Author: Michael Fladischer <FladischerMichael at fladi.at>
Date: Fri Feb 19 13:28:04 2016 +0100
importing python-measurement_1.8.0.orig.tar.gz
---
MANIFEST.in | 4 +
PKG-INFO | 18 +
docs/Makefile | 153 +++++++
docs/conf.py | 242 +++++++++++
docs/index.rst | 47 ++
docs/topics/creating_your_own_class.rst | 150 +++++++
docs/topics/installation.rst | 14 +
docs/topics/measures.rst | 128 ++++++
docs/topics/use.rst | 64 +++
docs/util.py | 53 +++
measurement.egg-info/PKG-INFO | 18 +
measurement.egg-info/SOURCES.txt | 42 ++
measurement.egg-info/dependency_links.txt | 1 +
measurement.egg-info/pbr.json | 1 +
measurement.egg-info/requires.txt | 2 +
measurement.egg-info/top_level.txt | 2 +
measurement/__init__.py | 0
measurement/base.py | 682 ++++++++++++++++++++++++++++++
measurement/measures/__init__.py | 12 +
measurement/measures/capacitance.py | 18 +
measurement/measures/current.py | 18 +
measurement/measures/distance.py | 172 ++++++++
measurement/measures/energy.py | 23 +
measurement/measures/frequency.py | 18 +
measurement/measures/mass.py | 36 ++
measurement/measures/resistance.py | 17 +
measurement/measures/speed.py | 20 +
measurement/measures/temperature.py | 23 +
measurement/measures/time.py | 32 ++
measurement/measures/voltage.py | 17 +
measurement/measures/volume.py | 60 +++
measurement/utils.py | 64 +++
readme.rst | 55 +++
requirements.txt | 2 +
setup.cfg | 5 +
setup.py | 32 ++
tests/__init__.py | 0
tests/base.py | 5 +
tests/test_distance.py | 80 ++++
tests/test_energy.py | 15 +
tests/test_speed.py | 204 +++++++++
tests/test_temperature.py | 33 ++
tests/test_utils.py | 32 ++
tests/test_volume.py | 15 +
44 files changed, 2629 insertions(+)
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..06403f7
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,4 @@
+include readme.rst
+include requirements.txt
+recursive-include tests *
+recursive-include docs *
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..4577430
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,18 @@
+Metadata-Version: 1.1
+Name: measurement
+Version: 1.8.0
+Summary: Easily use and manipulate unit-aware measurements in Python
+Home-page: http://github.com/coddingtonbear/python-measurement/
+Author: Adam Coddington
+Author-email: me at adamcoddington.net
+License: UNKNOWN
+Description: UNKNOWN
+Platform: UNKNOWN
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: MIT License
+Classifier: Operating System :: OS Independent
+Classifier: Programming Language :: Python
+Classifier: Programming Language :: Python :: 2.6
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3
+Classifier: Topic :: Utilities
diff --git a/docs/Makefile b/docs/Makefile
new file mode 100644
index 0000000..efd252f
--- /dev/null
+++ b/docs/Makefile
@@ -0,0 +1,153 @@
+# Makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS =
+SPHINXBUILD = sphinx-build
+PAPER =
+BUILDDIR = _build
+
+# Internal variables.
+PAPEROPT_a4 = -D latex_paper_size=a4
+PAPEROPT_letter = -D latex_paper_size=letter
+ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
+# the i18n builder cannot share the environment and doctrees with the others
+I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
+
+.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
+
+help:
+ @echo "Please use \`make <target>' where <target> is one of"
+ @echo " html to make standalone HTML files"
+ @echo " dirhtml to make HTML files named index.html in directories"
+ @echo " singlehtml to make a single large HTML file"
+ @echo " pickle to make pickle files"
+ @echo " json to make JSON files"
+ @echo " htmlhelp to make HTML files and a HTML help project"
+ @echo " qthelp to make HTML files and a qthelp project"
+ @echo " devhelp to make HTML files and a Devhelp project"
+ @echo " epub to make an epub"
+ @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
+ @echo " latexpdf to make LaTeX files and run them through pdflatex"
+ @echo " text to make text files"
+ @echo " man to make manual pages"
+ @echo " texinfo to make Texinfo files"
+ @echo " info to make Texinfo files and run them through makeinfo"
+ @echo " gettext to make PO message catalogs"
+ @echo " changes to make an overview of all changed/added/deprecated items"
+ @echo " linkcheck to check all external links for integrity"
+ @echo " doctest to run all doctests embedded in the documentation (if enabled)"
+
+clean:
+ -rm -rf $(BUILDDIR)/*
+
+html:
+ $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
+ @echo
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
+
+dirhtml:
+ $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
+ @echo
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
+
+singlehtml:
+ $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
+ @echo
+ @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
+
+pickle:
+ $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
+ @echo
+ @echo "Build finished; now you can process the pickle files."
+
+json:
+ $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
+ @echo
+ @echo "Build finished; now you can process the JSON files."
+
+htmlhelp:
+ $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
+ @echo
+ @echo "Build finished; now you can run HTML Help Workshop with the" \
+ ".hhp project file in $(BUILDDIR)/htmlhelp."
+
+qthelp:
+ $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
+ @echo
+ @echo "Build finished; now you can run "qcollectiongenerator" with the" \
+ ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
+ @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/python-measurement.qhcp"
+ @echo "To view the help file:"
+ @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/python-measurement.qhc"
+
+devhelp:
+ $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
+ @echo
+ @echo "Build finished."
+ @echo "To view the help file:"
+ @echo "# mkdir -p $$HOME/.local/share/devhelp/python-measurement"
+ @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/python-measurement"
+ @echo "# devhelp"
+
+epub:
+ $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
+ @echo
+ @echo "Build finished. The epub file is in $(BUILDDIR)/epub."
+
+latex:
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+ @echo
+ @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
+ @echo "Run \`make' in that directory to run these through (pdf)latex" \
+ "(use \`make latexpdf' here to do that automatically)."
+
+latexpdf:
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+ @echo "Running LaTeX files through pdflatex..."
+ $(MAKE) -C $(BUILDDIR)/latex all-pdf
+ @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
+
+text:
+ $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
+ @echo
+ @echo "Build finished. The text files are in $(BUILDDIR)/text."
+
+man:
+ $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
+ @echo
+ @echo "Build finished. The manual pages are in $(BUILDDIR)/man."
+
+texinfo:
+ $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+ @echo
+ @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
+ @echo "Run \`make' in that directory to run these through makeinfo" \
+ "(use \`make info' here to do that automatically)."
+
+info:
+ $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+ @echo "Running Texinfo files through makeinfo..."
+ make -C $(BUILDDIR)/texinfo info
+ @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
+
+gettext:
+ $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
+ @echo
+ @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
+
+changes:
+ $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
+ @echo
+ @echo "The overview file is in $(BUILDDIR)/changes."
+
+linkcheck:
+ $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
+ @echo
+ @echo "Link check complete; look for any errors in the above output " \
+ "or in $(BUILDDIR)/linkcheck/output.txt."
+
+doctest:
+ $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
+ @echo "Testing of doctests in the sources finished, look at the " \
+ "results in $(BUILDDIR)/doctest/output.txt."
diff --git a/docs/conf.py b/docs/conf.py
new file mode 100644
index 0000000..3915dde
--- /dev/null
+++ b/docs/conf.py
@@ -0,0 +1,242 @@
+# -*- coding: utf-8 -*-
+#
+# python-measurement documentation build configuration file, created by
+# sphinx-quickstart on Tue Jan 22 20:02:38 2013.
+#
+# This file is execfile()d with the current directory set to its containing dir.
+#
+# Note that not all possible configuration values are present in this
+# autogenerated file.
+#
+# All configuration values have a default; values that are commented out
+# serve to show the default.
+
+import sys, os
+
+# If extensions (or modules to document with autodoc) are in another directory,
+# add these directories to sys.path here. If the directory is relative to the
+# documentation root, use os.path.abspath to make it absolute, like shown here.
+#sys.path.insert(0, os.path.abspath('.'))
+
+# -- General configuration -----------------------------------------------------
+
+# If your documentation needs a minimal Sphinx version, state it here.
+#needs_sphinx = '1.0'
+
+# Add any Sphinx extension module names here, as strings. They can be extensions
+# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
+extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode']
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# The suffix of source filenames.
+source_suffix = '.rst'
+
+# The encoding of source files.
+#source_encoding = 'utf-8-sig'
+
+# The master toctree document.
+master_doc = 'index'
+
+# General information about the project.
+project = u'python-measurement'
+copyright = u'2013, Adam Coddington'
+
+# The version info for the project you're documenting, acts as replacement for
+# |version| and |release|, also used in various other places throughout the
+# built documents.
+#
+# The short X.Y version.
+version = '1.0'
+# The full version, including alpha/beta/rc tags.
+release = '1.0'
+
+# The language for content autogenerated by Sphinx. Refer to documentation
+# for a list of supported languages.
+#language = None
+
+# There are two options for replacing |today|: either, you set today to some
+# non-false value, then it is used:
+#today = ''
+# Else, today_fmt is used as the format for a strftime call.
+#today_fmt = '%B %d, %Y'
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+exclude_patterns = ['_build']
+
+# The reST default role (used for this markup: `text`) to use for all documents.
+#default_role = None
+
+# If true, '()' will be appended to :func: etc. cross-reference text.
+#add_function_parentheses = True
+
+# If true, the current module name will be prepended to all description
+# unit titles (such as .. function::).
+#add_module_names = True
+
+# If true, sectionauthor and moduleauthor directives will be shown in the
+# output. They are ignored by default.
+#show_authors = False
+
+# The name of the Pygments (syntax highlighting) style to use.
+pygments_style = 'sphinx'
+
+# A list of ignored prefixes for module index sorting.
+#modindex_common_prefix = []
+
+
+# -- Options for HTML output ---------------------------------------------------
+
+# The theme to use for HTML and HTML Help pages. See the documentation for
+# a list of builtin themes.
+html_theme = 'default'
+
+# Theme options are theme-specific and customize the look and feel of a theme
+# further. For a list of options available for each theme, see the
+# documentation.
+#html_theme_options = {}
+
+# Add any paths that contain custom themes here, relative to this directory.
+#html_theme_path = []
+
+# The name for this set of Sphinx documents. If None, it defaults to
+# "<project> v<release> documentation".
+#html_title = None
+
+# A shorter title for the navigation bar. Default is the same as html_title.
+#html_short_title = None
+
+# The name of an image file (relative to this directory) to place at the top
+# of the sidebar.
+#html_logo = None
+
+# The name of an image file (within the static path) to use as favicon of the
+# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
+# pixels large.
+#html_favicon = None
+
+# Add any paths that contain custom static files (such as style sheets) here,
+# relative to this directory. They are copied after the builtin static files,
+# so a file named "default.css" will overwrite the builtin "default.css".
+html_static_path = ['_static']
+
+# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
+# using the given strftime format.
+#html_last_updated_fmt = '%b %d, %Y'
+
+# If true, SmartyPants will be used to convert quotes and dashes to
+# typographically correct entities.
+#html_use_smartypants = True
+
+# Custom sidebar templates, maps document names to template names.
+#html_sidebars = {}
+
+# Additional templates that should be rendered to pages, maps page names to
+# template names.
+#html_additional_pages = {}
+
+# If false, no module index is generated.
+#html_domain_indices = True
+
+# If false, no index is generated.
+#html_use_index = True
+
+# If true, the index is split into individual pages for each letter.
+#html_split_index = False
+
+# If true, links to the reST sources are added to the pages.
+#html_show_sourcelink = True
+
+# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
+#html_show_sphinx = True
+
+# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
+#html_show_copyright = True
+
+# If true, an OpenSearch description file will be output, and all pages will
+# contain a <link> tag referring to it. The value of this option must be the
+# base URL from which the finished HTML is served.
+#html_use_opensearch = ''
+
+# This is the file name suffix for HTML files (e.g. ".xhtml").
+#html_file_suffix = None
+
+# Output file base name for HTML help builder.
+htmlhelp_basename = 'python-measurementdoc'
+
+
+# -- Options for LaTeX output --------------------------------------------------
+
+latex_elements = {
+# The paper size ('letterpaper' or 'a4paper').
+#'papersize': 'letterpaper',
+
+# The font size ('10pt', '11pt' or '12pt').
+#'pointsize': '10pt',
+
+# Additional stuff for the LaTeX preamble.
+#'preamble': '',
+}
+
+# Grouping the document tree into LaTeX files. List of tuples
+# (source start file, target name, title, author, documentclass [howto/manual]).
+latex_documents = [
+ ('index', 'python-measurement.tex', u'python-measurement Documentation',
+ u'Adam Coddington', 'manual'),
+]
+
+# The name of an image file (relative to this directory) to place at the top of
+# the title page.
+#latex_logo = None
+
+# For "manual" documents, if this is true, then toplevel headings are parts,
+# not chapters.
+#latex_use_parts = False
+
+# If true, show page references after internal links.
+#latex_show_pagerefs = False
+
+# If true, show URL addresses after external links.
+#latex_show_urls = False
+
+# Documents to append as an appendix to all manuals.
+#latex_appendices = []
+
+# If false, no module index is generated.
+#latex_domain_indices = True
+
+
+# -- Options for manual page output --------------------------------------------
+
+# One entry per manual page. List of tuples
+# (source start file, name, description, authors, manual section).
+man_pages = [
+ ('index', 'python-measurement', u'python-measurement Documentation',
+ [u'Adam Coddington'], 1)
+]
+
+# If true, show URL addresses after external links.
+#man_show_urls = False
+
+
+# -- Options for Texinfo output ------------------------------------------------
+
+# Grouping the document tree into Texinfo files. List of tuples
+# (source start file, target name, title, author,
+# dir menu entry, description, category)
+texinfo_documents = [
+ ('index', 'python-measurement', u'python-measurement Documentation',
+ u'Adam Coddington', 'python-measurement', 'One line description of project.',
+ 'Miscellaneous'),
+]
+
+# Documents to append as an appendix to all manuals.
+#texinfo_appendices = []
+
+# If false, no module index is generated.
+#texinfo_domain_indices = True
+
+# How to display URL addresses: 'footnote', 'no', or 'inline'.
+#texinfo_show_urls = 'footnote'
diff --git a/docs/index.rst b/docs/index.rst
new file mode 100644
index 0000000..e81ea19
--- /dev/null
+++ b/docs/index.rst
@@ -0,0 +1,47 @@
+.. python-measurement documentation master file, created by
+ sphinx-quickstart on Tue Jan 22 20:02:38 2013.
+ You can adapt this file completely to your liking, but it should at least
+ contain the root `toctree` directive.
+
+python-measurement
+==================
+
+.. image:: https://travis-ci.org/coddingtonbear/python-measurement.png?branch=master
+ :target: https://travis-ci.org/coddingtonbear/python-measurement
+
+Easily use and manipulate unit-aware measurement objects in Python.
+
+`django.contrib.gis.measure <https://github.com/django/django/blob/master/django/contrib/gis/measure.py>`_
+has these wonderful 'Distance' objects that can be used not only for storing a
+unit-aware distance measurement, but also for converting between different
+units and adding/subtracting these objects from one another.
+
+This module not only provides those Distance and Area measurement objects
+(courtesy of Django), but also other measurements including Weight, Volume, and
+Temperature.
+
+.. warning::
+ Measurements are stored internally by converting them to a
+ floating-point number of a (generally) reasonable SI unit. Given that
+ floating-point numbers are very slightly lossy, you should be aware of
+ any inaccuracies that this might cause.
+
+ TLDR: Do not use this in
+ `navigation algorithms guiding probes into the atmosphere of extraterrestrial worlds <http://en.wikipedia.org/wiki/Mars_Climate_Orbiter>`_.
+
+Contents:
+
+.. toctree::
+ :maxdepth: 2
+ :glob:
+
+ topics/*
+
+
+Indices and tables
+==================
+
+* :ref:`genindex`
+* :ref:`modindex`
+* :ref:`search`
+
diff --git a/docs/topics/creating_your_own_class.rst b/docs/topics/creating_your_own_class.rst
new file mode 100644
index 0000000..d9abbf1
--- /dev/null
+++ b/docs/topics/creating_your_own_class.rst
@@ -0,0 +1,150 @@
+
+Creating your own Measure Class
+===============================
+
+You can create your own measures easily by subclassing either
+``measurement.base.MeasureBase`` or ``measurement.base.BidimensionalMeasure``.
+
+
+Simple Measures
+---------------
+
+If your measure is not a measure dependent upon another measure (e.g speed,
+distance/time) you can create new measurement by creating a subclass of
+``measurement.base.MeasureBase``.
+
+A simple example is Weight:
+
+.. code-block:: python
+
+ from measurement.base import MeasureBase
+
+ class Weight(MeasureBase):
+ STANDARD_UNIT = 'g'
+ UNITS = {
+ 'g': 1.0,
+ 'tonne': 1000000.0,
+ 'oz': 28.3495,
+ 'lb': 453.592,
+ 'stone': 6350.29,
+ 'short_ton': 907185.0,
+ 'long_ton': 1016000.0,
+ }
+ ALIAS = {
+ 'gram': 'g',
+ 'ton': 'short_ton',
+ 'metric tonne': 'tonne',
+ 'metric ton': 'tonne',
+ 'ounce': 'oz',
+ 'pound': 'lb',
+ 'short ton': 'short_ton',
+ 'long ton': 'long_ton',
+ }
+ SI_UNITS = ['g']
+
+Important details:
+
+* ``STANDARD_UNIT`` defines what unit will be used internally by the library
+ for storing the value of this measurement.
+* ``UNITS`` provides a mapping relating a unit of your ``STANDRD_UNIT`` to
+ any number of defined units. In the example above, you will see that
+ we've established ``28.3495 g`` to be equal to ``1 oz``.
+* ``ALIAS`` provides a list of aliases mapping keyword arguments to ``UNITS``.
+ these values are allowed to be used as keyword arguments when either creating
+ a new unit or guessing a measurement using ``measurement.utils.guess``.
+* ``SI_UNITS`` provides a list of units that are SI Units. Units in this list
+ will automatically have new units and aliases created for each of the main
+ SI magnitudes. In the above example, this causes the list of ``UNITS``
+ and ``ALIAS`` es to be extended to include the following units (aliases):
+ ``yg`` (yottagrams), ``zg`` (zeptograms), ``ag`` (attograms),
+ ``fg`` (femtograms), ``pg`` (picograms), ``ng`` (nanograms),
+ ``ug`` (micrograms), ``mg`` (milligrams), ``kg`` (kilograms),
+ ``Mg`` (megagrams), ``Gg`` (gigagrams), ``Tg`` (teragrams),
+ ``Pg`` (petagrams), ``Eg`` (exagrams), ``Zg`` (zetagrams),
+ ``Yg`` (yottagrams).
+
+Using formula-based conversions
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+In some situations, your conversions between units may not be simple enough
+to be accomplished by using simple conversions (e.g. temperature); for
+situations like that, you should use ``sympy`` to create expressions relating
+your measure's standard unit and the unit you're defining:
+
+.. code-block:: python
+
+ from sympy import S, Symbol
+ from measurement.base import MeasureBase
+
+ class Tempoerature(MeasureBase):
+ SU = Symbol('kelvin')
+ STANDARD_UNIT = 'k'
+ UNITS = {
+ 'c': SU - S(273.15),
+ 'f': (SU - S(273.15)) * S('9/5') + 32,
+ 'k': 1.0
+ }
+ ALIAS = {
+ 'celsius': 'c',
+ 'fahrenheit': 'f',
+ 'kelvin': 'k',
+ }
+
+Important details:
+
+* See above 'Important Details' under `Normal Measures`.
+* ``SU`` must define the symbol used in expressions relating your measure's
+ ``STANDARD_UNIT`` to the unit you're defining.
+
+
+Bi-dimensional Measures
+-----------------------
+
+Some measures are really just compositions of two separate measures -- Speed,
+being a measure of the amount of distance covered over a unit of time, is one
+common example of such a measure.
+
+You can create such measures by subclassing
+``measurement.base.BidimensionalMeasure``.
+
+.. code-block:: python
+
+ from measurement.base import BidimensionalMeasure
+
+ from measurement.measures.distance import Distance
+ from measurement.measures.time import Time
+
+
+ class Speed(BidimensionalMeasure):
+ PRIMARY_DIMENSION = Distance
+ REFERENCE_DIMENSION = Time
+
+ ALIAS = {
+ 'mph': 'mi__hr',
+ 'kph': 'km__hr',
+ }
+
+Important details:
+
+* ``PRIMARY_DIMENSION`` is a class that measures the variable dimension of
+ this measure. In the case of 'miles-per-hour', this would be the 'miles'
+ or 'distance' dimension of the measurement.
+* ``REFERENCE_DIMENSION`` is a class that measures the unit (reference)
+ dimension of the measure. In the case of 'miles-per-hour', this would be
+ the 'hour' or 'time' dimension of the measurement.
+* ``ALIAS`` defines a list of convenient abbreviations for use either when
+ creating or defining a new instance of this measurement. In the above case,
+ you can create an instance of speed like ``Speed(mph=10)`` (equivalent to
+ ``Speed(mile__hour=10)``) or convert to an existing measurement (
+ ``speed_measurement``) into one of the aliased measures by accessing
+ the attribute named -- ``speed_measurement.kph`` (equivalent to
+ ``speed_measurement.kilometer__hour``).
+
+.. note::
+
+ Although unit aliases defined in a bi-dimensional measurement's ``ALIAS``
+ dictionary can be used either as keyword arguments or as attributes used
+ for conversion, unit aliases defined in simple measurements (those
+ subclassing ``measurement.base.MeasureBase``) can be used only as keyword
+ arguments.
+
diff --git a/docs/topics/installation.rst b/docs/topics/installation.rst
new file mode 100644
index 0000000..e73291c
--- /dev/null
+++ b/docs/topics/installation.rst
@@ -0,0 +1,14 @@
+
+Installation
+============
+
+You can either install from pip::
+
+ pip install measurement
+
+*or* checkout and install the source from the `github repository <https://github.com/coddingtonbear/python-measurement/>`_::
+
+ git clone https://github.com/coddingtonbear/python-measurement.git
+ cd python-measurement
+ python setup.py install
+
diff --git a/docs/topics/measures.rst b/docs/topics/measures.rst
new file mode 100644
index 0000000..de35053
--- /dev/null
+++ b/docs/topics/measures.rst
@@ -0,0 +1,128 @@
+Measures
+========
+
+This application provides the following measures:
+
+.. note::
+ Python has restrictions on what can be used as a method attribute; if you
+ are not very familiar with python, the below chart outlines which
+ units can be used only when creating a new measurement object ('Acceptable
+ as Arguments') and which are acceptable for use either when creating a
+ new measurement object, or for converting a measurement object to a
+ different unit ('Acceptable as Arguments or Attributes')
+
+ Units that are acceptable as arguments (like the distance measurement
+ term ``km``) can be used like::
+
+ >>> from measurement.measures import Distance
+ >>> distance = Distance(km=10)
+
+ or can be used for converting other measures into kilometers:
+
+ >>> from measurement.measures import Distance
+ >>> distance = Distance(mi=10).km
+
+ but units that are only acceptable as arguments (like the distance
+ measurement term ``kilometer``) can *only* be used to create a measurement:
+
+ >>> from measurement.measures import Distance
+ >>> distance = Distance(kilometer=10)
+
+ You also might notice that some measures have arguments having spaces in
+ their name marked as 'Acceptable as Arguments'; their primary use is for
+ when using ``measurement.guess``::
+
+ >>> from measurement.utils import guess
+ >>> unit = 'U.S. Foot'
+ >>> value = 10
+ >>> measurement = guess(value, unit)
+ >>> print measurement
+ 10.0 U.S. Foot
+
+
+Area
+----
+
+* *Acceptable as Arguments or Attributes*: ``sq_Em``, ``sq_Gm``, ``sq_Mm``, ``sq_Pm``, ``sq_Tm``, ``sq_Ym``, ``sq_Zm``, ``sq_am``, ``sq_british_chain_benoit``, ``sq_british_chain_sears_truncated``, ``sq_british_chain_sears``, ``sq_british_ft``, ``sq_british_yd``, ``sq_chain_benoit``, ``sq_chain_sears``, ``sq_chain``, ``sq_clarke_ft``, ``sq_clarke_link``, ``sq_cm``, ``sq_dam``, ``sq_dm``, ``sq_fathom``, ``sq_fm``, ``sq_ft``, ``sq_german_m``, ``sq_gold_coast_ft``, ``sq_hm``, ``sq_inch``, ` [...]
+* *Acceptable as Arguments*: ``British chain (Benoit 1895 B)``, ``British chain (Sears 1922 truncated)``, ``British chain (Sears 1922)``, ``British foot (Sears 1922)``, ``British foot``, ``British yard (Sears 1922)``, ``British yard``, ``Chain (Benoit)``, ``Chain (Sears)``, ``Clarke's Foot``, ``Clarke's link``, ``Foot (International)``, ``German legal metre``, ``Gold Coast foot``, ``Indian yard``, ``Link (Benoit)``, ``Link (Sears)``, ``Nautical Mile (UK)``, ``Nautical Mile``, ``U.S. Foot [...]
+
+Distance
+--------
+
+* *Acceptable as Arguments or Attributes*: ``Em``, ``Gm``, ``Mm``, ``Pm``, ``Tm``, ``Ym``, ``Zm``, ``am``, ``british_chain_benoit``, ``british_chain_sears_truncated``, ``british_chain_sears``, ``british_ft``, ``british_yd``, ``chain_benoit``, ``chain_sears``, ``chain``, ``clarke_ft``, ``clarke_link``, ``cm``, ``dam``, ``dm``, ``fathom``, ``fm``, ``ft``, ``german_m``, ``gold_coast_ft``, ``hm``, ``inch``, ``indian_yd``, ``km``, ``link_benoit``, ``link_sears``, ``link``, ``m``, ``mi``, ``mm [...]
+* *Acceptable as Arguments*: ``British chain (Benoit 1895 B)``, ``British chain (Sears 1922 truncated)``, ``British chain (Sears 1922)``, ``British foot (Sears 1922)``, ``British foot``, ``British yard (Sears 1922)``, ``British yard``, ``Chain (Benoit)``, ``Chain (Sears)``, ``Clarke's Foot``, ``Clarke's link``, ``Foot (International)``, ``German legal metre``, ``Gold Coast foot``, ``Indian yard``, ``Link (Benoit)``, ``Link (Sears)``, ``Nautical Mile (UK)``, ``Nautical Mile``, ``U.S. Foot [...]
+
+Energy
+------
+
+* *Acceptable as Arguments or Attributes*: ``C``, ``EJ``, ``Ec``, ``GJ``, ``Gc``, ``J``, ``MJ``, ``Mc``, ``PJ``, ``Pc``, ``TJ``, ``Tc``, ``YJ``, ``Yc``, ``ZJ``, ``Zc``, ``aJ``, ``ac``, ``cJ``, ``c``, ``cc``, ``dJ``, ``daJ``, ``dac``, ``dc``, ``fJ``, ``fc``, ``hJ``, ``hc``, ``kJ``, ``kc``, ``mJ``, ``mc``, ``nJ``, ``nc``, ``pJ``, ``pc``, ``uJ``, ``uc``, ``yJ``, ``yc``, ``zJ``, ``zc``
+* *Acceptable as Arguments*: ``Calorie``, ``attocalorie``, ``attojoule``, ``calorie``, ``centicalorie``, ``centijoule``, ``decacalorie``, ``decajoule``, ``decicalorie``, ``decijoule``, ``exacalorie``, ``exajoule``, ``femtocalorie``, ``femtojoule``, ``gigacalorie``, ``gigajoule``, ``hectocalorie``, ``hectojoule``, ``joule``, ``kilocalorie``, ``kilojoule``, ``megacalorie``, ``megajoule``, ``microcalorie``, ``microjoule``, ``millicalorie``, ``millijoule``, ``nanocalorie``, ``nanojoule``, `` [...]
+
+Speed
+-----
+
+.. note::
+ This is a bi-dimensional measurement; bi-dimensional
+ measures are created by finding an appropriate unit in the
+ measure's primary measurement class, and an appropriate
+ in the measure's reference class, and using them as a
+ double-underscore-separated keyword argument (or, if
+ converting to another unit, as an attribute).
+
+ For example, to create an object representing 24 miles-per
+ hour::
+
+ >>> from measurement.measure import Speed
+ >>> my_speed = Speed(mile__hour=24)
+ >>> print my_speed
+ 24.0 mi/hr
+ >>> print my_speed.km__hr
+ 38.624256
+
+* *Primary Measurement*: Distance
+* *Reference Measurement*: Time
+
+Temperature
+-----------
+
+* *Acceptable as Arguments or Attributes*: ``c``, ``f``, ``k``
+* *Acceptable as Arguments*: ``celsius``, ``fahrenheit``, ``kelvin``
+
+.. warning::
+
+ Be aware that, unlike other measures, the zero points of the Celsius
+ and Farenheit scales are arbitrary and non-zero.
+
+ If you attempt, for example, to calculate the average of a series of
+ temperatures using ``sum``, be sure to supply your 'start' (zero)
+ value as zero Kelvin (read: absolute zero) rather than zero
+ degrees Celsius (which is rather warm comparatively)::
+
+ >>> temperatures = [Temperature(c=10), Temperature(c=20)]
+ >>> average = sum(temperatures, Temperature(k=0)) / len(temperatures)
+ >>> print average # The value will be shown in Kelvin by default since that is the starting unit
+ 288.15 k
+ >>> print average.c # But, you can easily get the Celsius value
+ 15.0
+ >>> average.unit = 'c' # Or, make the measurement report its value in Celsius by default
+ >>> print average
+ 15.0 c
+
+Time
+----
+
+* *Acceptable as Arguments or Attributes*: ``Esec``, ``Gsec``, ``Msec``, ``Psec``, ``Tsec``, ``Ysec``, ``Zsec``, ``asec``, ``csec``, ``dasec``, ``day``, ``dsec``, ``fsec``, ``hr``, ``hsec``, ``ksec``, ``min``, ``msec``, ``nsec``, ``psec``, ``sec``, ``usec``, ``ysec``, ``zsec``
+* *Acceptable as Arguments*: ``attosecond``, ``centisecond``, ``day``, ``decasecond``, ``decisecond``, ``exasecond``, ``femtosecond``, ``gigasecond``, ``hectosecond``, ``hour``, ``kilosecond``, ``megasecond``, ``microsecond``, ``millisecond``, ``minute``, ``nanosecond``, ``petasecond``, ``picosecond``, ``second``, ``terasecond``, ``yoctosecond``, ``yottasecond``, ``zeptosecond``, ``zetasecond``
+
+Volume
+------
+
+* *Acceptable as Arguments or Attributes*: ``El``, ``Gl``, ``Ml``, ``Pl``, ``Tl``, ``Yl``, ``Zl``, ``al``, ``cl``, ``cubic_centimeter``, ``cubic_foot``, ``cubic_inch``, ``cubic_meter``, ``dal``, ``dl``, ``fl``, ``hl``, ``imperial_g``, ``imperial_oz``, ``imperial_pint``, ``imperial_qt``, ``imperial_tbsp``, ``imperial_tsp``, ``kl``, ``l``, ``ml``, ``nl``, ``pl``, ``ul``, ``us_cup``, ``us_g``, ``us_oz``, ``us_pint``, ``us_qt``, ``us_tbsp``, ``us_tsp``, ``yl``, ``zl``
+* *Acceptable as Arguments*: ``Imperial Gram``, ``Imperial Ounce``, ``Imperial Pint``, ``Imperial Quart``, ``Imperial Tablespoon``, ``Imperial Teaspoon``, ``US Cup``, ``US Fluid Ounce``, ``US Gallon``, ``US Ounce``, ``US Pint``, ``US Quart``, ``US Tablespoon``, ``US Teaspoon``, ``attoliter``, ``attolitre``, ``centiliter``, ``centilitre``, ``cubic centimeter``, ``cubic foot``, ``cubic inch``, ``cubic meter``, ``decaliter``, ``decalitre``, ``deciliter``, ``decilitre``, ``exaliter``, ``exal [...]
+
+Weight
+------
+
+* *Acceptable as Arguments or Attributes*: ``Eg``, ``Gg``, ``Mg``, ``Pg``, ``Tg``, ``Yg``, ``Zg``, ``ag``, ``cg``, ``dag``, ``dg``, ``fg``, ``g``, ``hg``, ``kg``, ``lb``, ``long_ton``, ``mg``, ``ng``, ``oz``, ``pg``, ``short_ton``, ``stone``, ``tonne``, ``ug``, ``yg``, ``zg``
+* *Acceptable as Arguments*: ``attogram``, ``centigram``, ``decagram``, ``decigram``, ``exagram``, ``femtogram``, ``gigagram``, ``gram``, ``hectogram``, ``kilogram``, ``long ton``, ``mcg``, ``megagram``, ``metric ton``, ``metric tonne``, ``microgram``, ``milligram``, ``nanogram``, ``ounce``, ``petagram``, ``picogram``, ``pound``, ``short ton``, ``teragram``, ``ton``, ``yoctogram``, ``yottagram``, ``zeptogram``, ``zetagram``
+
diff --git a/docs/topics/use.rst b/docs/topics/use.rst
new file mode 100644
index 0000000..9da5680
--- /dev/null
+++ b/docs/topics/use.rst
@@ -0,0 +1,64 @@
+
+Using Measurement Objects
+=========================
+
+You can import any of the above measures from `measurement.measures`
+and use it for easily handling measurements like so::
+
+ >>> from measurement.measures import Weight
+ >>> w = Weight(lb=135) # Represents 135lbs
+ >>> print w
+ 135.0 lb
+ >>> print w.kg
+ 61.234919999999995
+
+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.
+
+To access the raw integer value of a measurement in the unit it was defined in,
+you can use the 'value' property::
+
+ >>> print w.value
+ 135.0
+
+
+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.::
+
+ >>> from measurement.utils import guess
+ >>> m = guess(10, 'mg')
+ >>> print repr(m)
+ Weight(mg=10.0)
+
+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::
+
+ >>> from measurement.measures import Distance, Temperature, Volume
+ >>> m = guess(24, 'f', measures=[Distance, Volume, Temperature])
+ >>> print repr(m)
+ Temperature(f=24)
+
+.. warning::
+ 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.
+
+If no match is found, a ``ValueError`` exception will be raised::
+
+ >>> m = guess(24, 'f', measures=[Distance, Volume])
+ Traceback (most recent call last):
+ File "<stdin>", line 1, in <module>
+ File "measurement/utils.py", line 61, in guess
+ ', '.join([m.__name__ for m in measures])
+ ValueError: No valid measure found for 24 f; checked Distance, Volume
+
diff --git a/docs/util.py b/docs/util.py
new file mode 100644
index 0000000..45465c3
--- /dev/null
+++ b/docs/util.py
@@ -0,0 +1,53 @@
+from __future__ import print_function
+
+from measurement.base import MeasureBase, BidimensionalMeasure
+from measurement.utils import get_all_measures
+
+for measure in get_all_measures():
+ classname = measure.__name__
+ print(classname)
+ print('-' * len(classname))
+ print()
+ if issubclass(measure, MeasureBase):
+ units = measure.get_units()
+ aliases = measure.get_aliases()
+ print(
+ '* *Acceptable as Arguments or Attributes*: %s' % (
+ ', '.join(sorted(['``%s``' % unit for unit in units]))
+ )
+ )
+ print(
+ '* *Acceptable as Arguments*: %s' % (
+ ', '.join(sorted(['``%s``' % alias for alias in aliases]))
+ )
+ )
+ elif issubclass(measure, BidimensionalMeasure):
+ print(".. note::")
+ print(" This is a bi-dimensional measurement; bi-dimensional")
+ print(" measures are created by finding an appropriate unit in the")
+ print(" measure's primary measurement class, and an appropriate")
+ print(" in the measure's reference class, and using them as a")
+ print(" double-underscore-separated keyword argument (or, if")
+ print(" converting to another unit, as an attribute).")
+ print()
+ print(" For example, to create an object representing 24 miles-per")
+ print(" hour::")
+ print()
+ print(" >>> from measurement.measure import Speed")
+ print(" >>> my_speed = Speed(mile__hour=24)")
+ print(" >>> print my_speed")
+ print(" 24.0 mi/hr")
+ print(" >>> print my_speed.km__hr")
+ print(" 38.624256")
+ print()
+ print(
+ "* *Primary Measurement*: %s" % (
+ measure.PRIMARY_DIMENSION.__name__
+ )
+ )
+ print(
+ "* *Reference Measurement*: %s" % (
+ measure.REFERENCE_DIMENSION.__name__
+ )
+ )
+ print()
diff --git a/measurement.egg-info/PKG-INFO b/measurement.egg-info/PKG-INFO
new file mode 100644
index 0000000..4577430
--- /dev/null
+++ b/measurement.egg-info/PKG-INFO
@@ -0,0 +1,18 @@
+Metadata-Version: 1.1
+Name: measurement
+Version: 1.8.0
+Summary: Easily use and manipulate unit-aware measurements in Python
+Home-page: http://github.com/coddingtonbear/python-measurement/
+Author: Adam Coddington
+Author-email: me at adamcoddington.net
+License: UNKNOWN
+Description: UNKNOWN
... 1941 lines suppressed ...
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-measurement.git
More information about the Python-modules-commits
mailing list