I wish to inspect the code inside a (pip installed) module that I've imported (called transformers if it is relevant). So right now what I am doing is putting breakpoint()
where relevant in the site_package location and calling the module inside test.py
.
from transformers import AutoModel, AutoTokenizer, EncoderDecoderModel
However, Ideally I wish to set and remove breakpoints on the fly as I inspect the code, as I could normally do with a python module I wrote. Wondering if there is something similar for external libraries.
Alternate Solution
I would equally be happy if I could write breakpoint()
where I need it to be on the fly. I used to do this with Jupyter with my own modules by adding the following two lines:
%load_ext autoreload
%autoreload 2
However, this did not work for an external library when I added in new breakpoints.
CodePudding user response:
Use an IDE such as PyCharm or Visual Studio Code.
I use Jetbrains CLion that allows me to view external libraries code by right clicking -> Go To -> Declaration or usage.
See this answer.
To do your breakpoint() function, you will have to modify the external library code.
As mentionned here, you should never modify an external library code. Alternatively, with an IDE you will be able to put breakpoints by clicking the line where you want to put a breakpoint.
But if you still want to edit the code, you should install the module with the -e option.
CodePudding user response:
You can add "justMyCode": false,
in the launch.json file as the default value of it is true.
You can refer to here for more details.