Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(setup/ci): require and test Python 3.5, 3.6, 3.7 and 3.8 #728

Merged
merged 2 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@ services:
- xvfb
matrix:
include:
- env: RUN_TYPE=test
python: 2.7
- env: RUN_TYPE=misc
python: 3.7
- env: RUN_TYPE=test
python: 3.5
- env: RUN_TYPE=test
python: 3.6
- env: RUN_TYPE=test
python: 3.7
- env: RUN_TYPE=misc
python: 3.7
# - env: RUN_TYPE=test
# python: 3.8-dev
- env: RUN_TYPE=test
python: 3.8
# allow_failures:
# - env: RUN_TYPE=test
# python: 3.8-dev
# python: 3.8
cache:
pip: true
directories:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ FloPy requires **Python** 3.5 (or higher).

**Dependencies:**

FloPy requires **NumPy** 1.9 (or higher) and **enum34** for **Python** 3.5 (or higher).
FloPy requires **NumPy** 1.9 (or higher).


**For base and Anaconda Python distributions:**
Expand Down
16 changes: 8 additions & 8 deletions autotest/t007_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,8 +926,10 @@ def check_vertices():
model=mf, line={'line': verts},
xul=mf.dis.sr.xul, yul=mf.dis.sr.yul)

# for wn in w:
# print(str(wn))
for wn in w:
print(str(wn))
if len(w) > 5:
w = w[0:5]
assert len(w) in (3, 5), len(w)
if len(w) == 5:
assert w[0].category == DeprecationWarning, w[0]
Expand Down Expand Up @@ -1061,17 +1063,15 @@ def test_vertex_model_dot_plot():
exe_name="mf6",
sim_ws=sim_path)
disv_ml = disv_sim.get_model('gwf_1')
if sys.version_info[0] > 2:
ax = disv_ml.plot()
assert ax
ax = disv_ml.plot()
assert ax


def test_model_dot_plot():
loadpth = os.path.join('..', 'examples', 'data', 'secp')
ml = flopy.modflow.Modflow.load('secp.nam', model_ws=loadpth)
if sys.version_info[0] > 2:
ax = ml.plot()
assert ax
ax = ml.plot()
assert ax


def test_get_rc_from_node_coordinates():
Expand Down
4 changes: 0 additions & 4 deletions autotest/t011_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@
"""

import os
import sys
import flopy
import numpy as np
from nose.tools import raises

if sys.version_info[0] == 2:
FileNotFoundError = IOError


def test_mflistfile():
pth = os.path.join('..', 'examples', 'data', 'freyberg')
Expand Down
10 changes: 2 additions & 8 deletions autotest/t017_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Test binary and formatted data readers
import os
import shutil
import sys
import numpy as np
import flopy
from nose.tools import assert_raises
Expand All @@ -12,11 +11,6 @@
shutil.rmtree(cpth)
os.makedirs(cpth)

if sys.version_info[0] == 2:
closed_file_error_msg = 'I/O operation on closed file'
else:
closed_file_error_msg = 'seek of closed file'


def test_formattedfile_read():

Expand Down Expand Up @@ -102,7 +96,7 @@ def test_binaryfile_read_context():

with assert_raises(ValueError) as e:
h.get_data()
assert str(e.exception) == closed_file_error_msg, str(e.exception)
assert str(e.exception) == 'seek of closed file', str(e.exception)


def test_cellbudgetfile_read_context():
Expand All @@ -116,7 +110,7 @@ def test_cellbudgetfile_read_context():

with assert_raises(ValueError) as e:
v.get_data(text='DRAINS')
assert str(e.exception) == closed_file_error_msg, str(e.exception)
assert str(e.exception) == 'seek of closed file', str(e.exception)


def test_cellbudgetfile_read():
Expand Down
2 changes: 0 additions & 2 deletions autotest/t032_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ def test_epsgreference():
if prjtxt is None:
print("unable to retrieve CRS prj txt")
return
if sys.version_info[0] == 2:
prjtxt = prjtxt.encode('ascii')
assert isinstance(prjtxt, str),type(prjtxt)
prj = ep.to_dict()
assert 32614 in prj
Expand Down
5 changes: 1 addition & 4 deletions autotest/t034_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,7 @@ def test_uzf_surfk():


def test_read_write_nwt_options():
if sys.version_info[0] > 2:
from io import StringIO
else:
from cStringIO import StringIO
from io import StringIO

from flopy.modflow import ModflowWel, ModflowUzf1, ModflowSfr2
from flopy.utils.optionblock import OptionBlock
Expand Down
6 changes: 1 addition & 5 deletions autotest/t041_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Test the observation process load and write
"""
import os
import sys
import shutil
import numpy as np
import flopy
Expand Down Expand Up @@ -276,10 +275,7 @@ def test_multilayerhob_prfail():


