0

I want to modify some functionality in a python library available on github, therefore I have forked the repo on github and downloaded a copy to modify it. What I have been doing is pushing my modifications to my forked repo on github and then installing the library to my computer via pip install -e as described in this answer. This has been working perfectly fine to modify the library and then execute a script that runs it.

The problem comes when I have enough modifications I want to use VSCode's debug function to debug the code locally before pushing them. When running in debug mode, of course, any intermediate library imports of the original library (and my code has many of them) call the original name of the library (lets say XXX) with import XXX. This import goes to the pip installed version of XXX library in my computer and therefore doesn't use the version with local modification I have created.

This is of course impossible to debug locally, because my version of the library isn't even being used in most of the code, the imports are just calling the original package XXX which I have pip installed on my computer, so no breakpoints or other functions can be used.

The workaround I have done is renaming the folder of the modified local version (the one I have edited) to another name "XXX_debug" and changed all of the imports in the local copy to import XXX_debug and from XXX_debug.import .... This is working fine and I can use all debug capabilities.

This seems like kind of an overkill and makes things much more difficult in my pipeline, changing it from:

  • Fork- Download local copy - modify - push to my fork - install with pip install -e

to, in order to debug with vscode:

  • Fork- Download local copy - modify - change folder name and import names - debug - change back the names-push to my fork - install with pip install -e

¿Is there any better way to do this debugging or any other better way to perform this whole library modification operation?

bobyfisch
  • 11
  • 5
  • `virtualenv` once, set path to python to the virtual env.; `pip install .` (local, no push required) on every change. – phd Jun 01 '23 at 12:19

1 Answers1

0

My understanding of your issue is that the package version of your local machine is inconsistent with your project.

If the Python package in your Git project can be directly installed through command pip install, I suggest you create a virtual environment then install the package in this virtual environment.

Then use shortcuts "Ctrl+Shift+P" and type "Python: Select Interpreter" to choose this virtual environment.

If the package has been edited and cannot be installed by pip, you could try .env file or "env" in launch.json.

Solution about .env file:

You can create .env file under the workspace:

PYTHONPATH=PATH/TO/Package

Then add the following codes to your settings.json:

"python.envFile": "${workspaceFolder}/.env"

Solution about env in launch.json has been shown in document, you can refer to document for more detials.

MingJie-MSFT
  • 5,569
  • 1
  • 2
  • 13