Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README for Python extension API to point to examples #21638

Merged
merged 3 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions pythonExtensionApi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ This npm module implements an API facade for the Python extension in VS Code.

## Example

The source code of the example can be found [here](TODO Update example extension link here)

First we need to define a `package.json` for the extension that wants to use the API:

```jsonc
Expand All @@ -24,8 +22,26 @@ First we need to define a `package.json` for the extension that wants to use the
}
```

TODO insert example here
The actual source code to get the active environment to run some script could look like this:

```typescript
TODO
// Load the Python extension API
const pythonApi: PythonExtension = await PythonExtension.api();

// This will return something like /usr/bin/python
const environmentPath = pythonApi.environments.getActiveEnvironmentPath();

// `environmentPath.path` carries the value of the setting. Note that this path may point to a folder and not the
// python binary. Depends entirely on how the env was created.
// E.g., `conda create -n myenv python` ensures the env has a python binary
// `conda create -n myenv` does not include a python binary.
// Also, the path specified may not be valid, use the following to get complete details for this environment if
// need be.

const environment = await pythonApi.environments.resolveEnvironment(environmentPath);
if (environment) {
// run your script here.
}
```

Check out [the wiki](https://aka.ms/pythonEnvironmentApi) for many more examples and usage.
Empty file.