Merge branch 'develop'

This commit is contained in:
Hernan Grecco 2016-11-18 01:23:15 -03:00
commit c3291eea39
4 changed files with 168 additions and 79 deletions

110
.travis-full.yml Normal file
View File

@ -0,0 +1,110 @@
language: python
python:
- "2.6"
- "2.7"
- "3.3"
- "3.4"
- "3.5"
env:
- UNCERTAINTIES="N" NUMPY_VERSION=0
- UNCERTAINTIES="N" NUMPY_VERSION=1.6.2
- UNCERTAINTIES="N" NUMPY_VERSION=1.7.1
- UNCERTAINTIES="N" NUMPY_VERSION=1.8.2
- UNCERTAINTIES="N" NUMPY_VERSION=1.9.3
- UNCERTAINTIES="N" NUMPY_VERSION=1.10.4
- UNCERTAINTIES="Y" NUMPY_VERSION=0
- UNCERTAINTIES="Y" NUMPY_VERSION=1.6.2
- UNCERTAINTIES="Y" NUMPY_VERSION=1.7.1
- UNCERTAINTIES="Y" NUMPY_VERSION=1.8.2
- UNCERTAINTIES="Y" NUMPY_VERSION=1.9.3
- UNCERTAINTIES="Y" NUMPY_VERSION=1.10.4
branches:
only:
- master
- develop
before_install:
- sudo apt-get update
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
wget https://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh;
else
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
fi
- bash miniconda.sh -b -p $HOME/miniconda
- export PATH="$HOME/miniconda/bin:$PATH"
- hash -r
- conda config --set always_yes yes --set changeps1 no
- conda update -q conda
# Useful for debugging any issues with conda
- conda info -a
# The next couple lines fix a crash with multiprocessing on Travis and are not specific to using Miniconda
- sudo rm -rf /dev/shm
- sudo ln -s /run/shm /dev/shm
- export ENV_NAME=travis
install:
- conda create -c mwcraig --yes -n $ENV_NAME python=$TRAVIS_PYTHON_VERSION pip
- source activate $ENV_NAME
- if [ $TRAVIS_PYTHON_VERSION == '2.6' ]; then pip install unittest2; fi
- if [ $UNCERTAINTIES == 'Y' ]; then pip install 'uncertainties==2.4.7.1'; fi
- if [ $NUMPY_VERSION != '0' ]; then conda install -c mwcraig --yes numpy==$NUMPY_VERSION; fi
- if [ $TRAVIS_PYTHON_VERSION == '3.2' ]; then pip install coverage==3.7.1; else pip install coverage; fi
- if [[ $TRAVIS_PYTHON_VERSION == '3.5' && $NUMPY_VERSION == 1.10.4 && $UNCERTAINTIES == "Y" ]]; then pip install serialize pyyaml; fi
- pip install coveralls
script:
- if [ $TRAVIS_PYTHON_VERSION == '2.6' ]; then coverage run -p --source=pint --omit="*test*","*compat*" setup.py test; fi
- if [ $TRAVIS_PYTHON_VERSION != '2.6' ]; then python -bb -m coverage run -p --source=pint --omit="*test*","*compat*" setup.py test; fi
- coverage combine
- coverage report -m
after_success:
- coveralls --verbose
matrix:
exclude:
# Do not edit after this line
- python: "3.5"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.8.2
- python: "3.5"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.6.2
- python: "3.5"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.8.2
- python: "3.5"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.6.2
- python: "3.5"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.7.1
- python: "3.5"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.7.1
- python: "3.4"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.6.2
- python: "3.4"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.6.2
- python: "3.4"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.7.1
- python: "3.4"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.7.1
- python: "3.3"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.6.2
- python: "3.3"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.9.3
- python: "3.3"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.10.4
- python: "3.3"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.6.2
- python: "3.3"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.9.3
- python: "3.3"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.10.4
- python: "2.6"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.9.3
- python: "2.6"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.10.4
- python: "2.6"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.9.3
- python: "2.6"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.10.4

View File

