File tree 3 files changed +25
-4
lines changed 3 files changed +25
-4
lines changed Original file line number Diff line number Diff line change 4
4
# ##############################################################################################
5
5
name : $(Date:yyyyMMdd)$(Rev:.r)
6
6
7
+ trigger : none
8
+
7
9
pr : none
8
10
9
11
resources :
Original file line number Diff line number Diff line change @@ -4,8 +4,6 @@ This npm module implements an API facade for the Python extension in VS Code.
4
4
5
5
## Example
6
6
7
- The source code of the example can be found [ here] (TODO Update example extension link here)
8
-
9
7
First we need to define a ` package.json ` for the extension that wants to use the API:
10
8
11
9
``` jsonc
@@ -24,8 +22,29 @@ First we need to define a `package.json` for the extension that wants to use the
24
22
}
25
23
```
26
24
27
- TODO insert example here
25
+ The actual source code to get the active environment to run some script could look like this:
28
26
29
27
``` typescript
30
- TODO
28
+ // Import the API
29
+ import { PythonExtension } from ' @vscode/python-extension' ;
30
+
31
+ // Load the Python extension API
32
+ const pythonApi: PythonExtension = await PythonExtension .api ();
33
+
34
+ // This will return something like /usr/bin/python
35
+ const environmentPath = pythonApi .environments .getActiveEnvironmentPath ();
36
+
37
+ // `environmentPath.path` carries the value of the setting. Note that this path may point to a folder and not the
38
+ // python binary. Depends entirely on how the env was created.
39
+ // E.g., `conda create -n myenv python` ensures the env has a python binary
40
+ // `conda create -n myenv` does not include a python binary.
41
+ // Also, the path specified may not be valid, use the following to get complete details for this environment if
42
+ // need be.
43
+
44
+ const environment = await pythonApi .environments .resolveEnvironment (environmentPath );
45
+ if (environment ) {
46
+ // run your script here.
47
+ }
31
48
```
49
+
50
+ Check out [ the wiki] ( https://aka.ms/pythonEnvironmentApi ) for many more examples and usage.
You can’t perform that action at this time.
0 commit comments