Skip to content

Commit

Permalink
Merge pull request #2197 from mikedh/release/fstring
Browse files Browse the repository at this point in the history
Release: fstring
  • Loading branch information
mikedh authored Mar 29, 2024
2 parents 563690a + c512b2f commit f00f271
Show file tree
Hide file tree
Showing 48 changed files with 116 additions and 108 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
run: |
pip install ruff
- name: Check Formatting
run: ruff .
run: ruff check .
tests:
name: Run Unit Tests
needs: formatting
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ jobs:
with:
python-version: "3.11"
- name: Install
run: pip install ruff black
run: pip install ruff
- name: Run Ruff
run: ruff .
# - name: Run Black
# run: black --check .
run: ruff check .

tests:
name: Run Unit Tests
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ requires = ["setuptools >= 61.0", "wheel"]
[project]
name = "trimesh"
requires-python = ">=3.7"
version = "4.2.2"
version = "4.2.3"
authors = [{name = "Michael Dawson-Haggerty", email = "[email protected]"}]
license = {file = "LICENSE.md"}
description = "Import, export, process, analyze and view triangular meshes."
Expand Down Expand Up @@ -129,7 +129,7 @@ select = [
"E", # style errors
"F", # flakes
"I", # import sorting
"RUF100", # meta
"RUF", # ruff specific rules
"UP", # upgrade
"W", # style warnings
"YTT", # sys.version
Expand All @@ -143,6 +143,7 @@ ignore = [
"E501", # Line too long ({width} > {limit} characters)
"B904", # raise ... from err
"B905", # zip() without an explicit strict= parameter
"RUF005", # recommends non-type-aware expansion
]

# don't allow implicit string concatenation
Expand Down
4 changes: 2 additions & 2 deletions tests/test_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_align(self):
unitized = g.trimesh.unitize(vectors)
for unit_dest, dest in zip(unitized[-10:], vectors[-10:]):
for unit, vector in zip(unitized, vectors):
T, a = align(vector, dest, return_angle=True)
T, _a = align(vector, dest, return_angle=True)
assert is_rigid(T)
assert g.np.isclose(g.np.linalg.det(T), 1.0)
# rotate vector with transform
Expand Down Expand Up @@ -97,7 +97,7 @@ def test_rigid(self):

vector_1 = g.np.array([7.12106798e-07, -7.43194705e-08, 1.00000000e00])
vector_2 = g.np.array([0, 0, -1])
T, angle = align(vector_1, vector_2, return_angle=True)
T, _angle = align(vector_1, vector_2, return_angle=True)
assert g.np.isclose(g.np.linalg.det(T), 1.0)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def test_triangulate(self):
)
except BaseException:
g.log.error("failed to benchmark triangle", exc_info=True)
g.log.info(f"benchmarked triangulation on {len(bench)} polygons: {str(times)}")
g.log.info(f"benchmarked triangulation on {len(bench)} polygons: {times!s}")

def test_triangulate_plumbing(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def test_parse_file_args(self):

def test_buffered_random(self):
"""Test writing to non-standard file"""
mesh = list(g.get_meshes(1))[0]
mesh = next(iter(g.get_meshes(1)))
with io.BufferedRandom(io.BytesIO()) as rw:
mesh.export(rw, "STL")
rw.seek(0)
Expand Down
14 changes: 8 additions & 6 deletions tests/test_gltf.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def to_integer(args):
)
assert len(reloaded.geometry) == 1
# get meshes back
sphere_b = list(reloaded.geometry.values())[0]
sphere_b = next(iter(reloaded.geometry.values()))
assert (sphere_b.visual.material.baseColorFactor == (255, 0, 0, 255)).all()

def test_material_hash(self):
Expand Down Expand Up @@ -1047,11 +1047,13 @@ def test_unitize_normals_null_values(self):

# Export the mesh
export = mesh.export(file_type="glb", unitize_normals=True)
reimported_mesh = list(
g.trimesh.load(
g.trimesh.util.wrap_as_stream(export), file_type="glb"
).geometry.values()
)[0]
reimported_mesh = next(
iter(
g.trimesh.load(
g.trimesh.util.wrap_as_stream(export), file_type="glb"
).geometry.values()
)
)

