diff --git a/pyinstrument/__main__.py b/pyinstrument/__main__.py index ae74047e..568093a9 100644 --- a/pyinstrument/__main__.py +++ b/pyinstrument/__main__.py @@ -421,8 +421,11 @@ 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 @@ -430,13 +433,16 @@ def compute_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: @@ -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}) diff --git a/pyinstrument/magic/magic.py b/pyinstrument/magic/magic.py index e5ed5880..25fabe8f 100644 --- a/pyinstrument/magic/magic.py +++ b/pyinstrument/magic/magic.py @@ -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) diff --git a/test/test_cmdline.py b/test/test_cmdline.py index c787c1ae..d3f7f02d 100644 --- a/test/test_cmdline.py +++ b/test/test_cmdline.py @@ -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)