cleanup: remove the package's per-body blob path check, and comments that still said "multi-body part"
DECISION: delete the one piece of dead code the one-solid change left behind, and correct comments that point at the withdrawn design. WHY: a Part holds exactly one solid (owner's decision after the discussion recorded in design-docs/part-holds-one-solid.md). The part-definition no longer has `bodies`, so product/packages.py's loop `for body in getattr(definition, "bodies", ()) or ()` (checking each body's BRep and snapshot path prefix) could never run; it only hid, by returning (), that the attribute is gone. Removing it with _checked_body_refs makes the package's blob check say exactly what a definition has. The comments in scene/preview.py (entity ids `entity/<id>/body:<name>/...`) and _glue/session.py described a "body of a multi-body part"; `body:<name>` entities now belong to the open solids of a notebook (compile_open_bodies), and the walk of product values lists a Part's children in _children. No behaviour change. Checked: test_product_packages, test_scene_preview and test_one_solid_part pass (59 tests). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -89,8 +89,7 @@ def walk_values(value: Any, *, deep: bool, seen: Optional[Set[int]] = None) -> I
|
||||
for item in value:
|
||||
yield from walk_values(item, deep=deep, seen=seen)
|
||||
elif deep:
|
||||
# a result wrapped in the caller's own dataclass (the product values have their own children: a multi-body Part's
|
||||
# `body` field refuses to name one body)
|
||||
# a result wrapped in the caller's own dataclass (the product values have their own children, listed in _children)
|
||||
if dataclasses.is_dataclass(value) and not isinstance(value, type) and type(value).__name__ not in _PRODUCT_KINDS:
|
||||
for field in dataclasses.fields(value):
|
||||
if not field.name.startswith("_"):
|
||||
|
||||
@@ -212,19 +212,9 @@ def _definition_refs(definition: Definition) -> list[Mapping[str, Any]]:
|
||||
f"definition blob path {path!r} outside its semantic domain {role.path_prefix!r}"
|
||||
)
|
||||
refs.append(ref.to_dict())
|
||||
for body in getattr(definition, "bodies", ()) or (): # every body of a multi-body part has its own BRep and snapshot
|
||||
refs.extend(_checked_body_refs((body.body_ref.to_dict(), body.topology_snapshot_ref.to_dict())))
|
||||
return refs
|
||||
|
||||
|
||||
def _checked_body_refs(refs: tuple[Mapping[str, Any], ...]) -> list[Mapping[str, Any]]:
|
||||
for ref, prefix in zip(refs, ("body/", "topology/")):
|
||||
path = str(ref["path"])
|
||||
if not path.startswith(prefix):
|
||||
raise ProductPackageError(f"definition blob path {path!r} outside its semantic domain {prefix!r}")
|
||||
return list(refs)
|
||||
|
||||
|
||||
def _definition_closure(root: Definition) -> dict[str, Definition]:
|
||||
definitions: dict[str, Definition] = {}
|
||||
active: set[str] = set()
|
||||
|
||||
@@ -426,8 +426,8 @@ def encode_preview(scene: PreviewScene, omit: Collection[str] = ()) -> bytes:
|
||||
continue
|
||||
definition = scene.definitions[key]
|
||||
body_id = scene.bodies.get(key)
|
||||
# entity/<part>/<kind>/<topo>; a body of a multi-body part: entity/<part>/body:<body>/<kind>/<topo> (as in
|
||||
# the package's scene, scene/product_scene.py)
|
||||
# entity/<part>/<kind>/<topo>; an open solid of a notebook (compile_open_bodies):
|
||||
# entity/<notebook id>/body:<name>/<kind>/<topo>
|
||||
prefix = f"entity/{definition}/" if body_id is None else f"entity/{definition}/body:{body_id}/"
|
||||
parts.append(
|
||||
{
|
||||
@@ -521,15 +521,15 @@ def decode_preview_header(data: bytes) -> dict[str, Any]:
|
||||
def entity_info(scene: PreviewScene, entity_id: str) -> dict[str, Any] | None:
|
||||
"""The geometric properties of the entity *entity_id* of a part of *scene*.
|
||||
|
||||
``entity/<definition>/<kind>/<topo id>`` (``entity/<definition>/body:<body id>/...`` for a body of a
|
||||
multi-body part); returns what the package's entity
|
||||
``entity/<definition>/<kind>/<topo id>`` (``entity/<notebook id>/body:<name>/...`` for an open solid of a
|
||||
notebook); returns what the package's entity
|
||||
sidecar holds for it (``properties``, ``geometry``, ``tags``) except the
|
||||
``source`` links into the feature graph, or ``None`` if there is no such entity.
|
||||
"""
|
||||
_, _, rest = entity_id.partition("entity/")
|
||||
definition, _, tail = rest.partition("/")
|
||||
body_id = ""
|
||||
if tail.startswith("body:"): # a body of a multi-body part
|
||||
if tail.startswith("body:"): # an open solid of a notebook
|
||||
segment, _, tail = tail.partition("/")
|
||||
body_id = segment[len("body:") :]
|
||||
kind, _, topo_id = tail.partition("/")
|
||||
|
||||
Reference in New Issue
Block a user