From 15cad1c89ef398c80d92bfa55202b0dc85358104 Mon Sep 17 00:00:00 2001 From: Kristian Jensen Date: Thu, 9 Nov 2017 14:32:40 +0100 Subject: [PATCH] Test symengine on travis (#146) * test: run symengine tests on travis * test: fix symengine matrix and properly indent .travis.yml * test: fix indentation error in .travis.yml * chore: check variable name type for symengine * test: raise an exception on travis if symengine could not be used * fix: add some pickle magic Tell pickle how to pickle variables --- .travis.yml | 85 +++++++++++++++++++++++--------------------- optlang/interface.py | 3 ++ optlang/symbolics.py | 5 +++ 3 files changed, 52 insertions(+), 41 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0a7f3d2f..8cd6a37d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,17 @@ language: python sudo: false python: -- '2.7' -- '3.4' -- '3.5' + - '2.7' + - '3.4' + - '3.5' +env: + global: + - secure: PBcwrLg4ZwVi9Gw25Q2adNd0uK+NCqFSiYl+ZuumkEXs4NQBbSXVd719wrWKUFdIqBy+h9ETo4Vsz/QsTZzI2mSG4zqTkm+oUxMW1tJxYEeKZvCo7GfZ883VlKFgdqvh6iouEvHSjfGbwc5cUp98CbjgI5ni01vGpDQh2hgokkI= + matrix: + - OPTLANG_USE_SYMENGINE=False + - OPTLANG_USE_SYMENGINE=True cache: -- pip: true + - pip: true addons: apt: packages: @@ -16,49 +22,46 @@ addons: - glpk-utils - pandoc before_install: -- export SYMPY_USE_CACHE=no -- export OPTLANG_USE_SYMENGINE=no -- pip install pip --upgrade -- 'echo "this is a build for: $TRAVIS_BRANCH"' -- 'if [[ "$TRAVIS_PYTHON_VERSION" != "3.5" ]]; then bash ./.travis/install_cplex.sh; fi' + - export SYMPY_USE_CACHE=no + - pip install pip --upgrade + - 'echo "this is a build for: $TRAVIS_BRANCH"' + - 'if [[ "$TRAVIS_PYTHON_VERSION" != "3.5" ]]; then bash ./.travis/install_cplex.sh; fi' install: -- pip install nose nose-progressive rednose coverage docutils flake8 codecov jsonschema -- pip install -r requirements.txt -- pip install inspyred -- pip install pypandoc -- pip install swiglpk -- pip install scipy -- python setup.py install + - pip install nose nose-progressive rednose coverage docutils flake8 codecov jsonschema + - pip install -r requirements.txt + - pip install inspyred + - pip install pypandoc + - pip install swiglpk + - pip install scipy + - pip install symengine + - python setup.py install before_script: -- flake8 . + - flake8 . script: nosetests after_success: -- codecov + - codecov notifications: slack: secure: s8Dj0MFreNwZ3Zhb0+5yJiHPL33JsxLjmoRo8f0ohLdD15L//E4VjkCsYkNEcLzid6HarEL/1JSmzAuGl40fCdLqTAoDRy01shT1zmfWQPXQlaALh5f8ExBAlyDHxKhd/B2SytYu6uhe0WOuxu/oo4c33a7pKhuV1piNcevPZew= before_deploy: -- pip install twine -- python setup.py sdist bdist_wheel -env: - global: - - secure: PBcwrLg4ZwVi9Gw25Q2adNd0uK+NCqFSiYl+ZuumkEXs4NQBbSXVd719wrWKUFdIqBy+h9ETo4Vsz/QsTZzI2mSG4zqTkm+oUxMW1tJxYEeKZvCo7GfZ883VlKFgdqvh6iouEvHSjfGbwc5cUp98CbjgI5ni01vGpDQh2hgokkI= + - pip install twine + - python setup.py sdist bdist_wheel deploy: -- provider: releases - api_key: - secure: u4aJv+5YoH3gjJpyiVoq33SqKIUtx8LWPp15pIh8hKHmUgJNyjGm7ELXOeczfQ5W7ZpnWj+ogewaes2oA0NLxBB1/MBPL7kr77hmzp+XhZomh73DzFKegbpBTgqpioBRxvPlq3HYNIWqrLkeg/HYlBW1WM6mKifFUwqbIaL+++4= - file_glob: true - file: dist/optlang*.whl - skip_cleanup: true - on: - branch: master - tags: true - repo: biosustain/optlang -- provider: pypi - user: Nikolaus.Sonnenschein - password: - secure: Gn23MUvzP1DPJXxRXUOXGBJjyMamawxey5ByrOd+JT90roljHKSk8v1wdBMH7+s1DB/ygUJqB2Zy0cBC3mr0waY6HmxKpXhddgzQzG56Eua/npTxpz58Y8xfSYF+5QqS3gcyBrYEXmeHWuEURERy0b7uYKMx/QcHAHYhTaVy4zE= - on: - branch: master - tags: true - repo: biosustain/optlang + - provider: releases + api_key: + secure: u4aJv+5YoH3gjJpyiVoq33SqKIUtx8LWPp15pIh8hKHmUgJNyjGm7ELXOeczfQ5W7ZpnWj+ogewaes2oA0NLxBB1/MBPL7kr77hmzp+XhZomh73DzFKegbpBTgqpioBRxvPlq3HYNIWqrLkeg/HYlBW1WM6mKifFUwqbIaL+++4= + file_glob: true + file: dist/optlang*.whl + skip_cleanup: true + on: + branch: master + tags: true + repo: biosustain/optlang + - provider: pypi + user: Nikolaus.Sonnenschein + password: + secure: Gn23MUvzP1DPJXxRXUOXGBJjyMamawxey5ByrOd+JT90roljHKSk8v1wdBMH7+s1DB/ygUJqB2Zy0cBC3mr0waY6HmxKpXhddgzQzG56Eua/npTxpz58Y8xfSYF+5QqS3gcyBrYEXmeHWuEURERy0b7uYKMx/QcHAHYhTaVy4zE= + on: + branch: master + tags: true + repo: biosustain/optlang diff --git a/optlang/interface.py b/optlang/interface.py index f06e5526..567e2004 100644 --- a/optlang/interface.py +++ b/optlang/interface.py @@ -304,6 +304,9 @@ def __getstate__(self): def __setstate__(self, state): self.__dict__ = state + def __reduce__(self): + return (type(self), (self.name, self.lb, self.ub, self.type, self.problem)) + def to_json(self): """ Returns a json-compatible object from the Variable that can be saved using the json module. diff --git a/optlang/symbolics.py b/optlang/symbolics.py index 6d7d89ce..dc641324 100644 --- a/optlang/symbolics.py +++ b/optlang/symbolics.py @@ -40,6 +40,8 @@ except ImportError as e: if SYMENGINE_PREFERENCE.lower() in ("true", "yes", "on"): logger.warn("Symengine could not be imported: " + str(e)) + if os.getenv('TRAVIS', None) is not None: # Travis should error here # pragma: no cover + raise RuntimeError("Symengine should be used but could not be!") USE_SYMENGINE = False else: USE_SYMENGINE = True @@ -68,6 +70,9 @@ class Symbol(symengine_Symbol): def __new__(cls, name, *args, **kwargs): + if not isinstance(name, six.string_types): + raise TypeError("name should be a string, not %s" % repr(type(name))) + return symengine_Symbol.__new__(cls, name) def __init__(self, name, *args, **kwargs):