Fix scene-object registration interfering with other COMPAS backends#5
Open
arpastrana wants to merge 2 commits into
Open
Fix scene-object registration interfering with other COMPAS backends#5arpastrana wants to merge 2 commits into
arpastrana wants to merge 2 commits into
Conversation
Eager import-time registration populated COMPAS's global ITEM_SCENEOBJECT, which suppressed the lazy discovery trigger in compas.scene.context and left other backends unregistered. Declare __all_plugins__ so the factory is found through the standard collect_all path instead.
Add test_import_does_not_populate_registry_eagerly, run in a subprocess for a pristine interpreter (ITEM_SCENEOBJECT is a process-global latch). Hoist the module-level imports it shares with existing tests to the top of the file.
Contributor
Author
|
I updated the changelog, so not sure why the PR checklist does not pass in CI... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
compas_plotterregistered its scene objects eagerly at import time. That side effect broke scene-object resolution for every other COMPAS visualization backend (the Viewer and the Notebook) whenevercompas_plotterhappened to be imported first.This PR removes the eager registration and instead exposes the plugin the way
compas_viewerdoes, via__all_plugins__, so COMPAS discovers it through the standard lazycollect_allpath.The bug
Note the script never imports
compas_plotter.Root cause
COMPAS lazily initialises its scene-object registry with a one-shot guard in
compas/scene/context.py:The
register_scene_objectspluggable uses thecollect_allselector, so this single call is what registers every backend (base COMPAS, Viewer, Notebook, Plotter, …). It only runs whileITEM_SCENEOBJECTis still empty.The failure chain:
NurbsCurve.from_points(...)needs a geometry backend, so COMPAS runs plugin discovery, which imports every installedcompas_*package — includingcompas_plotter.compas_plotterranregister_scene_objects()eagerly (viafrom . import sceneand the eager call at the end ofscene/__init__.py), writingITEM_SCENEOBJECT["Plotter"] = {...}.ITEM_SCENEOBJECTis now non-empty, so COMPAS'sif not ITEM_SCENEOBJECTguard never fires. Thecollect_alldiscovery that would have registered the Viewer and base contexts is skipped.viewer.scene.add(mesh)can't resolveMeshin the"Viewer"context and raisesSceneObjectNotRegisteredError.compas_plotterwas also missing__all_plugins__, so the PluginManager never importedcompas_plotter.sceneto find the@plugin-decorated factory the proper way — the eager import was compensating for that, which is exactly what messed up with the guard.The fix
__all_plugins__ = ["compas_plotter.scene"]incompas_plotter/__init__.py(mirrorscompas_viewer).from . import sceneside-effect import.register_scene_objects()call at the end ofcompas_plotter/scene/__init__.py.Registration now happens only through COMPAS's plugin discovery + lazy
collect_all, so backends no longer clobber each other's registration.Verification
Reproduced and fixed against
compas 2.15.1,compas_viewer 2.0.2,compas_occ.SceneObjectNotRegisteredErroronviewer.scene.add(mesh).meshresolves toMeshObjectandarchtoNurbsCurveObject.compas_plotterstandalone still registers and draws (Plotter().add(mesh)test_import_does_not_populate_registry_eagerlyasserts,in a subprocess, that importing
compas_plotterleavesITEM_SCENEOBJECTempty and thatcollect_allthen registers both the Plotter and base contexts.ruff check/ruff format --checkclean.