Skip to content

Commit c8aeba4

Browse files
committed
Merge pull request #243 from micahcochran/add_pkg_vers
Add package_versions() and option to print ver. info in test.py
2 parents f8252e5 + 2c9c8ed commit c8aeba4

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ install:
4646
- python setup.py install
4747

4848
script:
49-
- python lib/mpl_toolkits/basemap/test.py
49+
- python lib/mpl_toolkits/basemap/test.py --verbose
5050

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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_version = 'not installed'
34+
except ImportError:
35+
pil_version = 'not installed'
36+
pillow_version = 'not installed'
37+
38+
# Get PROJ.4 version info in a floating point number
39+
proj_ver_num = pyproj.Proj(init='epsg:4326').proj_version
40+
# reformats floating point number into string (4.90 becomes '4.9.0')
41+
proj4_version = '.'.join(list(str(int(proj_ver_num*100))))
42+
43+
BasemapPackageVersions = namedtuple(
44+
'BasemapPackageVersions',
45+
"""Python, basemap, matplotlib,
46+
numpy, pyproj, pyshp, PROJ4, GEOS,
47+
OWSLib, PIL, Pillow""")
48+
49+
return BasemapPackageVersions(
50+
Python = sys_version,
51+
basemap = basemap_version,
52+
matplotlib = matplotlib_version,
53+
numpy = numpy_version,
54+
pyproj = pyproj.__version__,
55+
pyshp = pyshp_version,
56+
PROJ4 = proj4_version,
57+
GEOS = _geoslib.__geos_version__,
58+
# optional dependencies below
59+
OWSLib = OWSLib_version,
60+
PIL = pil_version,
61+
Pillow = pillow_version)

lib/mpl_toolkits/basemap/test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,5 +206,19 @@ 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 sys
209214
import unittest
215+
216+
from mpl_toolkits.basemap.diagnostic import package_versions
217+
218+
if '--verbose' in sys.argv or '-v' in sys.argv:
219+
pkg_vers = package_versions()
220+
print('Basemaps installed package versions:')
221+
print('{0}\n'.format(pkg_vers))
222+
210223
unittest.main()
224+

0 commit comments

Comments
 (0)