@ -1,24 +1,14 @@
language: python
python:
- "2.6"
- "2.7"
- "3.3"
- "3.4"
- "3.5"
env:
- UNCERTAINTIES="N" NUMPY_VERSION=0
- UNCERTAINTIES="N" NUMPY_VERSION=1.6.2
- UNCERTAINTIES="N" NUMPY_VERSION=1.7.1
- UNCERTAINTIES="N" NUMPY_VERSION=1.8.2
- UNCERTAINTIES="N" NUMPY_VERSION=1.9.3
- UNCERTAINTIES="N" NUMPY_VERSION=1.10.4
- UNCERTAINTIES="Y" NUMPY_VERSION=0
- UNCERTAINTIES="Y" NUMPY_VERSION=1.6.2
- UNCERTAINTIES="Y" NUMPY_VERSION=1.7.1
- UNCERTAINTIES="Y" NUMPY_VERSION=1.8.2
- UNCERTAINTIES="Y" NUMPY_VERSION=1.9.3
- UNCERTAINTIES="Y" NUMPY_VERSION=1.10.4
- UNCERTAINTIES="N" PYTHON="2.6" NUMPY_VERSION=1.9.2
- UNCERTAINTIES="N" PYTHON="2.7" NUMPY_VERSION=1.11.2
- UNCERTAINTIES="N" PYTHON="3.3" NUMPY_VERSION=1.9.2
- UNCERTAINTIES="N" PYTHON="3.4" NUMPY_VERSION=1.11.2
- UNCERTAINTIES="N" PYTHON="3.5" NUMPY_VERSION=1.11.2
- UNCERTAINTIES="Y" PYTHON="3.5" NUMPY_VERSION=1.11.2
- UNCERTAINTIES="N" PYTHON="2.7" NUMPY_VERSION=0
- UNCERTAINTIES="N" PYTHON="3.5" NUMPY_VERSION=0
branches:
only:
@ -27,7 +17,7 @@ branches:
before_install:
- sudo apt-get update
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
- if [[ "$PYTHON" == "2.7" ]]; then
wget https://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh;
else
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
@ -47,64 +37,20 @@ before_install:
- export ENV_NAME=travis
install:
- conda create -c mwcraig --yes -n $ENV_NAME python=$TRAVIS_PYTHON_VERSION pip
- conda create --yes -n $ENV_NAME python=$PYTHON pip
- source activate $ENV_NAME
- if [ $TRAVIS_PYTHON_VERSION == '2.6' ]; then pip install unittest2; fi
- if [ $PYTHON == '2.6' ]; then pip install unittest2; fi
- if [ $UNCERTAINTIES == 'Y' ]; then pip install 'uncertainties==2.4.7.1'; fi
- if [ $NUMPY_VERSION != '0' ]; then conda install -c mwcraig --yes numpy==$NUMPY_VERSION; fi
- if [ $TRAVIS_PYTHON_VERSION == '3.2' ]; then pip install coverage==3.7.1; else pip install coverage; fi
- if [[ $TRAVIS_PYTHON_VERSION == '3.5' && $NUMPY_VERSION == 1.10.4 && $UNCERTAINTIES == "Y" ]]; then pip install serialize pyyaml; fi
- if [ $NUMPY_VERSION != '0' ]; then conda install --yes numpy==$NUMPY_VERSION; fi
- if [ $PYTHON == '3.2' ]; then pip install coverage==3.7.1; else pip install coverage; fi
- if [[ $TRAVIS_PYTHON_VERSION == '3.5' && $NUMPY_VERSION == 1.11.2 && $UNCERTAINTIES == "Y" ]]; then pip install serialize pyyaml; fi
- pip install coveralls
script:
- if [ $TRAVIS_PYTHON_VERSION == '2.6' ]; then coverage run -p --source=pint --omit="*test*","*compat*" setup.py test; fi
- if [ $TRAVIS_PYTHON_VERSION != '2.6' ]; then python -bb -m coverage run -p --source=pint --omit="*test*","*compat*" setup.py test; fi
- if [ $PYTHON == '2.6' ]; then coverage run -p --source=pint --omit="*test*","*compat*" setup.py test; fi
- if [ $PYTHON != '2.6' ]; then python -bb -m coverage run -p --source=pint --omit="*test*","*compat*" setup.py test; fi
- coverage combine
- coverage report -m
after_success:
- coveralls --verbose
matrix:
exclude:
# Do not edit after this line
- python: "3.5"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.8.2
- python: "3.5"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.6.2
- python: "3.5"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.8.2
- python: "3.5"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.6.2
- python: "3.5"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.7.1
- python: "3.5"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.7.1
- python: "3.4"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.6.2
- python: "3.4"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.6.2
- python: "3.4"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.7.1
- python: "3.4"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.7.1
- python: "3.3"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.6.2
- python: "3.3"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.9.3
- python: "3.3"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.10.4
- python: "3.3"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.6.2
- python: "3.3"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.9.3
- python: "3.3"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.10.4
- python: "2.6"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.9.3
- python: "2.6"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.10.4
- python: "2.6"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.9.3
- python: "2.6"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.10.4

