diff --git a/CHANGELOG.md b/CHANGELOG.md index e912cd4..722259f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ This document highlights high-level changes made to this program. + Formatted code with `black`. + Removed `__future__` imports now that we no longer support Python 2; reorder and fix imports to not use `.` notation. Removed encoding pragma. ++ Addressed some lint issues; removed Py2 `xrange` hack. ## 1.1.2 / 2019-10-14 diff --git a/README.md b/README.md index cf458d5..fa082dc 100644 --- a/README.md +++ b/README.md @@ -85,28 +85,31 @@ The easiest way to use this to to: 0. Import the `wm_app` module: - ```python + ```pycon >>> import wm_app ``` 1. Set up your data as a list of (grid_x, grid_y, value) tuples: - ```python - >>> data = [(grid_x_1, grid_y_1, data_1), # 1st die - ... (grid_x_2, grid_y_2, data_2), # 2nd die - ... (grid_x_3, grid_y_3, data_3) # 3rd die and so on - ... ] + ```pycon + >>> data = [ + ... (grid_x_1, grid_y_1, data_1), # 1st die + ... (grid_x_2, grid_y_2, data_2), # 2nd die + ... (grid_x_3, grid_y_3, data_3), # 3rd die and so on + ... ] ``` 2. Call `wm_app.WaferMapApp`. - ```python - >>> wm_app.WaferMapApp(data, - ... die_size, - ... center_xy, - ... dia, - ... edge_excl, - ... flat_excl) + ```pycon + >>> wm_app.WaferMapApp( + ... data, + ... die_size, + ... center_xy, + ... dia, + ... edge_excl, + ... flat_excl, + ... ) ``` The input parameters for WaferMapApp are: diff --git a/src/wafer_map/__init__.py b/src/wafer_map/__init__.py index 2aa8edb..d4e65b1 100644 --- a/src/wafer_map/__init__.py +++ b/src/wafer_map/__init__.py @@ -4,7 +4,6 @@ Determines the python version and monkeypatches wx.Colour. """ import os -import sys ### Constants ############################################################### @@ -12,14 +11,6 @@ # 'wm_legend', 'wm_utils'] -if sys.version_info < (3,): - PY2 = True -elif sys.version_info < (2, 6): - raise RuntimeError("Only Python >= 2.7 is supported.") -else: - PY2 = False - - # if we're building docs, don't try and import or monkeypatch wxPython. if os.getenv("READTHEDOCS", "False") == "True": pass diff --git a/src/wafer_map/gen_fake_data.py b/src/wafer_map/gen_fake_data.py index d65ccbe..04cc94d 100644 --- a/src/wafer_map/gen_fake_data.py +++ b/src/wafer_map/gen_fake_data.py @@ -7,17 +7,11 @@ import math import random -from wafer_map import PY2 from wafer_map import wm_constants as wm_const from wafer_map import wm_info from wafer_map import wm_utils -# Python2 Compatibility -if PY2: - range = xrange - - def generate_fake_data(**kwargs): """ Generate fake data for wafer_map. diff --git a/src/wafer_map/wm_core.py b/src/wafer_map/wm_core.py index e63b745..ab4f847 100644 --- a/src/wafer_map/wm_core.py +++ b/src/wafer_map/wm_core.py @@ -796,7 +796,7 @@ def draw_die_gridlines(wf): line_coords = list([(x, -edge), (x, edge)] for x in x_values) line_coords.extend([(-edge, y), (edge, y)] for y in y_values) - lines = [FloatCanvas.Line(l, LineColor=grey) for l in line_coords] + lines = [FloatCanvas.Line(_line, LineColor=grey) for _line in line_coords] return FloatCanvas.Group(list(lines)) diff --git a/src/wafer_map/wm_legend.py b/src/wafer_map/wm_legend.py index 6570e59..91b2ea4 100644 --- a/src/wafer_map/wm_legend.py +++ b/src/wafer_map/wm_legend.py @@ -8,16 +8,11 @@ import wx.lib.colourselect as csel from wx.lib.floatcanvas import FloatCanvas -from wafer_map import PY2 from wafer_map import wm_constants as wm_const from wafer_map import wm_utils # TODO: Update to Bezier Curves for colors. See http://bsou.io/p/3 -# Python2 Compatibility -if PY2: - range = xrange - class Legend(object): """ diff --git a/src/wafer_map/wm_utils.py b/src/wafer_map/wm_utils.py index de25b7c..62f9f40 100644 --- a/src/wafer_map/wm_utils.py +++ b/src/wafer_map/wm_utils.py @@ -4,13 +4,6 @@ import numpy as np from colour import Color -from wafer_map import PY2 - - -# Python2 Compatibility -if PY2: - range = xrange - class Gradient(object): """ @@ -196,12 +189,12 @@ def linear_gradient(initial_color, dest_color, value): h2, s2, l2 = c2.hsl # Perform the linear interpolation - h = rescale(value, (0, 1), (h1, h2)) - s = rescale(value, (0, 1), (s1, s2)) - l = rescale(value, (0, 1), (l1, l2)) + hue = rescale(value, (0, 1), (h1, h2)) + saturation = rescale(value, (0, 1), (s1, s2)) + lightness = rescale(value, (0, 1), (l1, l2)) # Convert back to 0-255 for wxPython - r, g, b = (int(_c * 255) for _c in Color(hsl=(h, s, l)).rgb) + r, g, b = (int(_c * 255) for _c in Color(hsl=(hue, saturation, lightness)).rgb) return (r, g, b) @@ -215,8 +208,8 @@ def polylinear_gradient(colors, value): Value is the 0-1 value between colors[0] and colors[-1]. Assumes uniform spacing between all colors. """ - n = len(colors) - if n == 2: + num_colors = len(colors) + if num_colors == 2: return linear_gradient(colors[0], colors[1], value) if value >= 1: @@ -225,18 +218,18 @@ def polylinear_gradient(colors, value): return colors[0] # divide up our range into n - 1 segments, where n is the number of colors - l = 1 / (n - 1) # float division + segment_size = 1 / (num_colors - 1) # float division # figure out which segment we're in - determines start and end colors - m = int(value // l) # Note floor division + segment = int(value // segment_size) # Note floor division - low = m * l - high = (m + 1) * l + low = segment * segment_size + high = (segment + 1) * segment_size # calculate where our value lies within that particular gradient v2 = rescale(value, (low, high), (0, 1)) - return linear_gradient(colors[m], colors[m + 1], v2) + return linear_gradient(colors[segment], colors[segment + 1], v2) def beizer_gradient(initial_color, arc_color, dest_color, value):