Skip to content

Commit d2646dc

Browse files
authored
More native tests for Native python finder (microsoft#23831)
1 parent a60f228 commit d2646dc

File tree

10 files changed

+227
-250
lines changed

10 files changed

+227
-250
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,13 @@ jobs:
257257
- name: Install test requirements
258258
run: python -m pip install --upgrade -r build/test-requirements.txt
259259

260+
- name: Rust Tool Chain setup
261+
uses: dtolnay/rust-toolchain@stable
262+
263+
- name: Build Native Binaries
264+
run: nox --session native_build
265+
shell: bash
266+
260267
- name: Install functional test requirements
261268
run: python -m pip install --upgrade -r ./build/functional-test-requirements.txt
262269
if: matrix.test-suite == 'functional'

.github/workflows/pr-check.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,13 @@ jobs:
253253
- name: Install test requirements
254254
run: python -m pip install --upgrade -r build/test-requirements.txt
255255

256+
- name: Rust Tool Chain setup
257+
uses: dtolnay/rust-toolchain@stable
258+
259+
- name: Build Native Binaries
260+
run: nox --session native_build
261+
shell: bash
262+
256263
- name: Install functional test requirements
257264
run: python -m pip install --upgrade -r ./build/functional-test-requirements.txt
258265
if: matrix.test-suite == 'functional'
@@ -512,6 +519,17 @@ jobs:
512519
requirements-file: './python_files/jedilsp_requirements/requirements.txt'
513520
options: '-t ./python_files/lib/jedilsp --implementation py'
514521

522+
- name: Install build pre-requisite
523+
run: python -m pip install wheel nox
524+
shell: bash
525+
526+
- name: Rust Tool Chain setup
527+
uses: dtolnay/rust-toolchain@stable
528+
529+
- name: Build Native Binaries
530+
run: nox --session native_build
531+
shell: bash
532+
515533
- name: Install test requirements
516534
run: python -m pip install --upgrade -r build/test-requirements.txt
517535

src/client/pythonEnvironments/base/locators/common/nativePythonFinder.ts

Lines changed: 12 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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';
55
import * as ch from 'child_process';
66
import * as path from 'path';
77
import * as rpc from 'vscode-jsonrpc/node';
@@ -16,9 +16,8 @@ import { CONDAPATH_SETTING_KEY } from '../../../common/environmentManagers/conda
1616
import { VENVFOLDERS_SETTING_KEY, VENVPATH_SETTING_KEY } from '../lowLevel/customVirtualEnvLocator';
1717
import { getUserHomeDir } from '../../../../common/utils/platform';
1818
import { createLogOutputChannel } from '../../../../common/vscodeApis/windowApis';
19-
import { PythonEnvKind } from '../../info';
2019
import { sendNativeTelemetry, NativePythonTelemetry } from './nativePythonTelemetry';
21-
import { traceError } from '../../../../logging';
20+
import { NativePythonEnvironmentKind } from './nativePythonUtils';
2221

2322
const 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-
6444
export 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-
14689
interface 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
480420
let _finder: NativePythonFinder | undefined;
481421
export function getNativePythonFinder(): NativePythonFinder {
482422
if (!_finder) {
483-
_finder = new NativeGlobalPythonFinderImpl();
423+
_finder = new NativePythonFinderImpl();
484424
}
485425
return _finder;
486426
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
import { LogOutputChannel } from 'vscode';
5+
import { PythonEnvKind } from '../../info';
6+
import { traceError } from '../../../../logging';
7+
8+
export enum NativePythonEnvironmentKind {
9+
Conda = 'Conda',
10+
Homebrew = 'Homebrew',
11+
Pyenv = 'Pyenv',
12+
GlobalPaths = 'GlobalPaths',
13+
PyenvVirtualEnv = 'PyenvVirtualEnv',
14+
Pipenv = 'Pipenv',
15+
Poetry = 'Poetry',
16+
MacPythonOrg = 'MacPythonOrg',
17+
MacCommandLineTools = 'MacCommandLineTools',
18+
LinuxGlobal = 'LinuxGlobal',
19+
MacXCode = 'MacXCode',
20+
Venv = 'Venv',
21+
VirtualEnv = 'VirtualEnv',
22+
VirtualEnvWrapper = 'VirtualEnvWrapper',
23+
WindowsStore = 'WindowsStore',
24+
WindowsRegistry = 'WindowsRegistry',
25+
}
26+
27+
const mapping = new Map<NativePythonEnvironmentKind, PythonEnvKind>([
28+
[NativePythonEnvironmentKind.Conda, PythonEnvKind.Conda],
29+
[NativePythonEnvironmentKind.GlobalPaths, PythonEnvKind.OtherGlobal],
30+
[NativePythonEnvironmentKind.Pyenv, PythonEnvKind.Pyenv],
31+
[NativePythonEnvironmentKind.PyenvVirtualEnv, PythonEnvKind.Pyenv],
32+
[NativePythonEnvironmentKind.Pipenv, PythonEnvKind.Pipenv],
33+
[NativePythonEnvironmentKind.Poetry, PythonEnvKind.Poetry],
34+
[NativePythonEnvironmentKind.VirtualEnv, PythonEnvKind.VirtualEnv],
35+
[NativePythonEnvironmentKind.VirtualEnvWrapper, PythonEnvKind.VirtualEnvWrapper],
36+
[NativePythonEnvironmentKind.Venv, PythonEnvKind.Venv],
37+
[NativePythonEnvironmentKind.WindowsRegistry, PythonEnvKind.System],
38+
[NativePythonEnvironmentKind.WindowsStore, PythonEnvKind.MicrosoftStore],
39+
[NativePythonEnvironmentKind.Homebrew, PythonEnvKind.System],
40+
[NativePythonEnvironmentKind.LinuxGlobal, PythonEnvKind.System],
41+
[NativePythonEnvironmentKind.MacCommandLineTools, PythonEnvKind.System],
42+
[NativePythonEnvironmentKind.MacPythonOrg, PythonEnvKind.System],
43+
[NativePythonEnvironmentKind.MacXCode, PythonEnvKind.System],
44+
]);
45+
46+
export function categoryToKind(category?: NativePythonEnvironmentKind, logger?: LogOutputChannel): PythonEnvKind {
47+
if (!category) {
48+
return PythonEnvKind.Unknown;
49+
}
50+
const kind = mapping.get(category);
51+
if (kind) {
52+
return kind;
53+
}
54+
55+
if (logger) {
56+
logger.error(`Unknown Python Environment category '${category}' from Native Locator.`);
57+
} else {
58+
traceError(`Unknown Python Environment category '${category}' from Native Locator.`);
59+
}
60+
return PythonEnvKind.Unknown;
61+
}

0 commit comments

Comments
 (0)