Skip to content

Commit

Permalink
update for new ruff rules
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedh committed Nov 26, 2024
1 parent 9581c1f commit 17672f2
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 24 deletions.
6 changes: 3 additions & 3 deletions trimesh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@


__all__ = [
"PointCloud",
"Geometry",
"Trimesh",
"PointCloud",
"Scene",
"Trimesh",
"Trimesh",
"__version__",
"available_formats",
"boolean",
Expand All @@ -103,8 +103,8 @@
"graph",
"grouping",
"inertia",
"iteration",
"intersections",
"iteration",
"load",
"load_mesh",
"load_path",
Expand Down
8 changes: 5 additions & 3 deletions trimesh/exchange/binvox.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ def voxel_from_binvox(rle_data, shape, translate=None, scale=1.0, axis_order="xz
elif axis_order is None or axis_order == "xyz":
encoding = encoding.reshape(shape)
else:
raise ValueError("Invalid axis_order '%s': must be None, 'xyz' or 'xzy'")
raise ValueError(
"Invalid axis_order '%s': must be None, 'xyz' or 'xzy'", axis_order
)

assert encoding.shape == shape

Expand Down Expand Up @@ -423,7 +425,7 @@ def __init__(
)

if dimension > 1024 and not exact:
raise ValueError("Maximum dimension using exact is 1024, got %d" % dimension)
raise ValueError("Maximum dimension using exact is 1024, got %d", dimension)
if file_type not in Binvoxer.SUPPORTED_OUTPUT_TYPES:
raise ValueError(
f"file_type {file_type} not in set of supported output types {Binvoxer.SUPPORTED_OUTPUT_TYPES!s}"
Expand Down Expand Up @@ -471,7 +473,7 @@ def __init__(
times = np.log2(downsample_factor)
if int(times) != times:
raise ValueError(
"downsample_factor must be a power of 2, got %d" % downsample_factor
"downsample_factor must be a power of 2, got %d", downsample_factor
)
args.extend(("-down",) * int(times))
if downsample_threshold is not None:
Expand Down
4 changes: 2 additions & 2 deletions trimesh/exchange/gltf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,14 +1029,14 @@ def _build_accessor(array):
if vec_length > 4:
raise ValueError("The GLTF spec does not support vectors larger than 4")
if vec_length > 1:
data_type = "VEC%d" % vec_length
data_type = f"VEC{int(vec_length)}"
else:
data_type = "SCALAR"

if len(shape) == 3:
if shape[2] not in [2, 3, 4]:
raise ValueError("Matrix types must have 4, 9 or 16 components")
data_type = "MAT%d" % shape[2]
data_type = f"MAT{int(shape[2])}"

# get the array data type as a str stripping off endian
lookup = array.dtype.str.lstrip("<>")
Expand Down
2 changes: 1 addition & 1 deletion trimesh/interfaces/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import blender, gmsh

# add to __all__ as per pep8
__all__ = ["gmsh", "blender"]
__all__ = ["blender", "gmsh"]
8 changes: 4 additions & 4 deletions trimesh/typed.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,21 @@
"Any",
"ArrayLike",
"BinaryIO",
"Callable",
"Dict",
"Hashable",
"Integer",
"Iterable",
"List",
"Loadable",
"Mapping",
"NDArray",
"Number",
"Optional",
"Sequence",
"Set",
"Stream",
"Tuple",
"float64",
"int64",
"Mapping",
"Callable",
"Hashable",
"Set",
]
19 changes: 12 additions & 7 deletions trimesh/voxel/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,17 +768,20 @@ def __init__(self, encoding, shape):
size = np.abs(size)
if self._data.size % size != 0:
raise ValueError(
"cannot reshape encoding of size %d into shape %s"
% (self._data.size, str(self._shape))
"cannot reshape encoding of size %d into shape %s",
self._data.size,
str(self._shape),
)

rem = self._data.size // size
self._shape = tuple(rem if s == -1 else s for s in self._shape)
elif nn > 2:
raise ValueError("shape cannot have more than one -1 value")
elif np.prod(self._shape) != self._data.size:
raise ValueError(
"cannot reshape encoding of size %d into shape %s"
% (self._data.size, str(self._shape))
"cannot reshape encoding of size %d into shape %s",
self._data.size,
str(self._shape),
)

def _from_base_indices(self, base_indices):
Expand Down Expand Up @@ -818,9 +821,11 @@ def __init__(self, base_encoding, perm):
raise ValueError(f"base_encoding must be an Encoding, got {base_encoding!s}")
if len(base_encoding.shape) != len(perm):
raise ValueError(
"base_encoding has %d ndims - cannot transpose with perm %s"
% (base_encoding.ndims, str(perm))
"base_encoding has %d ndims - cannot transpose with perm %s",
base_encoding.ndims,
str(perm),
)

super().__init__(base_encoding)
perm = np.array(perm, dtype=np.int64)
if not all(i in perm for i in range(base_encoding.ndims)):
Expand Down Expand Up @@ -898,7 +903,7 @@ def __init__(self, encoding, axes):
super().__init__(encoding)
if not all(0 <= a < self._data.ndims for a in axes):
raise ValueError(
"Invalid axes %s for %d-d encoding" % (str(axes), self._data.ndims)
"Invalid axes %s for %d-d encoding", str(axes), self._data.ndims
)

def _to_base_indices(self, indices):
Expand Down
4 changes: 2 additions & 2 deletions trimesh/voxel/morphology.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _sparse_indices(encoding, rank=None):

def _assert_rank(value, rank):
if len(value.shape) != rank:
raise ValueError("Expected rank %d, got shape %s" % (rank, str(value.shape)))
raise ValueError("Expected rank %d, got shape %s", rank, str(value.shape))


def _assert_sparse_rank(value, rank=None):
Expand All @@ -51,7 +51,7 @@ def _assert_sparse_rank(value, rank=None):
if rank is not None:
if value.shape[-1] != rank:
raise ValueError(
"sparse_indices.shape[1] must be %d, got %d" % (rank, value.shape[-1])
"sparse_indices.shape[1] must be %d, got %d", rank, value.shape[-1]
)


Expand Down
6 changes: 4 additions & 2 deletions trimesh/voxel/runlength.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,9 @@ def sorted_rle_gather_1d(rle_data, ordered_indices):
start += next(data_iter)
except StopIteration:
raise IndexError(
"Index %d out of range of raw_values length %d" % (index, start)
"Index %d out of range of raw_values length %d", index, start
)

try:
while index < start:
yield value
Expand Down Expand Up @@ -533,8 +534,9 @@ def sorted_brle_gather_1d(brle_data, ordered_indices):
start += next(data_iter)
except StopIteration:
raise IndexError(
"Index %d out of range of raw_values length %d" % (index, start)
"Index %d out of range of raw_values length %d", index, start
)

try:
while index < start:
yield value
Expand Down

0 comments on commit 17672f2

Please sign in to comment.