# Check that the normals are still null
assert g.np.allclose(reimported_mesh.vertex_normals[0], [0, 0, 0])
Expand Down
6 changes: 3 additions & 3 deletions tests/test_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_obj_simple_order(self):
m = g.trimesh.load(file_name, process=False)
# use trivial loading to compare with fancy performant one
with open(file_name) as f:
f, v, vt = simple_load(f.read())
f, v, _vt = simple_load(f.read())
# trimesh loader should return the same face order
assert g.np.allclose(f, m.faces)
assert g.np.allclose(v, m.vertices)
Expand All @@ -123,7 +123,7 @@ def test_order_tex(self):
m = g.trimesh.load(file_name, process=False, maintain_order=True)
# use trivial loading to compare with fancy performant one
with open(file_name) as f:
f, v, vt = simple_load(f.read())
f, v, _vt = simple_load(f.read())
# trimesh loader should return the same face order
assert g.np.allclose(f, m.faces)
assert g.np.allclose(v, m.vertices)
Expand Down Expand Up @@ -448,7 +448,7 @@ def test_export_normals(self):
def test_export_mtl_args(self):
mesh = g.trimesh.creation.box()
# check for a crash with no materials defined
a, b = g.trimesh.exchange.obj.export_obj(
_a, _b = g.trimesh.exchange.obj.export_obj(
mesh, return_texture=True, mtl_name="hi.mtl"
)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_packing.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_obb(self):
from trimesh.path import packing

nestable = [g.Polygon(i) for i in g.data["nestable"]]
inserted, transforms = packing.polygons(nestable)
_inserted, _transforms = packing.polygons(nestable)

def test_image(self):
from trimesh.path import packing
Expand Down Expand Up @@ -157,11 +157,11 @@ def test_3D(self):
)

# try packing these 3D boxes
bounds, consume = packing.rectangles_single(e)
_bounds, consume = packing.rectangles_single(e)
assert consume.all()

# try packing these 3D boxes
bounds, consume = packing.rectangles_single(e, size=[14, 14, 1])
_bounds, consume = packing.rectangles_single(e, size=[14, 14, 1])
assert not consume.all()

def test_transform(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def test_section(self):
)

# Path3D -> Path2D
planar, T = section.to_planar()
planar, _T = section.to_planar()

# tube should have one closed polygon
assert len(planar.polygons_full) == 1
Expand Down
4 changes: 2 additions & 2 deletions tests/test_permutate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def make_assertions(mesh, test, rigid=False):
close(test.face_adjacency, mesh.face_adjacency)
and len(mesh.faces) > MIN_FACES
):
g.log.error(f"face_adjacency unchanged: {str(test.face_adjacency)}")
g.log.error(f"face_adjacency unchanged: {test.face_adjacency!s}")
raise ValueError(
"face adjacency of %s the same after permutation!",
mesh.metadata["file_name"],
Expand All @@ -33,7 +33,7 @@ def make_assertions(mesh, test, rigid=False):
and len(mesh.faces) > MIN_FACES
):
g.log.error(
f"face_adjacency_edges unchanged: {str(test.face_adjacency_edges)}"
f"face_adjacency_edges unchanged: {test.face_adjacency_edges!s}"
)
raise ValueError(
"face adjacency edges of %s the same after permutation!",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_plane(self):
# so the true normal should be Z then rotated
truth = g.trimesh.transform_points([[0, 0, 1]], matrix, translate=False)[0]
# run the plane fit
C, N = g.trimesh.points.plane_fit(p)
_C, N = g.trimesh.points.plane_fit(p)
# sign of normal is arbitrary on fit so check both
assert g.np.allclose(truth, N) or g.np.allclose(truth, -N)
# make sure plane fit works with multiple point sets at once
Expand Down Expand Up @@ -130,7 +130,7 @@ def test_plane(self):
[[0, 0, 1]], matrix, translate=False
)[0]
# run the plane fit
C, N = g.trimesh.points.plane_fit(p)
_C, N = g.trimesh.points.plane_fit(p)

