Replies: 3 comments 2 replies
-
Some terminals turn FILE:LINE in to a clickable link, but will generally not know how to handle Python tracebacks. PyCharm is obviously aware of Python tracebacks and knows how to extract path and link. Unfortunately if I make it work in PyCharm, it would break clickable links in the terminal. I could be persuaded to add a PyCharm mode for tracebacks to get the best of both worlds. BTW you might want to check the note in the docs about PyCharm, you may be able to get even prettier tracebacks. |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for the tip! I think I'll open an issue on the PyCharm side, there is a problem with their regexp: This is correctly recognized: print('FILE:LINE') This is not: print('| FILE:LINE') |
Beta Was this translation helpful? Give feedback.
-
Thanks to lucmos' comment I was able to do a monkey-patch that can be placed eg in django's settings.py import rich.box
import rich.traceback
from rich.panel import Panel
panel_init_original = Panel.__init__
def panel_init_fixed(self, *args, **kwargs):
is_traceback_panel = "Traceback" in kwargs.get("title", "")
if is_traceback_panel:
box_pycharm_compatible = rich.box.MINIMAL_DOUBLE_HEAD
kwargs["box"] = box_pycharm_compatible
for arg in args:
# handle rich code that passes Box as a positional arg
if isinstance(arg, rich.box.Box):
args = list(args)
args.remove(arg)
args = tuple(args)
panel_init_original(self, *args, **kwargs)
Panel.__init__ = panel_init_fixed
rich.traceback.install(with=300) |
Beta Was this translation helpful? Give feedback.
-
Hello,
I'd like to use the pretty tracebacks in PyCharm.
Currently, my traceback looks like this:
It's uglier than the rich's tracebacks, but it contains "links" that let the editor jump directly to the file and line in question.
Using rich, the path is still there:
But, it is not clickable anymore.
Do you know how can I make the links work?
There is a regexp in PyCharm that catches the pattern
The line number is optional, e.g. this opens the file manager correctly
Unfortunately at the moment, I can't find a way to change the regexp or change the formatting in the rich output. Is there?
Adding the
File
keyword and some quotes is enough to make it work (correctly, even if the underlying is wrong)Beta Was this translation helpful? Give feedback.
All reactions