diff --git a/examples/example.py b/examples/example.py index 8b0c4ef..588dabe 100644 --- a/examples/example.py +++ b/examples/example.py @@ -5,6 +5,6 @@ pts = [] for x in range(400): pts.append((random.random(), random.random())) - print "Processing %d points..." % len(pts) + print("Processing %d points..." % len(pts)) hm = heatmap.Heatmap() img = hm.heatmap(pts).save("classic.png") diff --git a/heatmap/__init__.py b/heatmap/__init__.py index da77f06..10fd00a 100644 --- a/heatmap/__init__.py +++ b/heatmap/__init__.py @@ -1,6 +1,6 @@ try: __version__ = __import__('pkg_resources').get_distribution(__name__).version -except Exception, e: +except Exception as e: __version__ = 'unknown' -from heatmap import Heatmap \ No newline at end of file +from .heatmap import Heatmap diff --git a/heatmap/heatmap.py b/heatmap/heatmap.py index 173e5cc..0a39beb 100644 --- a/heatmap/heatmap.py +++ b/heatmap/heatmap.py @@ -2,9 +2,9 @@ import sys import ctypes import platform -import math +import glob -import colorschemes +from .colorschemes import schemes, valid_schemes from PIL import Image @@ -65,12 +65,21 @@ def __init__(self, libpath=None): libname = "cHeatmap-x86.dll" if "64" in platform.architecture()[0]: libname = "cHeatmap-x64.dll" + + # to support multiple Python versions + libname_search_string = '*'.join(libname.split('.')) + # now rip through everything in sys.path to find 'em. Should be in site-packages # or local dir for d in sys.path: - if os.path.isfile(os.path.join(d, libname)): - self._heatmap = ctypes.cdll.LoadLibrary( - os.path.join(d, libname)) + # search for matching file names + for f in glob.glob(os.path.join(d, libname_search_string)): + self._heatmap = ctypes.cdll.LoadLibrary(f) + + break + + if self._heatmap is not None: + break if not self._heatmap: raise Exception("Heatmap shared library not found in PYTHONPATH.") @@ -122,7 +131,7 @@ def heatmap(self, points, dotsize=150, opacity=128, size=(1024, 1024), scheme="c if not ret: raise Exception("Unexpected error during processing.") - self.img = Image.frombuffer('RGBA', (self.size[0], self.size[1]), + self.img = Image.frombuffer('RGBA', (self.size[0], self.size[1]), arrFinalImage, 'raw', 'RGBA', 0, 1) return self.img @@ -146,12 +155,12 @@ def _convertScheme(self, scheme): #TODO is there a better way to do this?? flat = [] - for r, g, b in colorschemes.schemes[scheme]: + for r, g, b in schemes[scheme]: flat.append(r) flat.append(g) flat.append(b) arr_cs = ( - ctypes.c_int * (len(colorschemes.schemes[scheme]) * 3))(*flat) + ctypes.c_int * (len(schemes[scheme]) * 3))(*flat) return arr_cs def _ranges(self, points): @@ -189,10 +198,12 @@ def saveKML(self, kmlFile): ((east, south), (west, north)) = self._ranges(self.points) bytes = self.KML % (tilePath, north, south, east, west) - file(kmlFile, "w").write(bytes) + + with open(kmlFile, 'w') as f: + f.write(bytes) def schemes(self): """ Return a list of available color scheme names. """ - return colorschemes.valid_schemes() + return valid_schemes() diff --git a/setup.py b/setup.py index 4ed87d7..7dba1a4 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ class mybuild(build_ext): def run(self): if "nt" in os.name: - print "On Windows, skipping build_ext." + print("On Windows, skipping build_ext.") return build_ext.run(self)