def test_multilayerhob_pr_multiline():
if sys.version_info[0] > 2:
from io import StringIO
else:
from cStringIO import StringIO
from io import StringIO

problem_hob = ["2 4 7",
"1 1",
Expand Down
5 changes: 0 additions & 5 deletions autotest/t066_test_copy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Test copying of flopy objects.
"""
import sys
import os
import copy
import inspect
Expand Down Expand Up @@ -190,8 +189,6 @@ def list_is_copy(mflist1, mflist2):


def test_mf2005_copy():
if sys.version_info[0] < 3:
return
path = '../examples/data/freyberg_multilayer_transient/freyberg.nam'
model_ws, namefile = os.path.split(path)
m = fm.Modflow.load(namefile, model_ws=model_ws)
Expand All @@ -202,8 +199,6 @@ def test_mf2005_copy():


def test_mf6_copy():
if sys.version_info[0] < 3:
return
sim_ws = '../examples/data/mf6/test045_lake2tr'
sim = mf6.MFSimulation.load('mfsim.nam', 'mf6', sim_ws=sim_ws)
m = sim.get_model('lakeex2a')
Expand Down
19 changes: 3 additions & 16 deletions flopy/mbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
import shutil
import threading
import warnings
import queue as Queue

if sys.version_info > (3, 0):
import queue as Queue
else:
import Queue
from datetime import datetime
from shutil import which
from subprocess import Popen, PIPE, STDOUT
import copy
import numpy as np
Expand All @@ -26,10 +24,6 @@
from .discretization.modeltime import ModelTime
from .discretization.grid import Grid

if sys.version_info >= (3, 3):
from shutil import which
else:
from distutils.spawn import find_executable as which

# Global variables
iconst = 1 # Multiplier for individual array elements in integer and real arrays read by MODFLOW's U2DREL, U1DREL and U2DINT.
Expand Down Expand Up @@ -1603,15 +1597,8 @@ def q_output(output, q):
for t in cargs:
argv.append(t)

if sys.version_info[0:2] == (2, 7) and sys.platform != 'win32':
# Python 2.7 workaround for non-Windows
close_fds = True
else:
close_fds = False # default

# run the model with Popen
proc = Popen(argv, stdout=PIPE, stderr=STDOUT, cwd=model_ws,
close_fds=close_fds)
proc = Popen(argv, stdout=PIPE, stderr=STDOUT, cwd=model_ws)

if not use_async:
while True:
Expand Down
6 changes: 1 addition & 5 deletions flopy/modflow/mf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@

import os
import flopy
import sys
if sys.version_info[0] == 2:
from inspect import getargspec as getfullargspec
else:
from inspect import getfullargspec
from inspect import getfullargspec
from ..mbase import BaseModel
from ..pakbase import Package
from ..utils import mfreadnam
Expand Down
5 changes: 1 addition & 4 deletions flopy/modflow/mfgage.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,7 @@ def load(f, model, nper=None, ext_unit_dict=None):
openfile = not hasattr(f, 'read')
if openfile:
filename = f
if sys.version_info[0] == 2:
f = open(filename, 'r')
elif sys.version_info[0] == 3:
f = open(filename, 'r', errors='replace')
f = open(filename, 'r', errors='replace')

# dataset 0 -- header
while True:
Expand Down
23 changes: 7 additions & 16 deletions flopy/modflow/mfhyd.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,22 +228,13 @@ def write_file(self):

# write dataset 2
for idx in range(self.nhyd):
if sys.version_info[0] == 3:
f.write('{} '.format(self.obsdata['pckg'][idx].decode()))
f.write('{} '.format(self.obsdata['arr'][idx].decode()))
f.write('{} '.format(self.obsdata['intyp'][idx].decode()))
f.write('{} '.format(self.obsdata['klay'][idx] + 1))
f.write('{} '.format(self.obsdata['xl'][idx]))
f.write('{} '.format(self.obsdata['yl'][idx]))
f.write('{} '.format(self.obsdata['hydlbl'][idx].decode()))
else:
f.write('{} '.format(self.obsdata['pckg'][idx]))
f.write('{} '.format(self.obsdata['arr'][idx]))
f.write('{} '.format(self.obsdata['intyp'][idx]))
f.write('{} '.format(self.obsdata['klay'][idx] + 1))
f.write('{} '.format(self.obsdata['xl'][idx]))
f.write('{} '.format(self.obsdata['yl'][idx]))
f.write('{} '.format(self.obsdata['hydlbl'][idx]))
f.write('{} '.format(self.obsdata['pckg'][idx].decode()))
f.write('{} '.format(self.obsdata['arr'][idx].decode()))
f.write('{} '.format(self.obsdata['intyp'][idx].decode()))
f.write('{} '.format(self.obsdata['klay'][idx] + 1))
f.write('{} '.format(self.obsdata['xl'][idx]))
f.write('{} '.format(self.obsdata['yl'][idx]))
f.write('{} '.format(self.obsdata['hydlbl'][idx].decode()))
f.write('\n')

# close hydmod file
Expand Down
5 changes: 1 addition & 4 deletions flopy/modflow/mflak.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,10 +614,7 @@ def load(f, model, nper=None, ext_unit_dict=None):
openfile = not hasattr(f, 'read')
if openfile:
filename = f
if sys.version_info[0] == 2:
f = open(filename, 'r')
elif sys.version_info[0] == 3:
f = open(filename, 'r', errors='replace')
f = open(filename, 'r', errors='replace')

# dataset 0 -- header
while True:
Expand Down
2 changes: 0 additions & 2 deletions flopy/modflow/mfuzf1.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,9 +776,7 @@ def load(f, model, ext_unit_dict=None, check=False):

# dataset 0 -- header
while True:
# can't use next() because util2d uses readline()
line = f.readline()
# (can't mix iteration types in python 2)
if line[0] != '#':
break
# determine problem dimensions
Expand Down
9 changes: 1 addition & 8 deletions flopy/pakbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

import abc
import os
import sys
import platform
import webbrowser as wb

import numpy as np
Expand Down Expand Up @@ -680,12 +678,7 @@ def load(f, model, pak_type, ext_unit_dict=None, **kwargs):
openfile = not hasattr(f, 'read')
if openfile:
filename = f
if platform.system().lower() == 'windows' and \
sys.version_info[0] < 3:
import io
f = io.open(filename, 'r')
else:
f = open(filename, 'r')
f = open(filename, 'r')
elif hasattr(f, 'name'):
filename = f.name
else:
Expand Down
11 changes: 4 additions & 7 deletions flopy/plot/map.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
import sys
from ..discretization import StructuredGrid, UnstructuredGrid
from ..utils import geometry

Expand Down Expand Up @@ -899,9 +898,8 @@ def plot_pathline(self, pl, travel_time=None, **kwargs):

if 'layer' in kwargs:
kon = kwargs.pop('layer')
if sys.version_info[0] > 2:
if isinstance(kon, bytes):
kon = kon.decode()
if isinstance(kon, bytes):
kon = kon.decode()
if isinstance(kon, str):
if kon.lower() == 'all':
kon = -1
Expand Down Expand Up @@ -1046,9 +1044,8 @@ def plot_timeseries(self, ts, travel_time=None, **kwargs):
if 'layer' in kwargs:
kon = kwargs.pop('layer')

if sys.version_info[0] > 2:
if isinstance(kon, bytes):
kon = kon.decode()
if isinstance(kon, bytes):
kon = kon.decode()

if isinstance(kon, str):
if kon.lower() == 'all':
Expand Down
9 changes: 2 additions & 7 deletions flopy/utils/flopy_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,9 @@ def loadtxt(file, delimiter=' ', dtype=None, skiprows=0, use_pandas=True,

def get_url_text(url, error_msg=None):
"""
Get text from a url, using either python 3 or 2.
Get text from a url.
"""
try:
# For Python 3.0 and later
from urllib.request import urlopen
except ImportError:
# Fall back to Python 2's urllib2
from urllib2 import urlopen
from urllib.request import urlopen
try:
urlobj = urlopen(url)
text = urlobj.read().decode()
Expand Down
Loading