From 4307720321e95077d56f93f436d84da038c8d7d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=B3pez=20Barr=C3=B3n?= Date: Sun, 8 Dec 2024 16:38:42 +1100 Subject: [PATCH] minor wording and cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian López Barrón --- grill/cook/__init__.py | 9 ++++----- grill/views/_graph.py | 6 +++--- tests/test_cook.py | 3 ++- tests/test_views.py | 4 +--- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/grill/cook/__init__.py b/grill/cook/__init__.py index fc84fa41..98921577 100644 --- a/grill/cook/__init__.py +++ b/grill/cook/__init__.py @@ -191,7 +191,8 @@ def define_taxon(stage: Usd.Stage, name: str, *, references: tuple[Usd.Prim] = t return prim -def itaxa(stage): +def itaxa(stage: Usd.Stage) -> typing.Generator[Usd.Prim]: + """For the given stage, iterate existing taxa under the taxonomy hierarchy.""" return filter( lambda prim: prim.GetAssetInfoByKey(_ASSETINFO_TAXA_KEY), _usd.iprims(stage, root_paths={_TAXONOMY_ROOT_PATH}, traverse_predicate=Usd.PrimAllPrimsPredicate) @@ -532,10 +533,8 @@ def _inherit_or_specialize_unit(method, context_unit): @functools.singledispatch -def taxonomy_graph(prims, url_id_prefix): - """ - prims - """ +def taxonomy_graph(prims: Usd.Prim, url_id_prefix) -> nx.DiGraph: + """Get the hierarchical taxonomy representation of the given taxa prims.""" graph = nx.DiGraph(tooltip="Taxonomy Graph") graph.graph.update( graph={'rankdir': 'LR'}, diff --git a/grill/views/_graph.py b/grill/views/_graph.py index 0e4639a5..b40a6529 100644 --- a/grill/views/_graph.py +++ b/grill/views/_graph.py @@ -49,7 +49,7 @@ Please make sure graphviz is installed and 'dot' available on the system's PATH environment variable. -For more details on installing graphviz, visit https://pygraphviz.github.io/documentation/stable/install.html +For more details on installing graphviz, visit https://graphviz.org/download/ or https://grill.readthedocs.io/en/latest/install.html#conda-environment-example """ @@ -90,7 +90,7 @@ def _dot_2_svg(sourcepath): class _Node(QtWidgets.QGraphicsTextItem): - # TODO: see if we can remove 'label', since we are already processing the graphviz one here, it might be cheaper to have label created only when we need it + # Note: keep 'label' as an argument to use as much as possible as-is for clients to provide their own HTML style def __init__(self, parent=None, label="", color="", fillcolor="", plugs: tuple = (), visible=True): super().__init__(parent) self._edges = [] @@ -599,7 +599,7 @@ def _load_graph(self, graph): self.scene().addItem(text_item) return - try: # exit early if pygraphviz is not installed, needed for positions + try: # exit early if pydot is not installed, needed for positions positions = drawing.nx_pydot.graphviz_layout(graph, prog='dot') except ImportError as exc: message = str(exc) diff --git a/tests/test_cook.py b/tests/test_cook.py index 91dbaee7..6e0e3e28 100644 --- a/tests/test_cook.py +++ b/tests/test_cook.py @@ -50,7 +50,8 @@ def test_fetch_stage(self): usd_opened = str(names.UsdAsset.get_anonymous(item='usd_opened')) Sdf.Layer.CreateNew(str(repo_path / usd_opened)) - with self.assertRaises(Tf.ErrorException): + with self.assertRaisesRegex(Tf.ErrorException, "Failed to open layer"): + # no resolver context, so unable to open stage Usd.Stage.Open(usd_opened) with Ar.ResolverContextBinder(resolver_ctx): diff --git a/tests/test_views.py b/tests/test_views.py index fe2672ae..4f780f45 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -154,8 +154,6 @@ def test_scenegraph_composition(self): widget._layers.table.selectAll() self.assertEqual(5, widget._layers.model.rowCount()) self.assertEqual(1, widget._prims.model.rowCount()) - # add_dll_directory only on Windows - os.add_dll_directory = lambda path: print(f"Added {path}") if not hasattr(os, "add_dll_directory") else os.add_dll_directory _core._which.cache_clear() with mock.patch("grill.views.description._which") as patch: # simulate dot is not in the environment @@ -163,7 +161,7 @@ def test_scenegraph_composition(self): widget._graph_view.view([0,1]) _core._which.cache_clear() - with mock.patch("grill.views.description.nx.nx_agraph.write_dot") as patch: # simulate pygraphviz is not installed + with mock.patch("grill.views.description.nx.nx_agraph.write_dot") as patch: # simulate pydot not installed patch.side_effect = ImportError widget._graph_view.view([0])