Closed Stewart86 closed 1 year ago
I don't know if there is a better way, but I am thinking if we parse pyproject.toml
for the extra paths and append it into venv.lua
that would work. however, I feel it's kind of hackish.
Yeah I agree. This week I'm starting a new job so won't have much free time, but if you have time and energy, please think about a good solution to this. I really like that you have some ideas already and maybe the hackish solution can be OK if we don't find another one for now....
See what you can come up with (if you have time of course).
Now that my PR #12 to resolve this issue have been merged into main. This issue is being resolved. Closing this for now!
As mentioned in #10. Opening a new ticket here to keep track of this issue.
Context
For some specific use case where
extraPaths
is defined in thepyproject.toml
(example below). After activating VenvSelect venv, pyright no longer respect the extra paths defined.pyproject.toml
Investigation
Even when
extraPaths
is declared in thelspconfig
as such.lspconfig.lua
However, when
extraPaths
is added intovenv.lua
venv.lua
Also, before activating VenvSelect pyright knows my extra paths but is not aware of the venv paths. Which was reflected with errors to the externally imported packages. As soon as venv is activated, the import errors switched from showing errors to my internal packages and nothing for the external packages.
To Replicate
This particular use case is mainly for building a AWS serverless application where Lambda Functions and Layer live in a separate runtime environment but stay in a single repository. Of cause there might be other use cases which I am not aware of. Directory structure looks similar to this.
directory tree
In normal circumstances
main.py
infunction_one/
folder should importutils.py
as suchmy_serverless_app/lambda_functions/function_one/main.py
But this will break on AWS Lambda runtime environment because the root directory is not being included into the runtime. So we can only import as such
my_serverless_app/lambda_functions/function_one/main.py
That means, we need to declare
extraPaths
inpyproject.toml
for pyright to know that we are directly importing from a particular folder.