From da5756d213aa635d776cbe8bd60ceb81a691233a Mon Sep 17 00:00:00 2001 From: Ricardo Newbery Date: Mon, 24 Apr 2023 18:35:00 -0600 Subject: [PATCH 1/2] Add hyperlink to console output --- coverage/html.py | 10 +++++++++- coverage/report.py | 8 +++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/coverage/html.py b/coverage/html.py index 570760604..806192b62 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -13,6 +13,7 @@ import re import shutil import string # pylint: disable=deprecated-module +import sys from dataclasses import dataclass from typing import Any, Dict, Iterable, List, Optional, Tuple, TYPE_CHECKING, cast @@ -493,7 +494,14 @@ def index_file(self, first_html: str, final_html: str) -> None: index_file = os.path.join(self.directory, "index.html") write_html(index_file, html) - self.coverage._message(f"Wrote HTML report to {index_file}") + + if os.isatty(sys.stdout.fileno()): + file_path = f"file://{os.path.abspath(index_file)}" + print_path = f"\033]8;;{file_path}\a{index_file}\033]8;;\a" + else: + print_path = index_file + + self.coverage._message(f"Wrote HTML report to {print_path}") # Write the latest hashes for next time. self.incr.write() diff --git a/coverage/report.py b/coverage/report.py index 09eed0a82..c4429345c 100644 --- a/coverage/report.py +++ b/coverage/report.py @@ -5,6 +5,7 @@ from __future__ import annotations +import os import sys from typing import Callable, Iterable, Iterator, IO, Optional, Tuple, TYPE_CHECKING @@ -58,7 +59,12 @@ def render_report( try: ret = reporter.report(morfs, outfile=outfile) if file_to_close is not None: - msgfn(f"Wrote {reporter.report_type} to {output_path}") + if os.isatty(sys.stdout.fileno()): + file_path = f"file://{os.path.abspath(output_path)}" + print_path = f"\033]8;;{file_path}\a{output_path}\033]8;;\a" + else: + print_path = output_path + msgfn(f"Wrote {reporter.report_type} to {print_path}") delete_file = False return ret finally: From 4561ddf06ad68325c5194b601dfdce11778ab494 Mon Sep 17 00:00:00 2001 From: Ricardo Newbery Date: Tue, 25 Apr 2023 11:45:16 -0600 Subject: [PATCH 2/2] python 3.7 compat version of detecting console tty --- coverage/html.py | 2 +- coverage/report.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/coverage/html.py b/coverage/html.py index 806192b62..4e594343c 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -495,7 +495,7 @@ def index_file(self, first_html: str, final_html: str) -> None: index_file = os.path.join(self.directory, "index.html") write_html(index_file, html) - if os.isatty(sys.stdout.fileno()): + if sys.stdout.isatty(): file_path = f"file://{os.path.abspath(index_file)}" print_path = f"\033]8;;{file_path}\a{index_file}\033]8;;\a" else: diff --git a/coverage/report.py b/coverage/report.py index c4429345c..1e14eb78e 100644 --- a/coverage/report.py +++ b/coverage/report.py @@ -59,7 +59,7 @@ def render_report( try: ret = reporter.report(morfs, outfile=outfile) if file_to_close is not None: - if os.isatty(sys.stdout.fileno()): + if sys.stdout.isatty(): file_path = f"file://{os.path.abspath(output_path)}" print_path = f"\033]8;;{file_path}\a{output_path}\033]8;;\a" else: