diff --git a/xrfeitoria/cmd/blender/render.py b/xrfeitoria/cmd/blender/render.py index c0516710..9a64e254 100644 --- a/xrfeitoria/cmd/blender/render.py +++ b/xrfeitoria/cmd/blender/render.py @@ -155,7 +155,7 @@ def main( camera_name = 'camera' with xf.init_blender(exec_path=blender_exec, background=background) as xf_runner: - with xf_runner.Sequence.new(seq_name=seq_name) as seq: + with xf_runner.sequence(seq_name=seq_name) as seq: actor = seq.import_actor(actor_name='actor', file_path=mesh_path, stencil_value=255) actor.set_origin_to_center() actor.location = (0, 0, 0) diff --git a/xrfeitoria/sequence/sequence_wrapper.py b/xrfeitoria/sequence/sequence_wrapper.py index 6f44c5de..87e809c9 100644 --- a/xrfeitoria/sequence/sequence_wrapper.py +++ b/xrfeitoria/sequence/sequence_wrapper.py @@ -1,8 +1,9 @@ """Sequence wrapper functions.""" +import inspect import warnings from contextlib import contextmanager -from typing import ContextManager, List, Optional, Tuple, Union +from typing import ContextManager, Optional, Union from typing_extensions import deprecated @@ -15,6 +16,21 @@ __all__ = ['sequence_wrapper_blender', 'sequence_wrapper_unreal'] +def _get_caller_frame(): + """Get the actual caller's frame by traversing the frame stack.""" + frame = inspect.currentframe() + try: + while frame: + frame_info = inspect.getframeinfo(frame) + # Skip frames from this module and contextlib + if frame_info.filename.endswith(('sequence_wrapper.py', 'contextlib.py')): + frame = frame.f_back + continue + return frame + finally: + del frame + + @deprecated('Use `xf_runner.sequence` function instead.', category=DeprecationWarning) class SequenceWrapperBlender: """Sequence utils class.""" @@ -47,7 +63,14 @@ def new( Yields: SequenceBase: Sequence object. """ - warnings.showwarning(cls._warn_msg, DeprecationWarning, __file__, 0) + caller_frame = _get_caller_frame() + if caller_frame: + warnings.showwarning( + cls._warn_msg, DeprecationWarning, caller_frame.f_code.co_filename, caller_frame.f_lineno + ) + else: + warnings.warn(cls._warn_msg, DeprecationWarning, stacklevel=3) + cls._seq._new( seq_name=seq_name, level=level, @@ -69,7 +92,14 @@ def open(cls, seq_name: str) -> ContextManager[SequenceBase]: Yields: SequenceBase: Sequence object. """ - warnings.showwarning(cls._warn_msg, DeprecationWarning, __file__, 0) + caller_frame = _get_caller_frame() + if caller_frame: + warnings.showwarning( + cls._warn_msg, DeprecationWarning, caller_frame.f_code.co_filename, caller_frame.f_lineno + ) + else: + warnings.warn(cls._warn_msg, DeprecationWarning, stacklevel=3) + cls._seq._open(seq_name=seq_name) yield cls._seq cls._seq.close()