Fix incorrectly converting relative to absolute of files and always show paths in traceback in case file cannot be found #3429
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Type of changes
Checklist
Description
Currently Rich assumes that if a path in a traceback frame is relative, that it's relative to the current working directory. This is not the case when the Python application is running from a packaged bundle like a PAR. In these cases the traceback loses the path information or the incorrect absolute path is used. This PR makes it so:
Frame.filename
is not absolute if the original filename does not exist in the first place. That would indicate that it's not relative to the current working directory.I was considering replacing
rich.__init__._IMPORT_CWD
's value to one that is reflective of__file__
though that resulted in filenames relative to/proc
. Those are not readable and this might change other expectations.The
linecache
module understands the relative paths and even sometimes can give the lines inside of the PAR. (Though sometimes it cannot and I'm not sure when it can and cannot.) Regardless, this means we at least see some lines and also always see the location.