Skip to content

Commit

Permalink
Merge pull request #18 from simonsobs/filter
Browse files Browse the repository at this point in the history
Trace only the main scrip
  • Loading branch information
TaiSakuma authored Nov 1, 2023
2 parents a3da610 + 8525775 commit 1d33d9e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
7 changes: 4 additions & 3 deletions nextline/spawned/plugin/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
14 changes: 14 additions & 0 deletions nextline/spawned/plugin/plugins/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.'''
Expand Down Expand Up @@ -41,6 +43,18 @@ def filter(self, trace_args: TraceArgs) -> bool | None:
return func_name == '<lambda>' 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.'''

Expand Down

0 comments on commit 1d33d9e

Please sign in to comment.