nedbat / coveragepy

The code coverage tool for Python
https://coverage.readthedocs.io
Apache License 2.0
3k stars 429 forks source link

Add protocol for paths printed by xml/html subcommands #1523

Closed gaborbernat closed 1 year ago

gaborbernat commented 1 year ago

Currently, coverage xml/html report prints the path of the file written to stdout:

py311: commands[4]> coverage xml -o /home/bernat/git/virtualenv/.tox/coverage.py311.xml
Wrote XML report to /home/bernat/git/virtualenv/.tox/coverage.py311.xml
py311: commands[5]> coverage html -d /home/bernat/git/virtualenv/.tox/py311/tmp/htmlcov --show-contexts --title virtualenv-py311-coverage
Wrote HTML report to /home/bernat/git/virtualenv/.tox/py311/tmp/htmlcov/index.html

It would be great if we'd prepend the file:/ protocol prefix to this path so these links are clickable from the modern terminal, like iTerm or wezterm. I'm ok if it requires a flag to enable this behavior, as I can add that flag to tox.

See:

The file prefix enables integrated hyperlinks in all modern terminals.

Perhaps a better and more complicated alternative would be to hide it behind an extra and use rich to print integrated hyperlinks - see https://www.willmcgugan.com/blog/tech/post/real-working-hyperlinks-in-the-terminal-with-rich whenever tty is detected; this would allow to avoid the file prefix and also enable it for coverage report.

If you consider this feature out of scope for the core project, I'd request some way to achieve this via a plugin :blush:

newbery commented 1 year ago

Picking this up

nedbat commented 1 year ago

Are you sure you want .xml files to open this way? And if so, why not .json files?

gaborbernat commented 1 year ago

I'm only really interested in the HTML to be honest 😊

nedbat commented 1 year ago

This is implemented in 5f31ff9a thanks to #1613.

nedbat commented 1 year ago

This is now released as part of coverage 7.2.4.