import a library from another vscode extension #21284
-
Hi I am screening an exension for renpy. Renpy is written in python and gives the possibility to develop with phython language by importing a library called renpy. so my idea is to add the path to this library to vscode-python from my extension through its api. I know that you can do the following way to import them: // import python extension
let python = extensions.getExtension('ms-python.python');
let pythonApi = python?. Exports; the problem is that I don't know if there is a function that is right for me |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 11 replies
-
Greetings @donrp To add a path to the Python environment used by the VS Code Python extension, you can use the python.setExecutionDetails() method provided by the Python extension API. Here's an example of how you could use this method to add a path to the Python environment:
This code gets a reference to the Python extension API, and then calls the setExecutionDetails() method to add a path to the Python environment. The first argument to setExecutionDetails() is the name of the Python executable to modify (in this case, 'python'), and the second argument is an object that specifies the details to set for the executable. In this case, the object specifies a path property that contains the path to the Ren'Py library. Note that this code assumes that the Ren'Py library is installed on the same machine as VS Code, and that you know the path to the library. If the library is installed in a different location, or if you need to determine the path dynamically, you may need to modify this code accordingly. |
Beta Was this translation helpful? Give feedback.
-
The documentation for the API can be found in our wiki (we are also working towards creating an NPM package to make it easier to use).
I think you're referring to Pylance saying that the import doesn't exist? |
Beta Was this translation helpful? Give feedback.
-
Hi I read the wiki, and I tried in the following way. pythonApi.environments.updateActiveEnvironmentPath('renpy', sdkPath + "/renpy"); gives me the following error: rejected promise not handled within 1 second: TypeError: Cannot use 'in' operator to search for 'uri' in /home/user/renpy/renpy
extensionHostProcess.js:105
stack trace: TypeError: Cannot use 'in' operator to search for 'uri' in /home/user/renpy/renpy
at Object.updateActiveEnvironmentPath (/home/user/.vscode-server/extensions/ms-python.python-2023.8.0/out/client/extension.js:2:418681)
at /home/user/renpy-vscode/src/extension.ts:50:28
at processTicksAndRejections (node:internal/process/task_queues:96:5) I am not clear what the parameters refer to. in any case, I am not 100% sure that function my intention is to add this library which is in a specific folder in addition to the standard python ones. could someone confirm for me that |
Beta Was this translation helpful? Give feedback.
-
@donrp To do this programmatically through a VS Code extension, currently you can only make this work for things running in terminal. This is the API https://code.visualstudio.com/api/references/vscode-api#EnvironmentVariableCollection For intellisense, with either Jedi/Pylance, you can set the following setting programmatically To validate the path before you add setting do this:
We don't have an API that is generically make this work for all background process etc (that would be a feature request). But the above should get terminal runs. |
Beta Was this translation helpful? Give feedback.
@donrp To do this programmatically through a VS Code extension, currently you can only make this work for things running in terminal. This is the API https://code.visualstudio.com/api/references/vscode-api#EnvironmentVariableCollection
For intellisense, with either Jedi/Pylance, you can set the following setting programmatically
python.autoComplete.extraPaths
to include the path to renpy. This path should be similar to what you would do with PYTHONPATH.From your screen shot and messages it should likely be like this:
"python.autoComplete.extraPaths": ["/home/user/renpy"]
.To validate the path before you add setting do this:
W…