svaante / dape

Debug Adapter Protocol for Emacs
GNU General Public License v3.0
448 stars 25 forks source link

python sys.path does not include the project root when running in a subfolder #114

Closed zhenhua-wang closed 1 month ago

zhenhua-wang commented 2 months ago

Thank you for this very useful package!

I find this behavior when dape is started from an sub-folder in a project. Although cwd and command-cwd point to the project root, the sys.path variable in python does not include the project root, instead it has the current directory (the subfolder). I wonder if I change this and include the project root in sys.path for dape repl?

svaante commented 2 months ago

Hey, sorry for the late response. I think I have found the issue, if you specify the :program using an absolute path instead of an relative like the default configuration sys.path contains the expected file path. This is an debugy bug, one would expect cwd to affect the value of sys.path.

bild
zhenhua-wang commented 2 months ago

Thanks for checking. Sorry, I didn't describe my situation clearly. I have a test.py in a subfolder called test. When I run dape on this test.py, Sys.path points to the test subfolder. Since the test file imports functions from lib/lib.py, it needs to be run from the root folder to correctly resolve the path. My current fix for this is to add os.getcwd() to Sys.Path manually at the beginning of the test file. I wonder if there is a way in dape to make it point to the root folder as well?

My project structure looks like this.

root/
    lib/
        lib.py
    test/
        test.py
    main.py
svaante commented 1 month ago

Ah I see, this has nothing to do with dape but with how sys.path works, AFAIK cwd has no affect on sys.path.

zhenhua-wang commented 1 month ago

Thanks for the explain! Your first solution works great for me.