Skip to content
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
8 changes: 5 additions & 3 deletions line_profiler/line_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,14 @@ def add_module(self, mod):

# This could be in the ipython_extension submodule,
# but it doesn't depend on the IPython module so it's easier to just let it stay here.
def is_ipython_kernel_cell(filename):
""" Return True if a filename corresponds to a Jupyter Notebook cell
def is_generated_code(filename):
""" Return True if a filename corresponds to generated code, such as a
Jupyter Notebook cell.
"""
filename = os.path.normcase(filename)
temp_dir = os.path.normcase(tempfile.gettempdir())
return (
filename.startswith('<generated') or
filename.startswith('<ipython-input-') or
filename.startswith(os.path.join(temp_dir, 'ipykernel_')) or
filename.startswith(os.path.join(temp_dir, 'xpython_'))
Expand Down Expand Up @@ -249,7 +251,7 @@ def show_func(filename, start_lineno, func_name, timings, unit,
linenos = [t[0] for t in timings]

stream.write('Total time: %g s\n' % (total_time * unit))
if os.path.exists(filename) or is_ipython_kernel_cell(filename):
if os.path.exists(filename) or is_generated_code(filename):
stream.write(f'File: {filename}\n')
stream.write(f'Function: {func_name} at line {start_lineno}\n')
if os.path.exists(filename):
Expand Down
2 changes: 1 addition & 1 deletion line_profiler/line_profiler.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class LineProfiler(CLineProfiler, ByCountProfilerMixin):
...


def is_ipython_kernel_cell(filename):
def is_generated_code(filename):
...


Expand Down
Loading