line_profiler.autoprofile.profmod_extractor module

class line_profiler.autoprofile.profmod_extractor.ProfmodExtractor(tree, script_file, prof_mod)[source]

Bases: object

Map prof_mod to imports in an abstract syntax tree.

Takes the paths and dotted paths in prod_mod and finds their respective imports in an abstract syntax tree.

Initializes the AST tree profiler instance with the AST, script file path and prof_mod

Parameters:
  • tree (_ast.Module) – abstract syntax tree to fetch imports from.

  • script_file (str) – path to script being profiled.

  • prof_mod (List[str]) – list of imports to profile in script. passing the path to script will profile the whole script. the objects can be specified using its dotted path or full path (if applicable).

run()[source]

Map prof_mod to imports in an abstract syntax tree.

Takes the paths and dotted paths in prod_mod and finds their respective imports in an abstract syntax tree, returning their alias and the index they appear in the AST.

Returns:

tree_imports_to_profile_dict
dict of imports to profile
key (int):

index of import in AST

value (str):

alias (or name if no alias used) of import

Return type:

(Dict[int,str])