py-materials 3.5.0__tar.gz → 3.7.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {py_materials-3.5.0 → py_materials-3.7.0}/PKG-INFO +38 -1
- {py_materials-3.5.0 → py_materials-3.7.0}/README.md +37 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/pyproject.toml +1 -1
- {py_materials-3.5.0 → py_materials-3.7.0}/src/pymat/__init__.py +1 -1
- {py_materials-3.5.0 → py_materials-3.7.0}/src/pymat/core.py +115 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/src/pymat/vis/_model.py +101 -1
- {py_materials-3.5.0 → py_materials-3.7.0}/tests/test_e2e_vis.py +86 -0
- py_materials-3.7.0/tests/test_material_copy.py +325 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/tests/test_readme_examples.py +42 -0
- py_materials-3.7.0/tests/test_vis_override.py +466 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/.gitignore +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/LICENSE +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/docs/catalog/README.md +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/docs/catalog/ceramics/README.md +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/docs/catalog/electronics/README.md +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/docs/catalog/gases/README.md +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/docs/catalog/liquids/README.md +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/docs/catalog/metals/README.md +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/docs/catalog/plastics/README.md +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/docs/catalog/scintillators/README.md +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/docs/decisions/README.md +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/mat-rs/data/README.md +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/src/pymat/data/ceramics.toml +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/src/pymat/data/electronics.toml +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/src/pymat/data/gases.toml +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/src/pymat/data/liquids.toml +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/src/pymat/data/metals.toml +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/src/pymat/data/plastics.toml +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/src/pymat/data/scintillators.toml +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/src/pymat/elements.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/src/pymat/enrichers.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/src/pymat/factories.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/src/pymat/loader.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/src/pymat/properties.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/src/pymat/registry.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/src/pymat/search.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/src/pymat/units.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/src/pymat/vis/__init__.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/src/pymat/vis/adapters.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/tests/__init__.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/tests/_visual_compare.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/tests/baselines/README.md +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/tests/conftest.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/tests/material_preview.html +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/tests/test_adapters.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/tests/test_apply_to.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/tests/test_build123d_integration_examples.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/tests/test_catalog.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/tests/test_core.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/tests/test_enrichers.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/tests/test_integration.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/tests/test_loader.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/tests/test_lookup.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/tests/test_properties.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/tests/test_search.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/tests/test_toml_integrity.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/tests/test_uncertainties.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/tests/test_vis.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/tests/test_vis_inheritance.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/tests/test_visual_compare.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/tests/test_visual_regression.py +0 -0
- {py_materials-3.5.0 → py_materials-3.7.0}/tests/visual_render.html +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: py-materials
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.7.0
|
|
4
4
|
Summary: Hierarchical material library for CAD applications with build123d integration
|
|
5
5
|
Project-URL: Homepage, https://github.com/MorePet/py-mat
|
|
6
6
|
Project-URL: Repository, https://github.com/MorePet/py-mat
|
|
@@ -245,6 +245,43 @@ lyso_crystal = lyso
|
|
|
245
245
|
assert "LYSO" in lyso_crystal.name
|
|
246
246
|
```
|
|
247
247
|
|
|
248
|
+
## Customizing Appearance Safely
|
|
249
|
+
|
|
250
|
+
Materials reached via `pymat["..."]` or category imports
|
|
251
|
+
(`from pymat import stainless`) are *shared instances* — the
|
|
252
|
+
same object every caller in the process sees. Mutating
|
|
253
|
+
`m.vis.roughness = 0.6` or flipping `m.vis.finish` on those
|
|
254
|
+
leaks into every other consumer.
|
|
255
|
+
|
|
256
|
+
The safe pattern uses two methods that pair cleanly:
|
|
257
|
+
|
|
258
|
+
```python
|
|
259
|
+
import pymat
|
|
260
|
+
from pymat.vis import to_threejs
|
|
261
|
+
|
|
262
|
+
steel = pymat["Stainless Steel 304"] # registry singleton — DON'T mutate
|
|
263
|
+
|
|
264
|
+
# Derive an independent variant (1) and attach it to a fresh Material (2)
|
|
265
|
+
polished_vis = steel.vis.override(roughness=0.05, finish="polished")
|
|
266
|
+
shiny = steel.with_vis(polished_vis)
|
|
267
|
+
|
|
268
|
+
three = to_threejs(shiny) # uses the polished values
|
|
269
|
+
assert three["roughness"] == 0.05
|
|
270
|
+
assert steel.vis.material_id == "Metal012" # registry untouched
|
|
271
|
+
|
|
272
|
+
# ``Vis.override(**deltas) -> Vis`` → deep-copied Vis with deltas
|
|
273
|
+
# (finishes deep-copied; identity changes invalidate the texture
|
|
274
|
+
# cache atomically; unknown kwargs raise TypeError).
|
|
275
|
+
# ``Material.with_vis(vis) -> Material`` → registry-detached Material
|
|
276
|
+
# with the supplied Vis attached. Equivalent to ``Material.copy()``
|
|
277
|
+
# followed by slotting the new vis in.
|
|
278
|
+
# ``Material.copy() -> Material`` → generic detach if you need to
|
|
279
|
+
# tweak more than just the Vis.
|
|
280
|
+
|
|
281
|
+
# Materials *you* construct directly (Material(name="custom",
|
|
282
|
+
# vis={...})) are not shared and can be mutated freely.
|
|
283
|
+
```
|
|
284
|
+
|
|
248
285
|
## Physics Properties vs Visualization
|
|
249
286
|
|
|
250
287
|
Understand the difference between measured optical properties (physics)
|
|
@@ -211,6 +211,43 @@ lyso_crystal = lyso
|
|
|
211
211
|
assert "LYSO" in lyso_crystal.name
|
|
212
212
|
```
|
|
213
213
|
|
|
214
|
+
## Customizing Appearance Safely
|
|
215
|
+
|
|
216
|
+
Materials reached via `pymat["..."]` or category imports
|
|
217
|
+
(`from pymat import stainless`) are *shared instances* — the
|
|
218
|
+
same object every caller in the process sees. Mutating
|
|
219
|
+
`m.vis.roughness = 0.6` or flipping `m.vis.finish` on those
|
|
220
|
+
leaks into every other consumer.
|
|
221
|
+
|
|
222
|
+
The safe pattern uses two methods that pair cleanly:
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
import pymat
|
|
226
|
+
from pymat.vis import to_threejs
|
|
227
|
+
|
|
228
|
+
steel = pymat["Stainless Steel 304"] # registry singleton — DON'T mutate
|
|
229
|
+
|
|
230
|
+
# Derive an independent variant (1) and attach it to a fresh Material (2)
|
|
231
|
+
polished_vis = steel.vis.override(roughness=0.05, finish="polished")
|
|
232
|
+
shiny = steel.with_vis(polished_vis)
|
|
233
|
+
|
|
234
|
+
three = to_threejs(shiny) # uses the polished values
|
|
235
|
+
assert three["roughness"] == 0.05
|
|
236
|
+
assert steel.vis.material_id == "Metal012" # registry untouched
|
|
237
|
+
|
|
238
|
+
# ``Vis.override(**deltas) -> Vis`` → deep-copied Vis with deltas
|
|
239
|
+
# (finishes deep-copied; identity changes invalidate the texture
|
|
240
|
+
# cache atomically; unknown kwargs raise TypeError).
|
|
241
|
+
# ``Material.with_vis(vis) -> Material`` → registry-detached Material
|
|
242
|
+
# with the supplied Vis attached. Equivalent to ``Material.copy()``
|
|
243
|
+
# followed by slotting the new vis in.
|
|
244
|
+
# ``Material.copy() -> Material`` → generic detach if you need to
|
|
245
|
+
# tweak more than just the Vis.
|
|
246
|
+
|
|
247
|
+
# Materials *you* construct directly (Material(name="custom",
|
|
248
|
+
# vis={...})) are not shared and can be mutated freely.
|
|
249
|
+
```
|
|
250
|
+
|
|
214
251
|
## Physics Properties vs Visualization
|
|
215
252
|
|
|
216
253
|
Understand the difference between measured optical properties (physics)
|
|
@@ -410,6 +410,121 @@ class _MaterialInternal:
|
|
|
410
410
|
|
|
411
411
|
return obj
|
|
412
412
|
|
|
413
|
+
def copy(self) -> "Material":
|
|
414
|
+
"""Return a detached copy of this Material.
|
|
415
|
+
|
|
416
|
+
Materials reached via ``pymat["..."]`` or category imports
|
|
417
|
+
(``from pymat import stainless``) are *shared instances* — the
|
|
418
|
+
same object every caller in the process sees. Mutating
|
|
419
|
+
``m.properties.mechanical.density``, reassigning ``m.vis``, or
|
|
420
|
+
flipping ``m.vis.finish`` on those leaks into every other
|
|
421
|
+
consumer. ``copy`` returns an independent instance — same name
|
|
422
|
+
/ grade / properties / vis — that can be tweaked freely.
|
|
423
|
+
|
|
424
|
+
Materials *you* construct (``Material(name="custom", ...)``)
|
|
425
|
+
are not shared and need no copy. The hazard only applies to
|
|
426
|
+
registry instances.
|
|
427
|
+
|
|
428
|
+
Detached:
|
|
429
|
+
|
|
430
|
+
- ``_vis`` deep-copied AND its texture cache zeroed (deepcopy
|
|
431
|
+
bypasses ``Vis.__post_init__``, so the cache is cleared
|
|
432
|
+
explicitly here)
|
|
433
|
+
- ``properties`` deep-copied
|
|
434
|
+
- all property-group kwarg dicts (mechanical, thermal, …) deep-copied
|
|
435
|
+
|
|
436
|
+
Preserved by reference (intentionally — these are part of the
|
|
437
|
+
registry hierarchy, not per-instance state):
|
|
438
|
+
|
|
439
|
+
- ``parent`` (the registry parent the copy still belongs under).
|
|
440
|
+
Note: mutating ``c.parent.<anything>`` still affects the
|
|
441
|
+
registry. Don't.
|
|
442
|
+
- ``_children`` dict — empty for the copy (a detached node has
|
|
443
|
+
no children of its own; it's a leaf variant). For parent-level
|
|
444
|
+
materials this means ``stainless.copy().s304`` raises.
|
|
445
|
+
- ``_key`` cleared so it can't be confused with the registry entry
|
|
446
|
+
|
|
447
|
+
For just changing appearance, prefer
|
|
448
|
+
:meth:`with_vis` + :meth:`Vis.override` — single-shot and clearer.
|
|
449
|
+
"""
|
|
450
|
+
from copy import deepcopy
|
|
451
|
+
|
|
452
|
+
new = type(self)(name=self.name)
|
|
453
|
+
# Identity / hierarchy metadata
|
|
454
|
+
new.formula = self.formula
|
|
455
|
+
new.composition = deepcopy(self.composition)
|
|
456
|
+
new.color = self.color
|
|
457
|
+
new.grade = self.grade
|
|
458
|
+
new.temper = self.temper
|
|
459
|
+
new.treatment = self.treatment
|
|
460
|
+
new.vendor = self.vendor
|
|
461
|
+
# Property-group kwarg dicts — preserve so re-init is consistent
|
|
462
|
+
new.mechanical = deepcopy(self.mechanical)
|
|
463
|
+
new.thermal = deepcopy(self.thermal)
|
|
464
|
+
new.electrical = deepcopy(self.electrical)
|
|
465
|
+
new.optical = deepcopy(self.optical)
|
|
466
|
+
new.manufacturing = deepcopy(self.manufacturing)
|
|
467
|
+
new.compliance = deepcopy(self.compliance)
|
|
468
|
+
new.sourcing = deepcopy(self.sourcing)
|
|
469
|
+
# Independent properties + vis. ``deepcopy`` bypasses
|
|
470
|
+
# ``Vis.__post_init__`` (it goes through ``__reduce_ex__``), so
|
|
471
|
+
# the texture cache must be zeroed explicitly. Otherwise the copy
|
|
472
|
+
# carries duplicated texture bytes (waste, not a leak — the deep
|
|
473
|
+
# copy is independent of the parent — but the docstring promises
|
|
474
|
+
# a clean cache so we deliver it).
|
|
475
|
+
new.properties = deepcopy(self.properties)
|
|
476
|
+
if self._vis is not None:
|
|
477
|
+
new_vis = deepcopy(self._vis)
|
|
478
|
+
# ``deepcopy`` bypasses ``Vis.__post_init__`` (it goes through
|
|
479
|
+
# ``__reduce_ex__``), so the texture cache must be zeroed
|
|
480
|
+
# explicitly. ``object.__setattr__`` skips the identity-
|
|
481
|
+
# invalidation hook in ``Vis.__setattr__`` (which is fine here
|
|
482
|
+
# — we're not changing identity, just resetting cache).
|
|
483
|
+
object.__setattr__(new_vis, "_textures", {})
|
|
484
|
+
object.__setattr__(new_vis, "_fetched", False)
|
|
485
|
+
new._vis = new_vis
|
|
486
|
+
else:
|
|
487
|
+
new._vis = None
|
|
488
|
+
# Registry decoupling
|
|
489
|
+
new.parent = self.parent # stays registry-aware for fallback chain
|
|
490
|
+
new._children = {}
|
|
491
|
+
new._key = None
|
|
492
|
+
return new
|
|
493
|
+
|
|
494
|
+
def with_vis(self, vis: "Vis") -> "Material": # noqa: F821 — forward ref
|
|
495
|
+
"""Return a detached copy with the given Vis attached.
|
|
496
|
+
|
|
497
|
+
The canonical safe path for "I want this material with a tweaked
|
|
498
|
+
appearance" — pairs cleanly with :meth:`Vis.override`::
|
|
499
|
+
|
|
500
|
+
steel = pymat["Stainless Steel 304"]
|
|
501
|
+
shiny = steel.with_vis(steel.vis.override(roughness=0.05, finish="polished"))
|
|
502
|
+
pymat.vis.to_threejs(shiny)
|
|
503
|
+
# steel is the registry singleton; shiny is independent.
|
|
504
|
+
|
|
505
|
+
Closes the parent-singleton hazard: ``m.vis = ...`` directly on
|
|
506
|
+
a registry instance still mutates the shared object. ``with_vis``
|
|
507
|
+
returns a fresh Material whose ``vis`` slot is the new value,
|
|
508
|
+
leaving the registry untouched.
|
|
509
|
+
|
|
510
|
+
The supplied ``vis`` is deep-copied so passing in a registry
|
|
511
|
+
instance's own ``vis`` (e.g. ``m.with_vis(m.vis)``) does not
|
|
512
|
+
re-alias the singleton. Always returns an independent Vis.
|
|
513
|
+
"""
|
|
514
|
+
from copy import deepcopy
|
|
515
|
+
|
|
516
|
+
from pymat.vis._model import Vis
|
|
517
|
+
|
|
518
|
+
if not isinstance(vis, Vis):
|
|
519
|
+
raise TypeError(f"with_vis expects a Vis instance, got {type(vis).__name__}")
|
|
520
|
+
new = self.copy()
|
|
521
|
+
# Deep-copy the supplied vis so callers passing the registry's
|
|
522
|
+
# own ``m.vis`` don't re-alias the singleton. ``override`` already
|
|
523
|
+
# returns an independent Vis, but we cannot rely on the caller
|
|
524
|
+
# having gone through it.
|
|
525
|
+
new._vis = deepcopy(vis)
|
|
526
|
+
return new
|
|
527
|
+
|
|
413
528
|
# =========================================================================
|
|
414
529
|
# Information & Inspection
|
|
415
530
|
# =========================================================================
|
|
@@ -98,7 +98,6 @@ class Vis:
|
|
|
98
98
|
steel.vis.material_id # "Metal012"
|
|
99
99
|
steel.vis.tier # "1k"
|
|
100
100
|
steel.vis.finishes # {"brushed": {"source": ..., "id": ...}, ...}
|
|
101
|
-
steel.vis.finish = "polished" # switch appearance
|
|
102
101
|
|
|
103
102
|
Material-keyed delegates (ADR-0002)::
|
|
104
103
|
|
|
@@ -112,6 +111,21 @@ class Vis:
|
|
|
112
111
|
import pymat
|
|
113
112
|
d = pymat.vis.to_threejs(steel) # MeshPhysicalMaterial init dict
|
|
114
113
|
|
|
114
|
+
**Don't mutate the Vis on a registry Material.** Materials reached
|
|
115
|
+
via ``pymat["..."]`` or category imports (``from pymat import
|
|
116
|
+
stainless``) are *shared instances* — the same object every caller
|
|
117
|
+
in the process sees. Writing ``steel.vis.finish = "polished"`` on
|
|
118
|
+
one of those leaks into every other consumer.
|
|
119
|
+
|
|
120
|
+
The safe path: derive an independent copy via :meth:`override`,
|
|
121
|
+
attach it to a fresh Material via :meth:`Material.with_vis`::
|
|
122
|
+
|
|
123
|
+
polished_vis = steel.vis.override(finish="polished", roughness=0.05)
|
|
124
|
+
steel_polished = steel.with_vis(polished_vis)
|
|
125
|
+
|
|
126
|
+
Materials *you* construct directly (``Material(name="custom",
|
|
127
|
+
vis={...})``) are not shared and can be mutated freely.
|
|
128
|
+
|
|
115
129
|
Assigning ``source``, ``material_id``, or ``tier`` invalidates the
|
|
116
130
|
lazy texture cache automatically — the next ``.textures`` access
|
|
117
131
|
will re-fetch for the new identity.
|
|
@@ -315,6 +329,92 @@ class Vis:
|
|
|
315
329
|
super().__setattr__("_textures", {})
|
|
316
330
|
super().__setattr__("_fetched", False)
|
|
317
331
|
|
|
332
|
+
def override(self, **deltas: Any) -> Vis:
|
|
333
|
+
"""Return a new ``Vis`` with the given deltas applied; ``self``
|
|
334
|
+
is unchanged.
|
|
335
|
+
|
|
336
|
+
Use this when deriving a tweaked variant from a base Vis —
|
|
337
|
+
typically the registry instance returned by ``pymat["..."]``.
|
|
338
|
+
The registry instance is shared across all callers, so direct
|
|
339
|
+
mutation corrupts every other consumer of the same material::
|
|
340
|
+
|
|
341
|
+
steel = pymat["Stainless Steel 304"]
|
|
342
|
+
polished = steel.vis.override(roughness=0.3, finish="polished")
|
|
343
|
+
# steel.vis is unchanged; polished is independent.
|
|
344
|
+
|
|
345
|
+
Note: ``override`` is the runtime mirror of TOML grade override
|
|
346
|
+
(children inherit parent properties unless overridden). It is
|
|
347
|
+
NOT a flat field substitution like ``dataclasses.replace`` —
|
|
348
|
+
the ``finishes`` map is deep-copied (including caller-supplied
|
|
349
|
+
deltas), ``finish=`` is a special-cased lookup that flips
|
|
350
|
+
identity via the finishes map, and identity changes invalidate
|
|
351
|
+
the texture cache atomically.
|
|
352
|
+
|
|
353
|
+
Identity deltas (``source`` / ``material_id`` / ``tier``) route
|
|
354
|
+
through :meth:`set_identity` for atomic invalidation. The
|
|
355
|
+
``_finish`` label is cleared only when ``source`` or
|
|
356
|
+
``material_id`` change without an explicit ``finish=`` —
|
|
357
|
+
finishes pin (source, material_id), not tier, so a tier-only
|
|
358
|
+
change preserves the finish label.
|
|
359
|
+
|
|
360
|
+
``finish=`` runs LAST against the new (deep-copied) finishes
|
|
361
|
+
map, so ``override(finishes={...}, finish="x")`` resolves
|
|
362
|
+
``x`` in the replaced map.
|
|
363
|
+
|
|
364
|
+
Unknown kwargs raise ``TypeError`` — catches typos like
|
|
365
|
+
``roughnes=0.5`` that ``dataclasses.replace`` would accept
|
|
366
|
+
silently.
|
|
367
|
+
"""
|
|
368
|
+
from copy import deepcopy
|
|
369
|
+
from dataclasses import fields
|
|
370
|
+
|
|
371
|
+
# Public dataclass fields (excludes _textures, _fetched, _finish)
|
|
372
|
+
# plus the ``finish`` property — the canonical override surface.
|
|
373
|
+
valid_fields = {f.name for f in fields(self) if not f.name.startswith("_")}
|
|
374
|
+
valid_keys = valid_fields | {"finish"}
|
|
375
|
+
unknown = set(deltas) - valid_keys
|
|
376
|
+
if unknown:
|
|
377
|
+
raise TypeError(
|
|
378
|
+
f"Vis.override() got unexpected kwargs: {sorted(unknown)}. "
|
|
379
|
+
f"Valid keys: {sorted(valid_keys)}"
|
|
380
|
+
)
|
|
381
|
+
|
|
382
|
+
new = deepcopy(self)
|
|
383
|
+
|
|
384
|
+
# ``finish`` is a property setter (not a field) and must be
|
|
385
|
+
# applied LAST so it resolves against the new instance's
|
|
386
|
+
# (deep-copied) finishes map.
|
|
387
|
+
finish_delta = deltas.pop("finish", None)
|
|
388
|
+
|
|
389
|
+
# Identity-pair updates: route through set_identity for atomic
|
|
390
|
+
# cache invalidation. Compute "finish-invalidating change" from
|
|
391
|
+
# ``source``/``material_id`` only — tier doesn't pin which
|
|
392
|
+
# finish entry is selected (#103). Computed before set_identity
|
|
393
|
+
# writes so a no-op (same value) doesn't trigger the clear.
|
|
394
|
+
identity_keys = _IDENTITY_FIELDS & deltas.keys()
|
|
395
|
+
finish_invalidating_keys = identity_keys & {"source", "material_id"}
|
|
396
|
+
finish_invalidating = any(deltas[k] != getattr(new, k) for k in finish_invalidating_keys)
|
|
397
|
+
if identity_keys:
|
|
398
|
+
new.set_identity(**{k: deltas.pop(k) for k in list(identity_keys)})
|
|
399
|
+
|
|
400
|
+
for k, v in deltas.items():
|
|
401
|
+
# Caller-supplied ``finishes=`` must be deep-copied — storing
|
|
402
|
+
# by reference breaks the docstring promise and diverges from
|
|
403
|
+
# ``merge_from_toml`` semantics (#104).
|
|
404
|
+
if k == "finishes":
|
|
405
|
+
v = deepcopy(v)
|
|
406
|
+
setattr(new, k, v)
|
|
407
|
+
|
|
408
|
+
# Identity moved (source/material_id) without an explicit
|
|
409
|
+
# finish= → the inherited _finish label is now stale.
|
|
410
|
+
if finish_invalidating and finish_delta is None:
|
|
411
|
+
object.__setattr__(new, "_finish", None)
|
|
412
|
+
|
|
413
|
+
if finish_delta is not None:
|
|
414
|
+
new.finish = finish_delta
|
|
415
|
+
|
|
416
|
+
return new
|
|
417
|
+
|
|
318
418
|
@property
|
|
319
419
|
def client(self) -> MatVisClient:
|
|
320
420
|
"""The shared ``mat-vis-client`` singleton.
|
|
@@ -277,6 +277,92 @@ class TestEndToEnd:
|
|
|
277
277
|
assert rc.texture[:4] == b"\x89PNG"
|
|
278
278
|
|
|
279
279
|
|
|
280
|
+
@pytest.mark.skipif(SKIP_LIVE, reason="MAT_VIS_SKIP_LIVE=1")
|
|
281
|
+
class TestGpuopenNameLookup:
|
|
282
|
+
"""Human-readable name access for gpuopen materials.
|
|
283
|
+
|
|
284
|
+
Bernhard (build123d#1270) flagged gpuopen UX as UUID-only — see
|
|
285
|
+
mat-vis#143. mat-vis-client 0.6.3 fixed this upstream:
|
|
286
|
+
``MatVisClient._resolve_material_id`` accepts either canonical id
|
|
287
|
+
(UUID for gpuopen) or a normalized human-readable name from
|
|
288
|
+
``mat_vis.name`` in the index, and ``fetch_all_textures`` / ``mtlx``
|
|
289
|
+
call into it.
|
|
290
|
+
|
|
291
|
+
These tests pin: ``Vis.material_id`` set to a human-readable name
|
|
292
|
+
flows through to fetch + mtlx without py-mat needing to know about
|
|
293
|
+
the resolution. If mat-vis-client ever drops name-based lookup,
|
|
294
|
+
these go red and we know the consumer-facing UX regressed.
|
|
295
|
+
"""
|
|
296
|
+
|
|
297
|
+
PORTORO_NAME = "Portoro Green Marble"
|
|
298
|
+
PORTORO_UUID = "1f95c1cc-b0db-40b8-928c-775c0fc1228c"
|
|
299
|
+
|
|
300
|
+
def test_resolve_via_client(self):
|
|
301
|
+
"""Direct upstream check — proves the index has the name."""
|
|
302
|
+
from mat_vis_client import get_client
|
|
303
|
+
|
|
304
|
+
c = get_client()
|
|
305
|
+
with _skip_on_upstream_outage():
|
|
306
|
+
canonical = c._resolve_material_id("gpuopen", self.PORTORO_NAME, "1k")
|
|
307
|
+
assert canonical == self.PORTORO_UUID
|
|
308
|
+
|
|
309
|
+
def test_vis_fetch_textures_by_name(self):
|
|
310
|
+
"""Set ``vis.material_id`` to the human-readable name; texture
|
|
311
|
+
fetch resolves it transparently."""
|
|
312
|
+
from pymat import Material
|
|
313
|
+
|
|
314
|
+
m = Material(name="Portoro probe")
|
|
315
|
+
m.vis.source = "gpuopen"
|
|
316
|
+
m.vis.material_id = self.PORTORO_NAME
|
|
317
|
+
m.vis.tier = "1k"
|
|
318
|
+
|
|
319
|
+
with _skip_on_upstream_outage():
|
|
320
|
+
tx = m.vis.textures
|
|
321
|
+
|
|
322
|
+
assert tx, "no textures returned for gpuopen name lookup"
|
|
323
|
+
assert all(v[:4] == b"\x89PNG" for v in tx.values()), "non-PNG bytes"
|
|
324
|
+
|
|
325
|
+
def test_vis_mtlx_by_name(self):
|
|
326
|
+
"""``Vis.mtlx`` resolves the name → MaterialX XML."""
|
|
327
|
+
from pymat import Material
|
|
328
|
+
|
|
329
|
+
m = Material(name="Portoro mtlx probe")
|
|
330
|
+
m.vis.source = "gpuopen"
|
|
331
|
+
m.vis.material_id = self.PORTORO_NAME
|
|
332
|
+
m.vis.tier = "1k"
|
|
333
|
+
|
|
334
|
+
with _skip_on_upstream_outage():
|
|
335
|
+
xml = m.vis.mtlx.xml()
|
|
336
|
+
|
|
337
|
+
assert isinstance(xml, str)
|
|
338
|
+
assert len(xml) > 200, f"suspiciously short MaterialX ({len(xml)} chars)"
|
|
339
|
+
assert "<materialx" in xml.lower() or xml.startswith("<?xml")
|
|
340
|
+
|
|
341
|
+
def test_unknown_name_raises_typed_error(self):
|
|
342
|
+
"""Bad name → ``UnknownMaterialError``, not silent garbage."""
|
|
343
|
+
from mat_vis_client import UnknownMaterialError, get_client
|
|
344
|
+
|
|
345
|
+
c = get_client()
|
|
346
|
+
with _skip_on_upstream_outage():
|
|
347
|
+
with pytest.raises(UnknownMaterialError):
|
|
348
|
+
c._resolve_material_id("gpuopen", "Definitely Not A Material", "1k")
|
|
349
|
+
|
|
350
|
+
def test_canonical_uuid_still_works(self):
|
|
351
|
+
"""Backwards-compat: existing UUID-based callers (and our TOML)
|
|
352
|
+
keep working unchanged."""
|
|
353
|
+
from pymat import Material
|
|
354
|
+
|
|
355
|
+
m = Material(name="Portoro UUID probe")
|
|
356
|
+
m.vis.source = "gpuopen"
|
|
357
|
+
m.vis.material_id = self.PORTORO_UUID
|
|
358
|
+
m.vis.tier = "1k"
|
|
359
|
+
|
|
360
|
+
with _skip_on_upstream_outage():
|
|
361
|
+
tx = m.vis.textures
|
|
362
|
+
|
|
363
|
+
assert tx, "UUID lookup broke"
|
|
364
|
+
|
|
365
|
+
|
|
280
366
|
class TestSkipOnUpstreamOutage:
|
|
281
367
|
"""The flake-guard itself — tested without hitting the network."""
|
|
282
368
|
|