summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Newbery <ric@digitalmarbles.com>2023-04-26 17:31:18 -0600
committerGitHub <noreply@github.com>2023-04-26 16:31:18 -0700
commit5f31ff9ae35cee27a25f4413664c0ac527fc3a15 (patch)
treeff8095c6e1935eab0be2ef20a4131c7c19553aca
parent74f179b591e57fe042bd510b07edcdedcacac624 (diff)
downloadpython-coveragepy-git-5f31ff9ae35cee27a25f4413664c0ac527fc3a15.tar.gz
feat: add hyperlink to console output (#1613)
* Add hyperlink to console output * python 3.7 compat version of detecting console tty
-rw-r--r--coverage/html.py10
-rw-r--r--coverage/report.py8
2 files changed, 16 insertions, 2 deletions
diff --git a/coverage/html.py b/coverage/html.py
index 57076060..4e594343 100644
--- a/coverage/html.py
+++ b/coverage/html.py
@@ -13,6 +13,7 @@ import os
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 @@ class HtmlReporter:
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 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:
+ 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 09eed0a8..1e14eb78 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 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:
+ print_path = output_path
+ msgfn(f"Wrote {reporter.report_type} to {print_path}")
delete_file = False
return ret
finally: