From 491c1461f2819672eb26dd8f9c95ed1778c3bef7 Mon Sep 17 00:00:00 2001 From: Kristian Reed Date: Thu, 15 Feb 2018 13:25:31 +0100 Subject: [PATCH] add python 3 support and travis test --- .travis.yml | 28 +++++++++++++++++++--------- CMakeLists.txt | 2 +- python/sunbeam/__init__.py | 5 ++--- python/sunbeam/config.py | 5 +++-- python/sunbeam/parser.py | 6 ++++-- python/sunbeam/properties.py | 4 +++- python/sunbeam/schedule.py | 8 +++++--- python/sunbeam/sunbeam.py | 7 ++++--- tests/completions.py | 4 ++-- 9 files changed, 43 insertions(+), 26 deletions(-) diff --git a/.travis.yml b/.travis.yml index 710821898..683dea481 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ -language: cpp +language: python dist: trusty -sudo: false compiler: - gcc @@ -10,7 +9,6 @@ os: env: global: - - PYENV_VERSION=2.7 - INSTALL_ROOT=$HOME/install addons: @@ -20,10 +18,17 @@ addons: - ubuntu-toolchain-r-test packages: - libboost1.55-all-dev - - gcc-4.8 - - g++-4.8 - liblapack-dev +sudo: required + +python: + - 2.7 + - 3.6 + +matrix: + fast_finish: true + install: - pushd .. @@ -37,18 +42,23 @@ install: - mkdir opm-parser/build - pushd opm-parser/build - git checkout release/2017.10/final - - cmake -DCMAKE_PREFIX_PATH=$INSTALL_ROOT -DCMAKE_INSTALL_PREFIX=$INSTALL_ROOT -DBUILD_TESTING=OFF -DBUILD_SHARED_LIBS=ON .. + - cmake .. -DCMAKE_PREFIX_PATH=$INSTALL_ROOT + -DCMAKE_INSTALL_PREFIX=$INSTALL_ROOT + -DBUILD_TESTING=OFF + -DBUILD_SHARED_LIBS=ON - make install - popd - popd - - pip install --user -r requirements.txt + - pip install -r requirements.txt script: - mkdir build - pushd build - - cmake -DCMAKE_PREFIX_PATH=$INSTALL_ROOT -DUSE_RPATH=ON -DCMAKE_INSTALL_PREFIX=$INSTALL_ROOT .. + - cmake .. -DCMAKE_PREFIX_PATH=$INSTALL_ROOT + -DUSE_RPATH=ON + -DCMAKE_INSTALL_PREFIX=$INSTALL_ROOT + -DPYTHON_EXECUTABLE=`which python` - make install - - export PYTHONPATH=$PYTHONPATH:$INSTALL_ROOT/lib/python${PYENV_VERSION}/site-packages - ctest --output-on-failure - popd diff --git a/CMakeLists.txt b/CMakeLists.txt index 5bd4f34c8..d2fc40390 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ include( CheckCXXSourceCompiles ) include( CTest ) find_package(opm-parser REQUIRED) -find_package(PythonInterp 2.7 REQUIRED) +find_package(PythonInterp REQUIRED) set( warnings "-Wall -Wextra -pedantic -Wpointer-arith" ) set( warnings "${warnings} -Wformat-nonliteral -Wcast-align" ) diff --git a/python/sunbeam/__init__.py b/python/sunbeam/__init__.py index c8c1f8e5f..0aa965a91 100644 --- a/python/sunbeam/__init__.py +++ b/python/sunbeam/__init__.py @@ -1,11 +1,10 @@ -""" - -""" +from __future__ import absolute_import from .schedule import Well, Completion from .libsunbeam import action from .config import EclipseConfig from .parser import parse_deck, parse + __version__ = '0.0.4' __license__ = 'GNU General Public License version 3' diff --git a/python/sunbeam/config.py b/python/sunbeam/config.py index 4e2d866fd..af9382b1a 100644 --- a/python/sunbeam/config.py +++ b/python/sunbeam/config.py @@ -1,5 +1,6 @@ -from os.path import isfile -import libsunbeam as lib +from __future__ import absolute_import + +from sunbeam import libsunbeam as lib from .sunbeam import delegate @delegate(lib.SummaryConfig) diff --git a/python/sunbeam/parser.py b/python/sunbeam/parser.py index 1704c94c9..aa8553641 100644 --- a/python/sunbeam/parser.py +++ b/python/sunbeam/parser.py @@ -1,6 +1,8 @@ +from __future__ import absolute_import from os.path import isfile import json -import libsunbeam as lib + +from sunbeam import libsunbeam as lib from .properties import EclipseState @@ -108,7 +110,7 @@ def parse_deck(deck, keywords=[], recovery=[]): # carry on if isinstance(keywords, dict): keywords = [keywords] - keywords = map(json.dumps, keywords) + keywords = list(map(json.dumps, keywords)) is_file = isfile(deck) # If the deck is a file, the deck is read from # that file. Otherwise it is assumed to be a # string representation of the the deck. diff --git a/python/sunbeam/properties.py b/python/sunbeam/properties.py index 8d8443a7c..22ef71b34 100644 --- a/python/sunbeam/properties.py +++ b/python/sunbeam/properties.py @@ -1,5 +1,7 @@ +from __future__ import absolute_import from os.path import isfile -import libsunbeam as lib + +from sunbeam import libsunbeam as lib from .sunbeam import delegate from .schedule import Schedule from .config import EclipseConfig diff --git a/python/sunbeam/schedule.py b/python/sunbeam/schedule.py index 25ba3c9e4..ccc52a30d 100644 --- a/python/sunbeam/schedule.py +++ b/python/sunbeam/schedule.py @@ -1,4 +1,6 @@ -import libsunbeam as lib +from __future__ import absolute_import + +from sunbeam import libsunbeam as lib from .sunbeam import delegate @delegate(lib.Schedule) @@ -11,7 +13,7 @@ class Schedule(object): @property def wells(self): - return map(Well, self._wells) + return list(map(Well, self._wells)) def group(self, timestep=0): return {grp.name: grp for grp in self.groups(timestep)} @@ -35,7 +37,7 @@ class Well(object): return 'Well(name = "%s")' % self.name def completions(self, timestep): - return map(Completion, self._completions(timestep)) + return list(map(Completion, self._completions(timestep))) def __eq__(self,other): return self._sun.__equal__(other._sun) diff --git a/python/sunbeam/sunbeam.py b/python/sunbeam/sunbeam.py index de1bba089..5d746cc3f 100644 --- a/python/sunbeam/sunbeam.py +++ b/python/sunbeam/sunbeam.py @@ -1,4 +1,5 @@ -import libsunbeam as lib +from __future__ import absolute_import + class _delegate(object): def __init__(self, name, attr): @@ -26,13 +27,13 @@ def delegate(delegate_cls, to = '_sun'): pass setattr(cls, to, _property()) - for attr in attributes - set(cls.__dict__.keys() + ['__init__']): + for attr in attributes - set(list(cls.__dict__.keys()) + ['__init__']): setattr(cls, attr, _delegate(to, attr)) src, dst = getattr(delegate_cls, attr), getattr(cls, attr) setattr(dst, '__doc__', src.__doc__) def new__new__(_cls, this, *args, **kwargs): - new = super(cls, _cls).__new__(_cls, *args, **kwargs) + new = super(cls, _cls).__new__(_cls) setattr(new, to, this) # self._sun = this return new diff --git a/tests/completions.py b/tests/completions.py index ae402270e..5175836d9 100644 --- a/tests/completions.py +++ b/tests/completions.py @@ -29,8 +29,8 @@ class TestWells(unittest.TestCase): flowing = sunbeam.Completion.flowing() closed = sunbeam.Completion.closed() completions = self.wells[0].completions(0) - self.assertEqual(len(filter(flowing, completions)), 2) - self.assertEqual(len(filter(closed, completions)), 0) + self.assertEqual(len(list(filter(flowing, completions))), 2) + self.assertEqual(len(list(filter(closed, completions))), 0) def test_direction(self): for well in self.wells: