PyCharm should detect relative paths in Analyze Stacktrace Follow
Answered
Hey all! I am on PyCharm Pro 2018.1.3.
I have noticed a behavioral oddity while attempting to use the Analyze Stack functionality with an external stack trace: PyCharm does not play well with relative paths. Easier to explain with an example:
Exhibit A works
File "/users/myuser/myproj/thing.py", line 50, in main
Exhibit B does not work
File "myproj/thing.py", line 50, in main
Am I misconfigured somewhere? How can I work around this? Is this something that might be remedied in a future version?
Cheers
Please sign in to leave a comment.
Hi bestsharper! Could you please provide a code snippet to generate such stacktrace?
Sure, easy enough.
Consider this basic code snippet:
Save it as test.py in your home directory (e.g. /Users/myuser/test.py).
Execute it: python /Users/myuser/test.py
You will receive the following stack:
You can now plug that into PyCharm with Analyze Stacktrace and have the code navigable to the exact line.
However, try mangling the path to the file making it different from where it is located on local (or at the time the stack was obtained):
- pretend you have deployed the code on a live env and replace /Users/myuser with a different path
- execute the code without a full path, aka python test.py which will omit the full path from the stack
- move the file to a new location before opening it
For example,
Plugging that stack in causes PyCharm to not perform any analysis.
The application here is analyzing stack traces not produced by local machine (e.g. other devs or prod/qa/other envs):
/my/local/dev/services/apis/foo.py
vs
/production/deploy/services/apis/foo.py
The issue here is that prod stacks will never match whatever the paths local dev might have. One work-around is to find-replace the part of the path that does not match, but it seems like an IDE ought to be able to do something with the info it has.
I'm experiencing the same frustration while using PyCharm on the host machine and running tests in a VM.
Reproduced the issue by changing script path in the run configuration from absolute to relative.
@Pavel Karateev
Do you have any input?
Please vote for the corresponding feature requests: