@@ -7,13 +7,13 @@ import * as path from 'path';
77import { chain , iterable } from '../../../../common/utils/async' ;
88import { PythonEnvKind } from '../../info' ;
99import { BasicEnvInfo , IPythonEnvsIterator } from '../../locator' ;
10- import { FSWatcherKind , FSWatchingLocator } from './fsWatchingLocator' ;
1110import { getInterpreterPathFromDir } from '../../../common/commonUtils' ;
1211import { pathExists } from '../../../common/externalDependencies' ;
1312import { isPoetryEnvironment , localPoetryEnvDirName , Poetry } from '../../../common/environmentManagers/poetry' ;
1413import '../../../../common/extensions' ;
1514import { asyncFilter } from '../../../../common/utils/arrayUtils' ;
1615import { traceError , traceVerbose } from '../../../../logging' ;
16+ import { LazyResourceBasedLocator } from '../common/resourceBasedLocator' ;
1717
1818/**
1919 * Gets all default virtual environment locations to look for in a workspace.
@@ -28,27 +28,6 @@ async function getVirtualEnvDirs(root: string): Promise<string[]> {
2828 return asyncFilter ( envDirs , pathExists ) ;
2929}
3030
31- async function getRootVirtualEnvDir ( root : string ) : Promise < string [ ] > {
32- const rootDirs = [ ] ;
33- const poetry = await Poetry . getPoetry ( root ) ;
34- /**
35- * We can infer the directory in which the existing poetry environments are created to determine
36- * the root virtual env dir. If no virtual envs are created yet, then fetch the setting value to
37- * get the root directory instead. We prefer to use 'poetry env list' command first because the
38- * result of that command is already cached when getting poetry.
39- */
40- const virtualenvs = await poetry ?. getEnvList ( ) ;
41- if ( virtualenvs ?. length ) {
42- rootDirs . push ( path . dirname ( virtualenvs [ 0 ] ) ) ;
43- } else {
44- const setting = await poetry ?. getVirtualenvsPathSetting ( ) ;
45- if ( setting ) {
46- rootDirs . push ( setting ) ;
47- }
48- }
49- return rootDirs ;
50- }
51-
5231async function getVirtualEnvKind ( interpreterPath : string ) : Promise < PythonEnvKind > {
5332 if ( await isPoetryEnvironment ( interpreterPath ) ) {
5433 return PythonEnvKind . Poetry ;
@@ -60,16 +39,11 @@ async function getVirtualEnvKind(interpreterPath: string): Promise<PythonEnvKind
6039/**
6140 * Finds and resolves virtual environments created using poetry.
6241 */
63- export class PoetryLocator extends FSWatchingLocator {
42+ export class PoetryLocator extends LazyResourceBasedLocator {
6443 public readonly providerId : string = 'poetry' ;
6544
6645 public constructor ( private readonly root : string ) {
67- super (
68- ( ) => getRootVirtualEnvDir ( root ) ,
69- async ( ) => PythonEnvKind . Poetry ,
70- undefined ,
71- FSWatcherKind . Workspace ,
72- ) ;
46+ super ( ) ;
7347 }
7448
7549 protected doIterEnvs ( ) : IPythonEnvsIterator < BasicEnvInfo > {
0 commit comments