Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau committed Nov 20, 2024
1 parent 8446729 commit 5fd8f31
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
14 changes: 10 additions & 4 deletions pyinstrument/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,22 +421,28 @@ def compute_render_options(
"""

unicode_support: bool = file_supports_unicode(output_file)
color_support: bool = file_supports_color(output_file)

error, render_options = _compute_render_options(options, renderer_class, unicode_support)
error, render_options = _compute_render_options(
options, renderer_class, unicode_support, color_support
)
if error is not None:
raise OptionsParseError(error)
assert render_options is not None
return render_options


def _compute_render_options(
options: CommandLineOptions, renderer_class: type[renderers.Renderer], unicode_support: bool
options: CommandLineOptions,
renderer_class: type[renderers.Renderer],
unicode_support: bool,
color_support: bool,
) -> Tuple[Optional[str], Optional[dict[str, Any]]]:
"""
Similar as compute_render_options, but return a tuple (error message, data)
if there is an error; this will let us reuse _compute_render_options in magics.
output_file, has been replaced by unicode_support:bool
output_file, has been replaced by unicode_support:bool, color_support:bool
"""
# parse show/hide options
if options.hide_fnmatch is not None and options.hide_regex is not None:
Expand Down Expand Up @@ -476,7 +482,7 @@ def _compute_render_options(
unicode_override = options.unicode is not None
color_override = options.color is not None
unicode: Any = options.unicode if unicode_override else unicode_support
color: Any = options.color if color_override else unicode_support
color: Any = options.color if color_override else color_support

render_options.update({"unicode": unicode, "color": color})

Expand Down
2 changes: 1 addition & 1 deletion pyinstrument/magic/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def pyinstrument(self, line, cell=None):
return

html_error, html_config = _compute_render_options(
args, renderer_class=HTMLRenderer, unicode_support=True
args, renderer_class=HTMLRenderer, unicode_support=True, color_support=True
)
if html_error is not None:
raise ValueError(html_error)
Expand Down
2 changes: 1 addition & 1 deletion test/test_cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def test_invocation_machinery_is_trimmed(self, pyinstrument_invocation, tmp_path
print(output)

first_profiling_line = re.search(r"^\d+(\.\d+)?\s+([^\s]+)\s+(.*)", output, re.MULTILINE)
assert first_profiling_line
assert first_profiling_line, output

function_name = first_profiling_line.group(2)
location = first_profiling_line.group(3)
Expand Down

0 comments on commit 5fd8f31

Please sign in to comment.