Feature Request: Traceback Show Locals
As a hatch plugin developer I'll occasionally come across an issue reported from a user that contains hatch traceback - the traceback provided by rich has been super helpful but there are situations where I'd like additional output. The show_locals option is very verbose but there are some situations where I'd like them to be included. The feature I'm suggesting is being able to toggle show_locals using the --verbose option (or maybe a new --debug flag?).
Rich API Docs: https://rich.readthedocs.io/en/stable/traceback.html?highlight=print_exception#printing-tracebacks
The show_locals=True parameter causes Rich to display the value of local variables for each frame of the traceback.
Hatch Usage: https://github.com/pypa/hatch/blob/6de802b882578e342bd5d397b8050b4b18574bc2/src/hatch/cli/init.py#L226
If you're interested I'd be happy to take a crack at this.
I would be interested but just FYI it would be a bit tricky because the code that you linked wraps the actual CLI argument parsing. This is also why I have not yet come up with a good way to extend CLI commands via plugins.
I would be interested but just FYI it would be a bit tricky because the code that you linked wraps the actual CLI argument parsing. This is also why I have not yet come up with a good way to extend CLI commands via plugins.
🤔 what if instead of the try/except -> print_exception we made use of the traceback handler from rich? https://github.com/pypa/hatch/compare/master...juftin:hatch:feat/rich_tracebacks
Side note, how do I get the formatting to work just how you prefer it? Running ruff format . gets close but there are still some diffs
That should work precisely if you are using the same version as the default https://github.com/pypa/hatch/blob/master/src/hatch/env/internal/static_analysis.py
How does the change affect responsiveness? https://github.com/pypa/hatch/blob/6de802b882578e342bd5d397b8050b4b18574bc2/.github/workflows/test.yml#L169
It takes the response time from ~ 98ms to ~107ms (looking at the latest run on pypa/hatch/master
https://github.com/juftin/hatch/actions/runs/7335489661/job/19973471718?pr=1
Not super happy about that but it's the only way so that's fine
Oh something else to watch out for would be the publishing stuff e.g. credentials might be saved as a variable
Not super happy about that but it's the only way so that's fine
I'd be just as happy to keep everything the same and enable show_locals with an environment variable like HATCH_DEBUG=1 too. Or even something like if "--verbose" in sys.argv...
An environment variable sounds nice if that's okay with you!
An environment variable sounds nice if that's okay with you!
Yep, absolutely. Here's what I was thinking https://github.com/pypa/hatch/compare/master...juftin:hatch:feat/rich_tracebacks