# sign of normal is arbitrary on fit so check both
cosines = g.np.einsum("ij,ij->i", N, truths)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_polygons.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_sample(self):
assert radius < (1.0 + 1e-8)

# try getting OBB of samples
T, extents = g.trimesh.path.polygons.polygon_obb(s)
_T, extents = g.trimesh.path.polygons.polygon_obb(s)
# OBB of samples should be less than diameter of circle
diameter = g.np.reshape(p.bounds, (2, 2)).ptp(axis=0).max()
assert (extents <= diameter).all()
Expand Down Expand Up @@ -260,7 +260,7 @@ def test_native_centroid(self):

for p, c in zip(polygons, coords):
# area will be signed with respect to counter-clockwise
ccw, area, centroid = g.trimesh.util.is_ccw(c, return_all=True)
_ccw, area, centroid = g.trimesh.util.is_ccw(c, return_all=True)
assert g.np.allclose(centroid, g.np.array(p.centroid.coords)[0])
assert g.np.isclose(abs(area), p.area)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_poses.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_multiple(self):
copied.apply_transform(matrix)

# Compute the stable poses of the icosahedron
trans, probs = copied.compute_stable_poses()
_trans, probs = copied.compute_stable_poses()

# we are only testing primitives with point symmetry
# AKA 3 principal components of inertia are the same
Expand All @@ -43,8 +43,8 @@ def test_multiple(self):
def test_round(self):
mesh = g.trimesh.primitives.Cylinder(radius=1.0, height=10.0)

transforms, probabilities = mesh.compute_stable_poses()
transforms, probabilities = mesh.compute_stable_poses(n_samples=10)
_transforms, _probabilities = mesh.compute_stable_poses()
_transforms, _probabilities = mesh.compute_stable_poses(n_samples=10)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions tests/test_proximity.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_naive(self):
triangles = sphere.triangles # NOQA

# do the check
closest, distance, tid = g.trimesh.proximity.closest_point_naive(sphere, points)
closest, distance, _tid = g.trimesh.proximity.closest_point_naive(sphere, points)

# the distance from a sphere of radius 1.0 to a sphere of radius 2.0
# should be pretty darn close to 1.0
Expand Down Expand Up @@ -98,7 +98,7 @@ def points_on_circle(count):
# create a mesh with one triangle
mesh = g.Trimesh(**g.trimesh.triangles.to_kwargs([triangle]))

result, result_distance, result_tid = fun(mesh, query)
result, result_distance, _result_tid = fun(mesh, query)

polygon = g.Polygon(triangle[:, 0:2])
polygon_buffer = polygon.buffer(1e-5)
Expand Down
10 changes: 5 additions & 5 deletions tests/test_ray.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_on_vertex(self):

assert m.ray.intersects_any(ray_origins=origins, ray_directions=vectors).all()