25
pint/compat/meta.py Normal file
View File

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
"""
pint.compat.meta
~~~~~~~~~~~~~~~~
Compatibility layer.
:copyright: 2016 by Pint Authors, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""
def with_metaclass(meta, *bases):
"""Create a base class with a metaclass."""
# This requires a bit of explanation: the basic idea is to make a dummy
# metaclass for one level of class instantiation that replaces itself with
# the actual metaclass.
# Taken from six
class metaclass(meta):
def __new__(cls, name, this_bases, d):
return meta(name, bases, d)
return type.__new__(metaclass, 'temporary_class', (), {})

View File

@ -51,7 +51,7 @@ from .util import (logger, pi_theorem, solve_dependencies, ParserHelper,
find_shortest_path, UnitsContainer, _is_dim,
to_units_container, SourceIterator)
from .compat import tokenizer, string_types
from .compat import tokenizer, string_types, meta
from .definitions import (Definition, UnitDefinition, PrefixDefinition,
DimensionDefinition)
from .converters import ScaleConverter
@ -64,7 +64,18 @@ from . import systems
_BLOCK_RE = re.compile(r' |\(')
class BaseRegistry(object):
class _Meta(type):
"""This is just to call after_init at the right time
instead of asking the developer to do it when subclassing.
"""
def __call__(self, *args, **kwargs):
obj = super(_Meta, self).__call__(*args, **kwargs)
obj._after_init()
return obj
class BaseRegistry(meta.with_metaclass(_Meta)):
"""Base class for all registries.
Capabilities:
@ -76,9 +87,6 @@ class BaseRegistry(object):
- Parse a definition file.
- Allow extending the definition file parser by registering @ directives.
Its methods, `_after_init` should be called.
TODO: Make this unnecessary by using metaclasses
:param filename: path of the units definition file to load.
Empty to load the default definition file.
None to leave the UnitRegistry empty.
@ -153,10 +161,10 @@ class BaseRegistry(object):
#: Cache the unit name associated to user input. ('mV' -> 'millivolt')
self._parse_unit_cache = dict()
self._initialized = False
def _after_init(self):
"""This should be called after all __init__
TODO: Implement this with metaclasses or similar to avoid missing the call.
"""
if self._filename == '':
self.load_definitions('default_en.txt', True)
@ -166,6 +174,7 @@ class BaseRegistry(object):
self.define(UnitDefinition('pi', 'π', (), ScaleConverter(math.pi)))
self._build_cache()
self._initialized = True
def _register_parsers(self):
self._register_parser('@defaults', self._parse_defaults)
@ -1408,8 +1417,6 @@ class UnitRegistry(SystemRegistry, ContextRegistry, NonMultiplicativeRegistry):
autoconvert_offset_to_baseunit=autoconvert_offset_to_baseunit,
system=system)
self._after_init()
def pi_theorem(self, quantities):
"""Builds dimensionless quantities using the Buckingham π theorem
:param quantities: mapping between variable name and units
@ -1433,6 +1440,7 @@ class LazyRegistry(object):
kwargs['on_redefinition'] = 'raise'
self.__class__ = UnitRegistry
self.__init__(*args, **kwargs)
self._after_init()
def __getattr__(self, item):
if item == '_on_redefinition':