From 3e4e6eead3bfe5af7a2cbe3ec892a315c6cc4d8e Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Thu, 18 Jul 2024 00:17:45 -0700 Subject: [PATCH] flake8 fixup --- .flake8 | 29 +++++++++++++++++++++++++++++ gridlock/draw.py | 14 +++++++------- gridlock/grid.py | 1 - gridlock/position.py | 2 +- gridlock/read.py | 2 +- 5 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..0042015 --- /dev/null +++ b/.flake8 @@ -0,0 +1,29 @@ +[flake8] +ignore = + # E501 line too long + E501, + # W391 newlines at EOF + W391, + # E241 multiple spaces after comma + E241, + # E302 expected 2 newlines + E302, + # W503 line break before binary operator (to be deprecated) + W503, + # E265 block comment should start with '# ' + E265, + # E123 closing bracket does not match indentation of opening bracket's line + E123, + # E124 closing bracket does not match visual indentation + E124, + # E221 multiple spaces before operator + E221, + # E201 whitespace after '[' + E201, + # E741 ambiguous variable name 'I' + E741, + + +per-file-ignores = + # F401 import without use + */__init__.py: F401, diff --git a/gridlock/draw.py b/gridlock/draw.py index 2322a66..75eccc6 100644 --- a/gridlock/draw.py +++ b/gridlock/draw.py @@ -59,7 +59,7 @@ def draw_polygons( for i, polygon in enumerate(polygons): malformed = f'Malformed polygon: ({i})' if polygon.shape[1] not in (2, 3): - raise GridError(malformed + 'must be a Nx2 or Nx3 ndarray') + raise GridError(malformed + 'must be a Nx2 or Nx3 ndarray') if polygon.shape[1] == 3: polygon = polygon[surface, :] @@ -72,7 +72,7 @@ def draw_polygons( # Broadcast foreground where necessary foregrounds: Sequence[foreground_callable_t] | Sequence[float] if numpy.size(foreground) == 1: # type: ignore - foregrounds = [foreground] * len(cell_data) # type: ignore + foregrounds = [foreground] * len(cell_data) # type: ignore elif isinstance(foreground, numpy.ndarray): raise GridError('ndarray not supported for foreground') else: @@ -113,7 +113,7 @@ def draw_polygons( foregrounds_i = foregrounds[i] if callable(foregrounds_i): # meshgrid over the (shifted) domain - domain = [self.shifted_xyz(i)[k][bdi_min[k]:bdi_max[k]+1] for k in range(3)] + domain = [self.shifted_xyz(i)[k][bdi_min[k]:bdi_max[k] + 1] for k in range(3)] (x0, y0, z0) = numpy.meshgrid(*domain, indexing='ij') # evaluate on the meshgrid @@ -319,7 +319,7 @@ def draw_cylinder( num_points: The circle is approximated by a polygon with `num_points` vertices foreground: Value to draw with ('brush color'). See `draw_polygons()` for details. """ - theta = numpy.linspace(0, 2*numpy.pi, num_points, endpoint=False) + theta = numpy.linspace(0, 2 * numpy.pi, num_points, endpoint=False) x = radius * numpy.sin(theta) y = radius * numpy.cos(theta) polygon = numpy.hstack((x[:, None], y[:, None])) @@ -360,8 +360,8 @@ def draw_extrude_rectangle( surface = numpy.delete(range(3), direction) dim = numpy.fabs(numpy.diff(rectangle, axis=0).T)[surface] - p = numpy.vstack((numpy.array([-1, -1, 1, 1], dtype=float) * dim[0]/2.0, - numpy.array([-1, 1, 1, -1], dtype=float) * dim[1]/2.0)).T + p = numpy.vstack((numpy.array([-1, -1, 1, 1], dtype=float) * dim[0] * 0.5, + numpy.array([-1, 1, 1, -1], dtype=float) * dim[1] * 0.5)).T thickness = distance foreground_func = [] @@ -371,7 +371,7 @@ def draw_extrude_rectangle( ind = [int(numpy.floor(z)) if i == direction else slice(None) for i in range(3)] fpart = z - numpy.floor(z) - mult = [1-fpart, fpart][::s] # reverses if s negative + mult = [1 - fpart, fpart][::s] # reverses if s negative foreground = mult[0] * grid[tuple(ind)] ind[direction] += 1 # type: ignore #(known safe) diff --git a/gridlock/grid.py b/gridlock/grid.py index 36e0608..d8e9653 100644 --- a/gridlock/grid.py +++ b/gridlock/grid.py @@ -2,7 +2,6 @@ from typing import Callable, Sequence, ClassVar, Self import numpy from numpy.typing import NDArray, ArrayLike -from numpy import diff, floor, ceil, zeros, hstack, newaxis import pickle import warnings diff --git a/gridlock/position.py b/gridlock/position.py index b674716..5928174 100644 --- a/gridlock/position.py +++ b/gridlock/position.py @@ -99,7 +99,7 @@ def pos2ind( grid_pos = numpy.zeros((3,)) for a in range(3): - xi = numpy.digitize(r[a], sexyz[a]) - 1 # Figure out which cell we're in + xi = numpy.digitize(r[a], sexyz[a]) - 1 # Figure out which cell we're in xi_clipped = numpy.clip(xi, 0, sexyz[a].size - 2) # Clip back into grid bounds # No need to interpolate if round_ind is true or we were outside the grid diff --git a/gridlock/read.py b/gridlock/read.py index 8ea4b50..bbd4f39 100644 --- a/gridlock/read.py +++ b/gridlock/read.py @@ -4,7 +4,7 @@ Readback and visualization methods for Grid class from typing import Any, TYPE_CHECKING import numpy -from numpy.typing import NDArray, ArrayLike +from numpy.typing import NDArray from . import GridError