(locations, index_ray, index_tri) = m.ray.intersects_location(
(_locations, index_ray, _index_tri) = m.ray.intersects_location(
ray_origins=origins, ray_directions=vectors
)

Expand Down Expand Up @@ -146,14 +146,14 @@ def test_multiple_hits(self):

# Perform 256 * 256 raycasts, one for each pixel on the image
# plane. We only want the 'first' hit.
index_triangles, index_ray = cube_mesh.ray.intersects_id(
index_triangles, _index_ray = cube_mesh.ray.intersects_id(
ray_origins=ray_origins,
ray_directions=ray_directions,
multiple_hits=False,
)
assert len(g.np.unique(index_triangles)) == 2

index_triangles, index_ray = cube_mesh.ray.intersects_id(
index_triangles, _index_ray = cube_mesh.ray.intersects_id(
ray_origins=ray_origins, ray_directions=ray_directions, multiple_hits=True
)
assert len(g.np.unique(index_triangles)) > 2
Expand Down Expand Up @@ -192,7 +192,7 @@ def test_box(self):
# (n,3) float intersection position in space
# (n,) int, index of original ray
# (m,) int, index of mesh.faces
pos, ray, tri = mesh.ray.intersects_location(
pos, ray, _tri = mesh.ray.intersects_location(
ray_origins=origins, ray_directions=vectors
)

Expand All @@ -218,7 +218,7 @@ def test_broken(self):
for kwargs in [{"use_embree": True}, {"use_embree": False}]:
mesh = g.get_mesh("broken.STL", **kwargs)

locations, index_ray, index_tri = mesh.ray.intersects_location(
locations, _index_ray, _index_tri = mesh.ray.intersects_location(
ray_origins=ray_origins, ray_directions=ray_directions
)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_icp_mesh(self):
m = g.trimesh.creation.box()
X = m.sample(10)
X = X + [0.1, 0.1, 0.1]
matrix, transformed, cost = g.trimesh.registration.icp(X, m, scale=False)
_matrix, _transformed, cost = g.trimesh.registration.icp(X, m, scale=False)
assert cost < 0.01

def test_icp_points(self):
Expand Down Expand Up @@ -157,7 +157,7 @@ def test_mesh(self):
truth = g.trimesh.creation.box(extents=extents)

for a, b in [[truth, scan], [scan, truth]]:
a_to_b, cost = a.register(b)
a_to_b, _cost = a.register(b)

a_check = a.copy()
a_check.apply_transform(a_to_b)
Expand All @@ -172,7 +172,7 @@ def test_mesh(self):
points = g.trimesh.transform_points(
scan.sample(100), matrix=g.trimesh.transformations.random_rotation_matrix()
)
truth_to_points, cost = truth.register(points)
truth_to_points, _cost = truth.register(points)
truth.apply_transform(truth_to_points)
distance = truth.nearest.on_surface(points)[1]

Expand Down
2 changes: 1 addition & 1 deletion tests/test_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_args(self):
assert len(args) == 6
assert len(args_auto) == len(args)

P20, T = P30.to_planar()
P20, _T = P30.to_planar()
args = rendering.path_to_vertexlist(P20)
args_auto = rendering.convert_to_vertexlist(P20)
assert len(args) == 6
Expand Down
8 changes: 4 additions & 4 deletions tests/test_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_sample(self):
distance = m.nearest.signed_distance(samples)
assert g.np.abs(distance).max() < 1e-4

even, index = g.trimesh.sample.sample_surface_even(m, 1000)
even, _index = g.trimesh.sample.sample_surface_even(m, 1000)
# check to make sure all samples are on the mesh surface
distance = m.nearest.signed_distance(even)
assert g.np.abs(distance).max() < 1e-4
Expand All @@ -27,7 +27,7 @@ def test_weights(self):
weights[0] = 1.0

# sample with passed weights
points, fid = m.sample(count=100, return_index=True, face_weight=weights)
_points, fid = m.sample(count=100, return_index=True, face_weight=weights)
# all faces should be on single face
assert (fid == 0).all()

Expand All @@ -42,13 +42,13 @@ def test_color(self):

# sample a textured mesh
m = g.get_mesh("fuze.obj")
points, index, color = g.trimesh.sample.sample_surface(m, 100, sample_color=True)
points, _index, color = g.trimesh.sample.sample_surface(m, 100, sample_color=True)
assert len(points) == len(color)

# sample a color mesh
m = g.get_mesh("machinist.XAML")
assert m.visual.kind == "face"
points, index, color = g.trimesh.sample.sample_surface(m, 100, sample_color=True)
points, _index, color = g.trimesh.sample.sample_surface(m, 100, sample_color=True)
assert len(points) == len(color)

def test_sample_volume(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_section(self):
assert g.np.allclose(section.vertices[:, 2], z)
assert len(section.centroid) == 3

planar, to_3D = section.to_planar()
planar, _to_3D = section.to_planar()
assert planar.is_closed
assert len(planar.polygons_full) > 0
assert len(planar.centroid) == 2
Expand All @@ -72,7 +72,7 @@ def test_section(self):
)

# call the multiplane method directly
lines, faces, T = g.trimesh.intersections.mesh_multiplane(
lines, _faces, _T = g.trimesh.intersections.mesh_multiplane(
mesh=mesh,
plane_origin=[0, 0, 0],
plane_normal=plane_normal,
Expand Down
Loading

0 comments on commit f00f271

Please sign in to comment.