diff --git a/nextline/spawned/plugin/plugins/__init__.py b/nextline/spawned/plugin/plugins/__init__.py index b5817917..c899c2f9 100644 --- a/nextline/spawned/plugin/plugins/__init__.py +++ b/nextline/spawned/plugin/plugins/__init__.py @@ -5,7 +5,7 @@ from .compose import CallableComposer from .concurrency import TaskAndThreadKeeper, TaskOrThreadToTraceMapper -from .filter import FilerByModule, FilterByModuleName, FilterLambda +from .filter import FilerByModule, FilterByModuleName, FilterLambda, FilterMainScript from .global_ import GlobalTraceFunc, TraceFuncCreator from .local_ import LocalTraceFunc, TraceCallHandler from .pdb_ import PdbInstanceFactory, Prompt @@ -22,9 +22,10 @@ def register(hook: PluginManager) -> None: hook.register(LocalTraceFunc) hook.register(TaskOrThreadToTraceMapper) hook.register(TaskAndThreadKeeper) - hook.register(FilerByModule) + # hook.register(FilerByModule) hook.register(FilterLambda) - hook.register(FilterByModuleName) + # hook.register(FilterByModuleName) + hook.register(FilterMainScript) hook.register(GlobalTraceFunc) hook.register(TraceFuncCreator) hook.register(CallableComposer) diff --git a/nextline/spawned/plugin/plugins/filter.py b/nextline/spawned/plugin/plugins/filter.py index bed6d3a4..10aa361b 100644 --- a/nextline/spawned/plugin/plugins/filter.py +++ b/nextline/spawned/plugin/plugins/filter.py @@ -12,6 +12,8 @@ from nextline.spawned.types import TraceArgs from nextline.utils import current_task_or_thread, match_any +from . import _script + class FilterByModuleName: '''Skip Python modules with names that match any of the patterns.''' @@ -41,6 +43,18 @@ def filter(self, trace_args: TraceArgs) -> bool | None: return func_name == '' or None +class FilterMainScript: + '''Skip lambda functions.''' + + @hookimpl + def filter(self, trace_args: TraceArgs) -> bool | None: + frame = trace_args[0] + module_name = frame.f_globals.get('__name__') + if _script.__name__ == module_name: + return False + return True + + class FilerByModule: '''Accept the first module and modules ever in the cmdloop() context.'''