11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT License.
33
4- import { Disposable , EventEmitter , Event , Uri , LogOutputChannel } from 'vscode' ;
4+ import { Disposable , EventEmitter , Event , Uri } from 'vscode' ;
55import * as ch from 'child_process' ;
66import * as path from 'path' ;
77import * as rpc from 'vscode-jsonrpc/node' ;
@@ -16,9 +16,8 @@ import { CONDAPATH_SETTING_KEY } from '../../../common/environmentManagers/conda
1616import { VENVFOLDERS_SETTING_KEY , VENVPATH_SETTING_KEY } from '../lowLevel/customVirtualEnvLocator' ;
1717import { getUserHomeDir } from '../../../../common/utils/platform' ;
1818import { createLogOutputChannel } from '../../../../common/vscodeApis/windowApis' ;
19- import { PythonEnvKind } from '../../info' ;
2019import { sendNativeTelemetry , NativePythonTelemetry } from './nativePythonTelemetry' ;
21- import { traceError } from '../../../../logging ' ;
20+ import { NativePythonEnvironmentKind } from './nativePythonUtils ' ;
2221
2322const untildify = require ( 'untildify' ) ;
2423
@@ -30,7 +29,7 @@ export interface NativeEnvInfo {
3029 displayName ?: string ;
3130 name ?: string ;
3231 executable ?: string ;
33- kind ?: PythonEnvironmentKind ;
32+ kind ?: NativePythonEnvironmentKind ;
3433 version ?: string ;
3534 prefix ?: string ;
3635 manager ?: NativeEnvManagerInfo ;
@@ -42,32 +41,13 @@ export interface NativeEnvInfo {
4241 symlinks ?: string [ ] ;
4342}
4443
45- export enum PythonEnvironmentKind {
46- Conda = 'Conda' ,
47- Homebrew = 'Homebrew' ,
48- Pyenv = 'Pyenv' ,
49- GlobalPaths = 'GlobalPaths' ,
50- PyenvVirtualEnv = 'PyenvVirtualEnv' ,
51- Pipenv = 'Pipenv' ,
52- Poetry = 'Poetry' ,
53- MacPythonOrg = 'MacPythonOrg' ,
54- MacCommandLineTools = 'MacCommandLineTools' ,
55- LinuxGlobal = 'LinuxGlobal' ,
56- MacXCode = 'MacXCode' ,
57- Venv = 'Venv' ,
58- VirtualEnv = 'VirtualEnv' ,
59- VirtualEnvWrapper = 'VirtualEnvWrapper' ,
60- WindowsStore = 'WindowsStore' ,
61- WindowsRegistry = 'WindowsRegistry' ,
62- }
63-
6444export interface NativeEnvManagerInfo {
6545 tool : string ;
6646 executable : string ;
6747 version ?: string ;
6848}
6949
70- export function isNativeInfoEnvironment ( info : NativeEnvInfo | NativeEnvManagerInfo ) : info is NativeEnvInfo {
50+ export function isNativeEnvInfo ( info : NativeEnvInfo | NativeEnvManagerInfo ) : info is NativeEnvInfo {
7151 if ( ( info as NativeEnvManagerInfo ) . tool ) {
7252 return false ;
7353 }
@@ -92,63 +72,26 @@ export interface NativePythonFinder extends Disposable {
9272 *
9373 * If a Uri is provided, then it will search for python environments in that location (ignoring workspaces).
9474 * Uri can be a file or a folder.
95- * If a PythonEnvironmentKind is provided, then it will search for python environments of that kind (ignoring workspaces).
75+ * If a NativePythonEnvironmentKind is provided, then it will search for python environments of that kind (ignoring workspaces).
9676 */
97- refresh ( options ?: PythonEnvironmentKind | Uri [ ] ) : AsyncIterable < NativeEnvInfo | NativeEnvManagerInfo > ;
77+ refresh ( options ?: NativePythonEnvironmentKind | Uri [ ] ) : AsyncIterable < NativeEnvInfo | NativeEnvManagerInfo > ;
9878 /**
9979 * Will spawn the provided Python executable and return information about the environment.
10080 * @param executable
10181 */
10282 resolve ( executable : string ) : Promise < NativeEnvInfo > ;
103- categoryToKind ( category ?: PythonEnvironmentKind ) : PythonEnvKind ;
10483 /**
10584 * Used only for telemetry.
10685 */
10786 getCondaInfo ( ) : Promise < NativeCondaInfo > ;
10887}
10988
110- const mapping = new Map < PythonEnvironmentKind , PythonEnvKind > ( [
111- [ PythonEnvironmentKind . Conda , PythonEnvKind . Conda ] ,
112- [ PythonEnvironmentKind . GlobalPaths , PythonEnvKind . OtherGlobal ] ,
113- [ PythonEnvironmentKind . Pyenv , PythonEnvKind . Pyenv ] ,
114- [ PythonEnvironmentKind . PyenvVirtualEnv , PythonEnvKind . Pyenv ] ,
115- [ PythonEnvironmentKind . Pipenv , PythonEnvKind . Pipenv ] ,
116- [ PythonEnvironmentKind . Poetry , PythonEnvKind . Poetry ] ,
117- [ PythonEnvironmentKind . VirtualEnv , PythonEnvKind . VirtualEnv ] ,
118- [ PythonEnvironmentKind . VirtualEnvWrapper , PythonEnvKind . VirtualEnvWrapper ] ,
119- [ PythonEnvironmentKind . Venv , PythonEnvKind . Venv ] ,
120- [ PythonEnvironmentKind . WindowsRegistry , PythonEnvKind . System ] ,
121- [ PythonEnvironmentKind . WindowsStore , PythonEnvKind . MicrosoftStore ] ,
122- [ PythonEnvironmentKind . Homebrew , PythonEnvKind . System ] ,
123- [ PythonEnvironmentKind . LinuxGlobal , PythonEnvKind . System ] ,
124- [ PythonEnvironmentKind . MacCommandLineTools , PythonEnvKind . System ] ,
125- [ PythonEnvironmentKind . MacPythonOrg , PythonEnvKind . System ] ,
126- [ PythonEnvironmentKind . MacXCode , PythonEnvKind . System ] ,
127- ] ) ;
128-
129- export function categoryToKind ( category ?: PythonEnvironmentKind , logger ?: LogOutputChannel ) : PythonEnvKind {
130- if ( ! category ) {
131- return PythonEnvKind . Unknown ;
132- }
133- const kind = mapping . get ( category ) ;
134- if ( kind ) {
135- return kind ;
136- }
137-
138- if ( logger ) {
139- logger . error ( `Unknown Python Environment category '${ category } ' from Native Locator.` ) ;
140- } else {
141- traceError ( `Unknown Python Environment category '${ category } ' from Native Locator.` ) ;
142- }
143- return PythonEnvKind . Unknown ;
144- }
145-
14689interface NativeLog {
14790 level : string ;
14891 message : string ;
14992}
15093
151- class NativeGlobalPythonFinderImpl extends DisposableBase implements NativePythonFinder {
94+ class NativePythonFinderImpl extends DisposableBase implements NativePythonFinder {
15295 private readonly connection : rpc . MessageConnection ;
15396
15497 private firstRefreshResults : undefined | ( ( ) => AsyncGenerator < NativeEnvInfo , void , unknown > ) ;
@@ -172,11 +115,7 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativePytho
172115 return environment ;
173116 }
174117
175- categoryToKind ( category ?: PythonEnvironmentKind ) : PythonEnvKind {
176- return categoryToKind ( category , this . outputChannel ) ;
177- }
178-
179- async * refresh ( options ?: PythonEnvironmentKind | Uri [ ] ) : AsyncIterable < NativeEnvInfo > {
118+ async * refresh ( options ?: NativePythonEnvironmentKind | Uri [ ] ) : AsyncIterable < NativeEnvInfo > {
180119 if ( this . firstRefreshResults ) {
181120 // If this is the first time we are refreshing,
182121 // Then get the results from the first refresh.
@@ -322,7 +261,7 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativePytho
322261 }
323262
324263 private doRefresh (
325- options ?: PythonEnvironmentKind | Uri [ ] ,
264+ options ?: NativePythonEnvironmentKind | Uri [ ] ,
326265 ) : { completed : Promise < void > ; discovered : Event < NativeEnvInfo | NativeEnvManagerInfo > } {
327266 const disposable = this . _register ( new DisposableStore ( ) ) ;
328267 const discovered = disposable . add ( new EventEmitter < NativeEnvInfo | NativeEnvManagerInfo > ( ) ) ;
@@ -384,7 +323,7 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativePytho
384323 ) ;
385324
386325 type RefreshOptions = {
387- searchKind ?: PythonEnvironmentKind ;
326+ searchKind ?: NativePythonEnvironmentKind ;
388327 searchPaths ?: string [ ] ;
389328 } ;
390329
@@ -423,6 +362,7 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativePytho
423362 environmentDirectories : getCustomVirtualEnvDirs ( ) ,
424363 condaExecutable : getPythonSettingAndUntildify < string > ( CONDAPATH_SETTING_KEY ) ,
425364 poetryExecutable : getPythonSettingAndUntildify < string > ( 'poetryPath' ) ,
365+ // We don't use pipenvPath as it is not used for discovery
426366 } ;
427367 // No need to send a configuration request, is there are no changes.
428368 if ( JSON . stringify ( options ) === JSON . stringify ( this . lastConfiguration || { } ) ) {
@@ -480,7 +420,7 @@ function getPythonSettingAndUntildify<T>(name: string, scope?: Uri): T | undefin
480420let _finder : NativePythonFinder | undefined ;
481421export function getNativePythonFinder ( ) : NativePythonFinder {
482422 if ( ! _finder ) {
483- _finder = new NativeGlobalPythonFinderImpl ( ) ;
423+ _finder = new NativePythonFinderImpl ( ) ;
484424 }
485425 return _finder ;
486426}
0 commit comments