From 4699ed668e8ea211704d53ea978451140179b82c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?charlotte=20=F0=9F=8C=B8?= Date: Fri, 25 Sep 2026 15:55:53 -0700 Subject: [PATCH] A few misc fixes. --- crates/processing_pyo3/mewnala/__init__.py | 26 ++++++++++++---------- crates/processing_pyo3/mewnala/math.py | 6 +++++ crates/processing_render/src/render/mod.rs | 2 +- src/lib.rs | 6 ++++- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/crates/processing_pyo3/mewnala/__init__.py b/crates/processing_pyo3/mewnala/__init__.py index f3d6f78a..44d2cbae 100644 --- a/crates/processing_pyo3/mewnala/__init__.py +++ b/crates/processing_pyo3/mewnala/__init__.py @@ -5,22 +5,18 @@ # through an explicit alias rather than the shadowed names. import builtins as _builtins -# re-export the native submodules as submodules of this module, if they exist -# this allows users to import from `mewnala.math` without needing to know about -# the internal structure of the native module +# re-export native submodules that have no Python counterpart as submodules of +# this module, so users can import from `mewnala.color` without knowing about +# the internal structure of the native module. import sys as _sys from . import mewnala as _native -for _name in ("math",): - _sub = getattr(_native, _name, None) - if _sub is not None: - _sys.modules[f"{__name__}.{_name}"] = _sub - _color = getattr(_native, "color", None) if _color is not None: _sys.modules[f"{__name__}.color"] = _color -from . import math # noqa: E402 (Python submodule, extends native math) +import importlib as _importlib +math = _importlib.import_module(f"{__name__}.math") # noqa: E402 from .math import * # noqa: E402,F401,F403 # global var handling. for wildcard import of our module, we copy into globals, otherwise @@ -111,7 +107,11 @@ def __getattr__(name): g = _get_graphics() if g is None: return 0 - x, y = g.surface.position + # offscreen canvases (notebooks, embedding hosts) have no window position + try: + x, y = g.surface.position + except (AttributeError, RuntimeError): + return 0 return x if name == "window_x" else y raise AttributeError(f"module {__name__!r} has no attribute {name!r}") @@ -120,7 +120,9 @@ def __dir__(): return sorted(_builtins.set(list(globals().keys()) + list(_DYNAMIC))) __all__ = sorted( - {n for n in dir(_native) if not n.startswith("_")} | _builtins.set(_DYNAMIC) + {n for n in dir(_native) if not n.startswith("_")} + | {n for n in dir(math) if not n.startswith("_")} + | _builtins.set(_DYNAMIC) ) -del _sys, _name, _sub +del _sys, _importlib diff --git a/crates/processing_pyo3/mewnala/math.py b/crates/processing_pyo3/mewnala/math.py index c399e292..b910500a 100644 --- a/crates/processing_pyo3/mewnala/math.py +++ b/crates/processing_pyo3/mewnala/math.py @@ -1,6 +1,12 @@ """Processing math methods and vector/quaternion types.""" import math as _math from .mewnala import math as _native_math + +# extend native math so glob imports work +for _name in dir(_native_math): + if not _name.startswith("_"): + globals()[_name] = getattr(_native_math, _name) +del _name from math import ( sin, cos, tan, atan, atan2, diff --git a/crates/processing_render/src/render/mod.rs b/crates/processing_render/src/render/mod.rs index 685f6f80..e841461b 100644 --- a/crates/processing_render/src/render/mod.rs +++ b/crates/processing_render/src/render/mod.rs @@ -47,7 +47,7 @@ pub(crate) const BATCH_INDEX_STEP: f32 = 0.001; pub struct BelongsToGraphics(pub Entity); #[derive(Component, Default)] -#[relationship_target(relationship = BelongsToGraphics)] +#[relationship_target(relationship = BelongsToGraphics, linked_spawn)] pub struct TransientMeshes(Vec); #[derive(SystemParam)] diff --git a/src/lib.rs b/src/lib.rs index 9f00d064..7620f21c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -157,13 +157,17 @@ fn setup_tracing(log_level: Option<&str>) -> error::Result<()> { #[cfg(not(target_arch = "wasm32"))] { use tracing_subscriber::EnvFilter; + use tracing_subscriber::util::SubscriberInitExt; let filter = EnvFilter::try_new(log_level.unwrap_or("info")) .unwrap_or_else(|_| EnvFilter::new("info")); let subscriber = tracing_subscriber::FmtSubscriber::builder() .with_env_filter(filter) .finish(); - tracing::subscriber::set_global_default(subscriber)?; + // `try_init` also installs the `log` bridge, so wgpu/naga reach this subscriber. + if subscriber.try_init().is_err() { + tracing::debug!("global tracing subscriber already set by host; keeping it"); + } } Ok(()) }