Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 19 additions & 3 deletions extension/pyenv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import * as vscode from 'vscode';
import * as ini from 'ini';
import { DisposableContext } from './utils/disposableContext';
import { PythonExtension, ResolvedEnvironment } from '@vscode/python-extension';
import assert from 'assert';
import { Logger } from './logging';
import path from 'path';
import * as util from 'util';
Expand Down Expand Up @@ -160,7 +159,15 @@ export class PythonEnvironmentManager extends DisposableContext {
}

public async init() {
this.api = await PythonExtension.api();
try {
this.api = await PythonExtension.api();
} catch (e) {
this.logger.warn(
'The Python extension is not installed. ' +
'Install the Python extension (ms-python.python) to enable automatic SDK discovery.',
);
return;
}
this.pushSubscription(
this.api.environments.onDidChangeActiveEnvironmentPath((p) =>
this.handleEnvironmentChange(p.path),
Expand All @@ -181,7 +188,16 @@ export class PythonEnvironmentManager extends DisposableContext {

/// Finds the active SDK from the currently active Python environment, or undefined if one is not present.
public async findActiveSDK(): Promise<SDK | undefined> {
assert(this.api !== undefined);
if (!this.api) {
this.logger.error(
'Cannot discover SDK: the Python extension (ms-python.python) is not installed.',
);
await this.displaySDKError(
'The Python extension (ms-python.python) is required for automatic Mojo SDK discovery. ' +
'Please install it and restart the extension.',
);
return undefined;
}
// Prioritize retrieving a monorepo SDK over querying the environment.
const monorepoSDK = await this.tryGetMonorepoSDK();

Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
"onUri",
"onStartupFinished"
],
"extensionDependencies": [
"ms-python.python"
],
"main": "./out/extension.js",
"scripts": {
"vscode:prepublish": "npm run typecheck && npm run bundle",
Expand Down
Loading