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
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import * as path from 'path';
import { chain, iterable } from '../../../../common/utils/async';
import { PythonEnvKind } from '../../info';
import { BasicEnvInfo, IPythonEnvsIterator } from '../../locator';
import { FSWatcherKind, FSWatchingLocator } from './fsWatchingLocator';
import { getInterpreterPathFromDir } from '../../../common/commonUtils';
import { pathExists } from '../../../common/externalDependencies';
import { isPoetryEnvironment, localPoetryEnvDirName, Poetry } from '../../../common/environmentManagers/poetry';
import '../../../../common/extensions';
import { asyncFilter } from '../../../../common/utils/arrayUtils';
import { traceError, traceVerbose } from '../../../../logging';
import { LazyResourceBasedLocator } from '../common/resourceBasedLocator';

/**
* Gets all default virtual environment locations to look for in a workspace.
Expand All @@ -28,27 +28,6 @@ async function getVirtualEnvDirs(root: string): Promise<string[]> {
return asyncFilter(envDirs, pathExists);
}

async function getRootVirtualEnvDir(root: string): Promise<string[]> {
const rootDirs = [];
const poetry = await Poetry.getPoetry(root);
/**
* We can infer the directory in which the existing poetry environments are created to determine
* the root virtual env dir. If no virtual envs are created yet, then fetch the setting value to
* get the root directory instead. We prefer to use 'poetry env list' command first because the
* result of that command is already cached when getting poetry.
*/
const virtualenvs = await poetry?.getEnvList();
if (virtualenvs?.length) {
rootDirs.push(path.dirname(virtualenvs[0]));
} else {
const setting = await poetry?.getVirtualenvsPathSetting();
if (setting) {
rootDirs.push(setting);
}
}
return rootDirs;
}

async function getVirtualEnvKind(interpreterPath: string): Promise<PythonEnvKind> {
if (await isPoetryEnvironment(interpreterPath)) {
return PythonEnvKind.Poetry;
Expand All @@ -60,16 +39,11 @@ async function getVirtualEnvKind(interpreterPath: string): Promise<PythonEnvKind
/**
* Finds and resolves virtual environments created using poetry.
*/
export class PoetryLocator extends FSWatchingLocator {
export class PoetryLocator extends LazyResourceBasedLocator {
public readonly providerId: string = 'poetry';

public constructor(private readonly root: string) {
super(
() => getRootVirtualEnvDir(root),
async () => PythonEnvKind.Poetry,
undefined,
FSWatcherKind.Workspace,
);
super();
}

protected doIterEnvs(): IPythonEnvsIterator<BasicEnvInfo> {
Expand Down

This file was deleted.