Skip to content

Commit

Permalink
fix(setup.py): read package name, version, etc. from version.py (#893)
Browse files Browse the repository at this point in the history
Import of `__version__`, `__name__`, and `__author__` from `flopy` caused
failure of `setup.py` because of dependency of `flopy` on `numpy` with
python installations that did not already have `numpy` installed. Moved
all information needed by `setup.py` to `version.py` and update
`make-release.py` to retain `__name__`, `__author__`, and `__author_email__`
information in file after updating version numbers. Removed unintended
unmanaged dependency on `matplotlib` in `gridintersect.py` by wrapping
import in a try and except. In the case that `matplotlib` is not installed
and methods that depend on `matplotlib` are called then a
`ModuleNotFoundError` exception is issued.

Closes #892

* fix(setup.py): read package name, version, etc. from version.py

Import of __version__, __name__, and __author__ from flopy caused
failure of setup.py because of dependency of flopy on numpy with
python installations that did not already have numpy installed. Moved
all information needed by setup.py to version.py and update
make-release.py to retain __name__, __author__, and __author_email__
information in file after updating version numbers. Removed unintended
unmanaged dependency on matplotlib in gridintersect.py by wrapping
import in a try and except. In the case that matplotlib is not installed
and methods that depend on matplotlib are called then a
ModuleNotFoundError exception is issued.

Closes #892
  • Loading branch information
jdhughes-usgs committed May 26, 2020
1 parent 3cec792 commit b80a89c
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 26 deletions.
9 changes: 1 addition & 8 deletions flopy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,7 @@
"""

__name__ = 'flopy'
__author__ = 'Mark Bakker, Vincent Post, Christian D. Langevin, ' + \
'Joseph D. Hughes, Jeremy T. White, Andrew T. Leaf, ' + \
'Scott R. Paulinski, Joshua D. Larsen, Michael W. Toews, ' + \
'Eric D. Morway, Jason C. Bellino, Jeffrey Starn, ' + \
'and Michael N. Fienen'

from .version import __version__
from .version import __version__, __author__, __author_email__

# imports
from . import modflow
Expand Down
37 changes: 31 additions & 6 deletions flopy/utils/gridintersect.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import matplotlib.pyplot as plt
import numpy as np

try:
import matplotlib.pyplot as plt
except ModuleNotFoundError:
plt = None
print("matplotlib is needed for grid intersect operations! Please " +
"matplotlib if you need to use grid intersect functionality.")
from .geometry import transform

try:
from shapely.geometry import (MultiPoint, Point, Polygon, box,
GeometryCollection)
from shapely.strtree import STRtree
from shapely.affinity import translate, rotate
except ModuleNotFoundError:
print("Shapely is needed for grid intersect operations!"
"Please install shapely.")
print("Shapely is needed for grid intersect operations! Please install " +
"shapely if you need to use grid intersect functionality.")


def parse_shapely_ix_result(collection, ix_result, shptyps=None):
"""Recursive function for parsing shapely intersection results.
"""
Recursive function for parsing shapely intersection results.
Returns a list of shapely shapes matching shptyp
Parameters
Expand Down Expand Up @@ -209,8 +217,10 @@ def _sort_strtree_result(shapelist):
sorted list of Polygons
"""

def sort_key(o):
return o.name

shapelist.sort(key=sort_key)
return shapelist

Expand Down Expand Up @@ -1041,8 +1051,15 @@ def plot_polygon(rec, ax=None, **kwargs):
try:
from descartes import PolygonPatch
except ModuleNotFoundError:
raise ModuleNotFoundError(
"descartes module needed for plotting polygons")
msg = 'descartes package needed for plotting polygons'
if plt is None:
msg = 'matplotlib and descartes packages needed for ' + \
'plotting polygons'
raise ModuleNotFoundError(msg)

if plt is None:
msg = 'matplotlib package needed for plotting polygons'
raise ModuleNotFoundError(msg)

if ax is None:
_, ax = plt.subplots()
Expand Down Expand Up @@ -1077,6 +1094,10 @@ def plot_linestring(rec, ax=None, **kwargs):
returns the axes handle
"""
if plt is None:
msg = 'matplotlib package needed for plotting polygons'
raise ModuleNotFoundError(msg)

if ax is None:
_, ax = plt.subplots()

Expand Down Expand Up @@ -1114,6 +1135,10 @@ def plot_point(rec, ax=None, **kwargs):
returns the axes handle
"""
if plt is None:
msg = 'matplotlib package needed for plotting polygons'
raise ModuleNotFoundError(msg)

if ax is None:
_, ax = plt.subplots()

Expand Down
23 changes: 22 additions & 1 deletion flopy/version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
# flopy version file automatically created using...make-release.py
# created on...December 15, 2019 09:55:43
# created on...May 26, 2020 17:16:58

major = 3
minor = 3
micro = 1
__version__ = '{:d}.{:d}.{:d}'.format(major, minor, micro)

__pakname__ = 'flopy'

# edit author dictionary as necessary
author_dict = {
'Mark Bakker': 'mark.bakker@tudelft.nl',
'Vincent Post': 'Vincent.Post@bgr.de',
'Christian D. Langevin': 'langevin@usgs.gov',
'Joseph D. Hughes': 'jdhughes@usgs.gov',
'Jeremy T. White': 'jwhite@usgs.gov',
'Andrew T. Leaf': 'aleaf@usgs.gov',
'Scott R. Paulinski': 'spaulinski@usgs.gov',
'Joshua D. Larsen': 'jlarsen@usgs.gov',
'Michael W. Toews': 'M.Toews@gns.cri.nz',
'Eric D. Morway': 'emorway@usgs.gov',
'Jason C. Bellino': 'jbellino@usgs.gov',
'Jeffrey Starn': 'jjstarn@usgs.gov',
'Michael N. Fienen': 'mnfienen@usgs.gov',
}
__author__ = ', '.join(author_dict.keys())
__author_email__ = ', '.join(s for _, s in author_dict.items())
11 changes: 10 additions & 1 deletion release/make-release.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,25 @@ def get_software_citation(version, is_approved):


def update_version():
name_pos = None
try:
fpth = os.path.join(paths[0], files[0])

vmajor = 0
vminor = 0
vmicro = 0
lines = [line.rstrip('\n') for line in open(fpth, 'r')]
for line in lines:
for idx, line in enumerate(lines):
t = line.split()
if 'major =' in line:
vmajor = int(t[2])
elif 'minor =' in line:
vminor = int(t[2])
elif 'micro =' in line:
vmicro = int(t[2])
elif '__version__' in line:
name_pos = idx + 1

except:
msg = 'There was a problem updating the version file'
raise IOError(msg)
Expand All @@ -184,6 +188,11 @@ def update_version():
f.write('minor = {}\n'.format(vminor))
f.write('micro = {}\n'.format(vmicro))
f.write("__version__ = '{:d}.{:d}.{:d}'.format(major, minor, micro)\n")

# write the remainder of the version file
if name_pos is not None:
for line in lines[name_pos:]:
f.write('{}\n'.format(line))
f.close()
print('Successfully updated version.py')
except:
Expand Down
17 changes: 7 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
import sys
from setuptools import setup

from flopy import __version__, __name__, __author__

# ensure minimum version of Python is running
if sys.version_info[0:2] < (3, 5):
raise RuntimeError('Flopy requires Python >= 3.5')

# local import of package variables in flopy/version.py
sys.path.append('flopy')
from version import __version__, __pakname__, __author__, __author_email__
print(__version__, __pakname__, __author__, __author_email__)

try:
import pypandoc

Expand All @@ -16,18 +19,12 @@
except ImportError:
long_description = ''

setup(name=__name__,
setup(name=__pakname__,
description='FloPy is a Python package to create, run, and ' +
'post-process MODFLOW-based models.',
long_description=long_description,
author=__author__,
author_email='mark.bakker@tudelft.nl, Vincent.Post@bgr.de, ' +
'langevin@usgs.gov, jdhughes@usgs.gov, ' +
'j.white@gns.cri.nz, aleaf@usgs.gov, ' +
'spaulinski@usgs.gov, jlarsen@usgs.gov,' +
'M.Toews@gns.cri.nz, emorway@usgs.gov, ' +
'jbellino@usgs.gov, jjstarn@usgs.gov, ' +
'mnfienen@usgs.gov',
author_email=__author_email__,
url='https://github.com/modflowpy/flopy/',
license='CC0',
platforms='Windows, Mac OS-X, Linux',
Expand Down

0 comments on commit b80a89c

Please sign in to comment.