Skip to content

Commit baa4dea

Browse files
Micah CochranMicah Cochran
authored andcommitted
add package_versions() and option to print info in test.py
package_versions() is a new function that returns a namedtuple of version information of the dependent packages. It should also be useful to see if Travis is running the correct package versions. I made this with Issue #235 in mind. A --verbose option was added to test.py to display this version information. Additionally, this new function could serve a use in debugging future issues.
1 parent 24336eb commit baa4dea

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

.requirements-2.6.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
argparse
12
unittest2
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""
2+
These are diagnostic and debugging functions for basemap.
3+
"""
4+
5+
def package_versions():
6+
"""
7+
Gives version information for dependent packages.
8+
9+
returns namedtuple BasemapPackageVersions
10+
"""
11+
from collections import namedtuple
12+
from sys import version as sys_version
13+
14+
from matplotlib import __version__ as matplotlib_version
15+
from numpy import __version__ as numpy_version
16+
import pyproj
17+
from shapefile import __version__ as pyshp_version
18+
19+
import _geoslib
20+
from mpl_toolkits.basemap import __version__ as basemap_version
21+
22+
# import optional dependencies
23+
try:
24+
from OWSLib import __version__ as OWSLib_version
25+
except ImportError:
26+
OWSLib_version = 'not installed'
27+
28+
try:
29+
from PIL import VERSION as pil_version
30+
try:
31+
from PIL import PILLOW_VERSION as pillow_version
32+
except ImportError:
33+
pillow_verison = 'not installed'
34+
except ImportError:
35+
pil_version = 'not installed'
36+
pillow_verison = 'not installed'
37+
38+
BasemapPackageVersions = namedtuple(
39+
'BasemapPackageVersions',
40+
"""Python, basemap, matplotlib,
41+
numpy, pyproj, pyshp, PROJ4, GEOS,
42+
OWSLib, PIL, Pillow""")
43+
44+
return BasemapPackageVersions(
45+
Python = sys_version,
46+
basemap = basemap_version,
47+
matplotlib = matplotlib_version,
48+
numpy = numpy_version,
49+
pyproj = pyproj.__version__,
50+
pyshp = pyshp_version,
51+
PROJ4 = pyproj.Proj(init='epsg:4326').proj_version,
52+
GEOS = _geoslib.__geos_version__,
53+
# optional dependencies below
54+
OWSLib = OWSLib_version,
55+
PIL = pil_version,
56+
Pillow = pillow_version)

lib/mpl_toolkits/basemap/test.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,5 +206,25 @@ def test():
206206

207207

208208
if __name__ == '__main__':
209+
# When called with the -v / --verbose commandline parameter, it will
210+
# give package dependent version information:
211+
# $ python test.py --verbose
212+
213+
import argparse # standard module in Python >= 2.7 and >= 3.2
209214
import unittest
215+
216+
from mpl_toolkits.basemap.diagnostic import package_versions
217+
218+
parser = argparse.ArgumentParser()
219+
parser.add_argument('-v', '--verbose',action='count')
220+
args = parser.parse_args()
221+
222+
# VERBOSITY will default to None if not a parameter
223+
VERBOSITY = vars(args)['verbose']
224+
if VERBOSITY != None:
225+
pkg_vers = package_versions()
226+
print('Basemaps installed package versions:')
227+
print('{}\n'.format(pkg_vers))
228+
210229
unittest.main()
230+

0 commit comments

Comments
 (0)