Skip to content
Merged
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
5 changes: 2 additions & 3 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,9 @@ export interface PythonEnvironmentInfo {
readonly iconPath?: IconPath;

/**
* Information on how to execute the Python environment. If not provided, {@link PythonEnvironmentApi.resolveEnvironment} will be
* used to to get the details at later point if needed. The recommendation is to fill this in if known.
* Information on how to execute the Python environment. This is required for executing Python code in the environment.
*/
readonly execInfo?: PythonEnvironmentExecutionInfo;
readonly execInfo: PythonEnvironmentExecutionInfo;

/**
* `sys.prefix` is the path to the base directory of the Python installation. Typically obtained by executing `sys.prefix` in the Python interpreter.
Expand Down
1 change: 1 addition & 0 deletions src/features/pythonApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class PythonEnvironmentApiImpl implements PythonEnvironmentApi {
};
return new PythonEnvironmentImpl(envId, info);
}

async createEnvironment(scope: CreateEnvironmentScope): Promise<PythonEnvironment | undefined> {
if (scope === 'global' || (!Array.isArray(scope) && scope instanceof Uri)) {
const manager = this.envManagers.getEnvironmentManager(scope === 'global' ? undefined : scope);
Expand Down
2 changes: 1 addition & 1 deletion src/internal.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export class PythonEnvironmentImpl implements PythonEnvironment {
public readonly description?: string;
public readonly tooltip?: string | MarkdownString;
public readonly iconPath?: IconPath;
public readonly execInfo?: PythonEnvironmentExecutionInfo;
public readonly execInfo: PythonEnvironmentExecutionInfo;
public readonly sysPrefix: string;

constructor(public readonly envId: PythonEnvironmentId, info: PythonEnvironmentInfo) {
Expand Down
8 changes: 8 additions & 0 deletions src/managers/sysPython/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ export async function installPackages(
api: PythonEnvironmentApi,
manager: PackageManager,
): Promise<Package[]> {
if (environment.version.startsWith('2.')) {
throw new Error('Python 2.* is not supported (deprecated)');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also show some kind of warning via UI too?

}

if (environment.execInfo) {
if (packages.length === 0) {
throw new Error('No packages selected to install');
Expand Down Expand Up @@ -350,6 +354,10 @@ export async function uninstallPackages(
manager: PackageManager,
packages: string[] | Package[],
): Promise<Package[]> {
if (environment.version.startsWith('2.')) {
throw new Error('Python 2.* is not supported (deprecated)');
}

if (environment.execInfo) {
const remove = [];
for (let pkg of packages) {
Expand Down
19 changes: 17 additions & 2 deletions src/managers/sysPython/venvUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,20 +254,35 @@ export async function createPythonVenv(
basePythons: PythonEnvironment[],
venvRoot: Uri,
): Promise<PythonEnvironment | undefined> {
const filtered = basePythons.filter((e) => e.execInfo);
if (filtered.length === 0) {
if (basePythons.length === 0) {
log.error('No base python found');
showErrorMessage('No base python found');
return;
}

const filtered = basePythons.filter((e) => e.version.startsWith('3.'));
if (filtered.length === 0) {
log.error('Did not find any base python 3.*');
showErrorMessage('Did not find any base python 3.*');
basePythons.forEach((e) => {
log.error(`available base python: ${e.version}`);
});
return;
}

const basePython = await pickEnvironmentFrom(sortEnvironments(filtered));
if (!basePython || !basePython.execInfo) {
log.error('No base python selected, cannot create virtual environment.');
showErrorMessage('No base python selected, cannot create virtual environment.');
return;
}

if (basePython.version.startsWith('2.')) {
log.error('Python 2.* is not supported for virtual env creation');
showErrorMessage('Python 2.* is not supported, use Python 3.*');
return;
}

const name = await showInputBox({
prompt: 'Enter name for virtual environment',
value: '.venv',
Expand Down
Loading