Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trace only the main scrip #18

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading