1
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
2
// Licensed under the MIT License.
3
3
4
- import { Disposable , EventEmitter , Event , Uri , LogOutputChannel } from 'vscode' ;
4
+ import { Disposable , EventEmitter , Event , Uri } from 'vscode' ;
5
5
import * as ch from 'child_process' ;
6
6
import * as path from 'path' ;
7
7
import * as rpc from 'vscode-jsonrpc/node' ;
@@ -16,9 +16,8 @@ import { CONDAPATH_SETTING_KEY } from '../../../common/environmentManagers/conda
16
16
import { VENVFOLDERS_SETTING_KEY , VENVPATH_SETTING_KEY } from '../lowLevel/customVirtualEnvLocator' ;
17
17
import { getUserHomeDir } from '../../../../common/utils/platform' ;
18
18
import { createLogOutputChannel } from '../../../../common/vscodeApis/windowApis' ;
19
- import { PythonEnvKind } from '../../info' ;
20
19
import { sendNativeTelemetry , NativePythonTelemetry } from './nativePythonTelemetry' ;
21
- import { traceError } from '../../../../logging ' ;
20
+ import { NativePythonEnvironmentKind } from './nativePythonUtils ' ;
22
21
23
22
const untildify = require ( 'untildify' ) ;
24
23
@@ -30,7 +29,7 @@ export interface NativeEnvInfo {
30
29
displayName ?: string ;
31
30
name ?: string ;
32
31
executable ?: string ;
33
- kind ?: PythonEnvironmentKind ;
32
+ kind ?: NativePythonEnvironmentKind ;
34
33
version ?: string ;
35
34
prefix ?: string ;
36
35
manager ?: NativeEnvManagerInfo ;
@@ -42,32 +41,13 @@ export interface NativeEnvInfo {
42
41
symlinks ?: string [ ] ;
43
42
}
44
43
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
-
64
44
export interface NativeEnvManagerInfo {
65
45
tool : string ;
66
46
executable : string ;
67
47
version ?: string ;
68
48
}
69
49
70
- export function isNativeInfoEnvironment ( info : NativeEnvInfo | NativeEnvManagerInfo ) : info is NativeEnvInfo {
50
+ export function isNativeEnvInfo ( info : NativeEnvInfo | NativeEnvManagerInfo ) : info is NativeEnvInfo {
71
51
if ( ( info as NativeEnvManagerInfo ) . tool ) {
72
52
return false ;
73
53
}
@@ -92,63 +72,26 @@ export interface NativePythonFinder extends Disposable {
92
72
*
93
73
* If a Uri is provided, then it will search for python environments in that location (ignoring workspaces).
94
74
* 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).
96
76
*/
97
- refresh ( options ?: PythonEnvironmentKind | Uri [ ] ) : AsyncIterable < NativeEnvInfo | NativeEnvManagerInfo > ;
77
+ refresh ( options ?: NativePythonEnvironmentKind | Uri [ ] ) : AsyncIterable < NativeEnvInfo | NativeEnvManagerInfo > ;
98
78
/**
99
79
* Will spawn the provided Python executable and return information about the environment.
100
80
* @param executable
101
81
*/
102
82
resolve ( executable : string ) : Promise < NativeEnvInfo > ;
103
- categoryToKind ( category ?: PythonEnvironmentKind ) : PythonEnvKind ;
104
83
/**
105
84
* Used only for telemetry.
106
85
*/
107
86
getCondaInfo ( ) : Promise < NativeCondaInfo > ;
108
87
}
109
88
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
-
146
89
interface NativeLog {
147
90
level : string ;
148
91
message : string ;
149
92
}
150
93
151
- class NativeGlobalPythonFinderImpl extends DisposableBase implements NativePythonFinder {
94
+ class NativePythonFinderImpl extends DisposableBase implements NativePythonFinder {
152
95
private readonly connection : rpc . MessageConnection ;
153
96
154
97
private firstRefreshResults : undefined | ( ( ) => AsyncGenerator < NativeEnvInfo , void , unknown > ) ;
@@ -172,11 +115,7 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativePytho
172
115
return environment ;
173
116
}
174
117
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 > {
180
119
if ( this . firstRefreshResults ) {
181
120
// If this is the first time we are refreshing,
182
121
// Then get the results from the first refresh.
@@ -322,7 +261,7 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativePytho
322
261
}
323
262
324
263
private doRefresh (
325
- options ?: PythonEnvironmentKind | Uri [ ] ,
264
+ options ?: NativePythonEnvironmentKind | Uri [ ] ,
326
265
) : { completed : Promise < void > ; discovered : Event < NativeEnvInfo | NativeEnvManagerInfo > } {
327
266
const disposable = this . _register ( new DisposableStore ( ) ) ;
328
267
const discovered = disposable . add ( new EventEmitter < NativeEnvInfo | NativeEnvManagerInfo > ( ) ) ;
@@ -384,7 +323,7 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativePytho
384
323
) ;
385
324
386
325
type RefreshOptions = {
387
- searchKind ?: PythonEnvironmentKind ;
326
+ searchKind ?: NativePythonEnvironmentKind ;
388
327
searchPaths ?: string [ ] ;
389
328
} ;
390
329
@@ -423,6 +362,7 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativePytho
423
362
environmentDirectories : getCustomVirtualEnvDirs ( ) ,
424
363
condaExecutable : getPythonSettingAndUntildify < string > ( CONDAPATH_SETTING_KEY ) ,
425
364
poetryExecutable : getPythonSettingAndUntildify < string > ( 'poetryPath' ) ,
365
+ // We don't use pipenvPath as it is not used for discovery
426
366
} ;
427
367
// No need to send a configuration request, is there are no changes.
428
368
if ( JSON . stringify ( options ) === JSON . stringify ( this . lastConfiguration || { } ) ) {
@@ -480,7 +420,7 @@ function getPythonSettingAndUntildify<T>(name: string, scope?: Uri): T | undefin
480
420
let _finder : NativePythonFinder | undefined ;
481
421
export function getNativePythonFinder ( ) : NativePythonFinder {
482
422
if ( ! _finder ) {
483
- _finder = new NativeGlobalPythonFinderImpl ( ) ;
423
+ _finder = new NativePythonFinderImpl ( ) ;
484
424
}
485
425
return _finder ;
486
426
}
0 commit comments