python sys.path does not include the project root when running in a subfolder
zhenhua-wang opened this issue · comments
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?
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
Ah I see, this has nothing to do with dape
but with how sys.path
works, AFAIK cwd
has no affect on sys.path
.
- Use env variable
PYTONPATH
likedebugpy :program "main.py" :env (:PYTHONPATH dape-cwd)
to addroot
folder tosys.path
- symlink your python package to
site-packages
withpip
and editable install see link - Use unittest module
debugpy-module :module "unittest" :args ["test.test"]
(make sure thatroot/test/__init__.py
exists)
Thanks for the explain! Your first solution works great for me.