Skip to content

Commit 82466bd

Browse files
authored
Merge pull request #2075 from mikedh/feat/ukey
Release: load_remote to httpx
2 parents 46b6aaf + bd06c65 commit 82466bd

7 files changed

Lines changed: 34 additions & 18 deletions

File tree

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ requires = ["setuptools >= 61.0", "wheel"]
55
[project]
66
name = "trimesh"
77
requires-python = ">=3.7"
8-
version = "4.0.4"
8+
version = "4.0.5"
99
authors = [{name = "Michael Dawson-Haggerty", email = "mikedh@kerfed.com"}]
1010
license = {file = "LICENSE.md"}
1111
description = "Import, export, process, analyze and view triangular meshes."
@@ -73,7 +73,7 @@ easy = [
7373
"shapely",
7474
"xxhash",
7575
"rtree",
76-
"requests",
76+
"httpx",
7777
"scipy",
7878
"embreex",
7979
"pillow",

tests/test_dae.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_duck(self):
2929
assert len(scene.graph.nodes_geometry) == 1
3030

3131
conv = scene.convert_units("inch")
32-
assert conv.units == 'inch'
32+
assert conv.units == "inch"
3333

3434
def test_shoulder(self):
3535
if collada is None:
@@ -40,9 +40,9 @@ def test_shoulder(self):
4040
assert len(scene.geometry) == 3
4141
assert len(scene.graph.nodes_geometry) == 3
4242

43-
assert scene.units != 'mm'
43+
assert scene.units != "mm"
4444
conv = scene.convert_units("mm")
45-
assert conv.units == 'mm'
45+
assert conv.units == "mm"
4646

4747
def test_export(self):
4848
if collada is None:
@@ -67,8 +67,7 @@ def test_obj_roundtrip(self):
6767
assert s.visual.material.baseColorTexture.size == rec.visual.material.image.size
6868

6969
conv = s.convert_units("inch")
70-
assert conv.units == 'inch'
71-
70+
assert conv.units == "inch"
7271

7372
def test_material_round(self):
7473
"""

tests/test_units.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ def test_path(self):
5959
# extents should scale exactly with unit conversion
6060
assert g.np.allclose(p.extents / extents_pre, 25.4, atol=0.01)
6161

62+
def test_keys(self):
63+
units = g.trimesh.units.keys()
64+
assert isinstance(units, set)
65+
assert "in" in units
66+
6267
def test_arbitrary(self):
6368
ac = g.np.allclose
6469
to_inch = g.trimesh.units.to_inch

trimesh/exchange/load.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,12 @@ def load_remote(url, **kwargs):
344344
Loaded result
345345
"""
346346
# import here to keep requirement soft
347-
import requests
347+
import httpx
348348

349349
# download the mesh
350-
response = requests.get(url)
350+
response = httpx.get(url, follow_redirects=True)
351+
response.raise_for_status()
352+
351353
# wrap as file object
352354
file_obj = util.wrap_as_stream(response.content)
353355

trimesh/resolvers.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def get(self, name):
354354
Asset name, i.e. 'quadknot.obj.mtl'
355355
"""
356356
# do import here to keep soft dependency
357-
import requests
357+
import httpx
358358

359359
# remove leading and trailing whitespace
360360
name = name.strip()
@@ -363,16 +363,16 @@ def get(self, name):
363363
# base url has been carefully formatted
364364
url = self.base_url + name
365365

366-
response = requests.get(url)
366+
response = httpx.get(url, follow_redirects=True)
367367

368-
if response.status_code != 200:
368+
if response.status_code >= 300:
369369
# try to strip off filesystem crap
370370
if name.startswith("./"):
371371
name = name[2:]
372-
response = requests.get(self.base_url + name)
372+
response = httpx.get(self.base_url + name, follow_redirects=True)
373373

374-
if response.status_code == "404":
375-
raise ValueError(response.content)
374+
# now raise if we don't have
375+
response.raise_for_status()
376376

377377
# return the bytes of the response
378378
return response.content

trimesh/units.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ def unit_conversion(current: str, desired: str) -> float:
3434
return to_inch(current.strip().lower()) / to_inch(desired.strip().lower())
3535

3636

37+
def keys() -> set:
38+
"""
39+
Return a set containing all currently valid units.
40+
41+
Returns
42+
--------
43+
keys
44+
All units with conversions i.e. {'in', 'm', ...}
45+
"""
46+
return set(_lookup.keys())
47+
48+
3749
def to_inch(unit: str) -> float:
3850
"""
3951
Calculate the conversion to an arbitrary common unit.

trimesh/visual/gloss.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,7 @@ def get_specular_glossiness(
180180
or specularGlossinessTexture.shape[-1]
181181
) == 1:
182182
# use the one channel as a multiplier for specular and glossiness
183-
specularTexture = glossinessTexture = specularGlossinessTexture.reshape(
184-
(-1, -1, 1)
185-
)
183+
specularTexture = glossinessTexture = specularGlossinessTexture[..., np.newaxis]
186184
elif specularGlossinessTexture.shape[-1] == 3:
187185
# all channels are specular, glossiness is only a factor
188186
specularTexture = specularGlossinessTexture[..., :3]

0 commit comments

Comments
 (0)