Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More native tests for Native python finder #23831

Merged
merged 9 commits into from
Jul 19, 2024
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
7 changes: 7 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@ jobs:
- name: Install test requirements
run: python -m pip install --upgrade -r build/test-requirements.txt

- name: Rust Tool Chain setup
uses: dtolnay/rust-toolchain@stable

- name: Build Native Binaries
run: nox --session native_build
shell: bash

- name: Install functional test requirements
run: python -m pip install --upgrade -r ./build/functional-test-requirements.txt
if: matrix.test-suite == 'functional'
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@ jobs:
- name: Install test requirements
run: python -m pip install --upgrade -r build/test-requirements.txt

- name: Rust Tool Chain setup
uses: dtolnay/rust-toolchain@stable

- name: Build Native Binaries
run: nox --session native_build
shell: bash

- name: Install functional test requirements
run: python -m pip install --upgrade -r ./build/functional-test-requirements.txt
if: matrix.test-suite == 'functional'
Expand Down Expand Up @@ -512,6 +519,17 @@ jobs:
requirements-file: './python_files/jedilsp_requirements/requirements.txt'
options: '-t ./python_files/lib/jedilsp --implementation py'

- name: Install build pre-requisite
run: python -m pip install wheel nox
shell: bash

- name: Rust Tool Chain setup
uses: dtolnay/rust-toolchain@stable

- name: Build Native Binaries
run: nox --session native_build
shell: bash

- name: Install test requirements
run: python -m pip install --upgrade -r build/test-requirements.txt

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { Disposable, EventEmitter, Event, Uri, LogOutputChannel } from 'vscode';
import { Disposable, EventEmitter, Event, Uri } from 'vscode';
import * as ch from 'child_process';
import * as path from 'path';
import * as rpc from 'vscode-jsonrpc/node';
Expand All @@ -16,9 +16,8 @@ import { CONDAPATH_SETTING_KEY } from '../../../common/environmentManagers/conda
import { VENVFOLDERS_SETTING_KEY, VENVPATH_SETTING_KEY } from '../lowLevel/customVirtualEnvLocator';
import { getUserHomeDir } from '../../../../common/utils/platform';
import { createLogOutputChannel } from '../../../../common/vscodeApis/windowApis';
import { PythonEnvKind } from '../../info';
import { sendNativeTelemetry, NativePythonTelemetry } from './nativePythonTelemetry';
import { traceError } from '../../../../logging';
import { NativePythonEnvironmentKind } from './nativePythonUtils';

const untildify = require('untildify');

Expand All @@ -30,7 +29,7 @@ export interface NativeEnvInfo {
displayName?: string;
name?: string;
executable?: string;
kind?: PythonEnvironmentKind;
kind?: NativePythonEnvironmentKind;
version?: string;
prefix?: string;
manager?: NativeEnvManagerInfo;
Expand All @@ -42,32 +41,13 @@ export interface NativeEnvInfo {
symlinks?: string[];
}

export enum PythonEnvironmentKind {
Conda = 'Conda',
Homebrew = 'Homebrew',
Pyenv = 'Pyenv',
GlobalPaths = 'GlobalPaths',
PyenvVirtualEnv = 'PyenvVirtualEnv',
Pipenv = 'Pipenv',
Poetry = 'Poetry',
MacPythonOrg = 'MacPythonOrg',
MacCommandLineTools = 'MacCommandLineTools',
LinuxGlobal = 'LinuxGlobal',
MacXCode = 'MacXCode',
Venv = 'Venv',
VirtualEnv = 'VirtualEnv',
VirtualEnvWrapper = 'VirtualEnvWrapper',
WindowsStore = 'WindowsStore',
WindowsRegistry = 'WindowsRegistry',
}

export interface NativeEnvManagerInfo {
tool: string;
executable: string;
version?: string;
}

export function isNativeInfoEnvironment(info: NativeEnvInfo | NativeEnvManagerInfo): info is NativeEnvInfo {
export function isNativeEnvInfo(info: NativeEnvInfo | NativeEnvManagerInfo): info is NativeEnvInfo {
if ((info as NativeEnvManagerInfo).tool) {
return false;
}
Expand All @@ -92,63 +72,26 @@ export interface NativePythonFinder extends Disposable {
*
* If a Uri is provided, then it will search for python environments in that location (ignoring workspaces).
* Uri can be a file or a folder.
* If a PythonEnvironmentKind is provided, then it will search for python environments of that kind (ignoring workspaces).
* If a NativePythonEnvironmentKind is provided, then it will search for python environments of that kind (ignoring workspaces).
*/
refresh(options?: PythonEnvironmentKind | Uri[]): AsyncIterable<NativeEnvInfo | NativeEnvManagerInfo>;
refresh(options?: NativePythonEnvironmentKind | Uri[]): AsyncIterable<NativeEnvInfo | NativeEnvManagerInfo>;
/**
* Will spawn the provided Python executable and return information about the environment.
* @param executable
*/
resolve(executable: string): Promise<NativeEnvInfo>;
categoryToKind(category?: PythonEnvironmentKind): PythonEnvKind;
/**
* Used only for telemetry.
*/
getCondaInfo(): Promise<NativeCondaInfo>;
}

const mapping = new Map<PythonEnvironmentKind, PythonEnvKind>([
[PythonEnvironmentKind.Conda, PythonEnvKind.Conda],
[PythonEnvironmentKind.GlobalPaths, PythonEnvKind.OtherGlobal],
[PythonEnvironmentKind.Pyenv, PythonEnvKind.Pyenv],
[PythonEnvironmentKind.PyenvVirtualEnv, PythonEnvKind.Pyenv],
[PythonEnvironmentKind.Pipenv, PythonEnvKind.Pipenv],
[PythonEnvironmentKind.Poetry, PythonEnvKind.Poetry],
[PythonEnvironmentKind.VirtualEnv, PythonEnvKind.VirtualEnv],
[PythonEnvironmentKind.VirtualEnvWrapper, PythonEnvKind.VirtualEnvWrapper],
[PythonEnvironmentKind.Venv, PythonEnvKind.Venv],
[PythonEnvironmentKind.WindowsRegistry, PythonEnvKind.System],
[PythonEnvironmentKind.WindowsStore, PythonEnvKind.MicrosoftStore],
[PythonEnvironmentKind.Homebrew, PythonEnvKind.System],
[PythonEnvironmentKind.LinuxGlobal, PythonEnvKind.System],
[PythonEnvironmentKind.MacCommandLineTools, PythonEnvKind.System],
[PythonEnvironmentKind.MacPythonOrg, PythonEnvKind.System],
[PythonEnvironmentKind.MacXCode, PythonEnvKind.System],
]);

export function categoryToKind(category?: PythonEnvironmentKind, logger?: LogOutputChannel): PythonEnvKind {
if (!category) {
return PythonEnvKind.Unknown;
}
const kind = mapping.get(category);
if (kind) {
return kind;
}

if (logger) {
logger.error(`Unknown Python Environment category '${category}' from Native Locator.`);
} else {
traceError(`Unknown Python Environment category '${category}' from Native Locator.`);
}
return PythonEnvKind.Unknown;
}

interface NativeLog {
level: string;
message: string;
}

class NativeGlobalPythonFinderImpl extends DisposableBase implements NativePythonFinder {
class NativePythonFinderImpl extends DisposableBase implements NativePythonFinder {
private readonly connection: rpc.MessageConnection;

private firstRefreshResults: undefined | (() => AsyncGenerator<NativeEnvInfo, void, unknown>);
Expand All @@ -171,11 +114,7 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativePytho
return environment;
}

categoryToKind(category?: PythonEnvironmentKind): PythonEnvKind {
return categoryToKind(category, this.outputChannel);
}

async *refresh(options?: PythonEnvironmentKind | Uri[]): AsyncIterable<NativeEnvInfo> {
async *refresh(options?: NativePythonEnvironmentKind | Uri[]): AsyncIterable<NativeEnvInfo> {
if (this.firstRefreshResults) {
// If this is the first time we are refreshing,
// Then get the results from the first refresh.
Expand Down Expand Up @@ -321,7 +260,7 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativePytho
}

private doRefresh(
options?: PythonEnvironmentKind | Uri[],
options?: NativePythonEnvironmentKind | Uri[],
): { completed: Promise<void>; discovered: Event<NativeEnvInfo | NativeEnvManagerInfo> } {
const disposable = this._register(new DisposableStore());
const discovered = disposable.add(new EventEmitter<NativeEnvInfo | NativeEnvManagerInfo>());
Expand Down Expand Up @@ -383,7 +322,7 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativePytho
);

type RefreshOptions = {
searchKind?: PythonEnvironmentKind;
searchKind?: NativePythonEnvironmentKind;
searchPaths?: string[];
};

Expand Down Expand Up @@ -422,6 +361,7 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativePytho
environmentDirectories: getCustomVirtualEnvDirs(),
condaExecutable: getPythonSettingAndUntildify<string>(CONDAPATH_SETTING_KEY),
poetryExecutable: getPythonSettingAndUntildify<string>('poetryPath'),
// We don't use pipenvPath as it is not used for discovery
};
// No need to send a configuration request, is there are no changes.
if (JSON.stringify(options) === JSON.stringify(this.lastConfiguration || {})) {
Expand Down Expand Up @@ -483,7 +423,7 @@ function getPythonSettingAndUntildify<T>(name: string, scope?: Uri): T | undefin
let _finder: NativePythonFinder | undefined;
export function getNativePythonFinder(): NativePythonFinder {
if (!_finder) {
_finder = new NativeGlobalPythonFinderImpl();
_finder = new NativePythonFinderImpl();
}
return _finder;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { LogOutputChannel } from 'vscode';
import { PythonEnvKind } from '../../info';
import { traceError } from '../../../../logging';

export enum NativePythonEnvironmentKind {
Conda = 'Conda',
Homebrew = 'Homebrew',
Pyenv = 'Pyenv',
GlobalPaths = 'GlobalPaths',
PyenvVirtualEnv = 'PyenvVirtualEnv',
Pipenv = 'Pipenv',
Poetry = 'Poetry',
MacPythonOrg = 'MacPythonOrg',
MacCommandLineTools = 'MacCommandLineTools',
LinuxGlobal = 'LinuxGlobal',
MacXCode = 'MacXCode',
Venv = 'Venv',
VirtualEnv = 'VirtualEnv',
VirtualEnvWrapper = 'VirtualEnvWrapper',
WindowsStore = 'WindowsStore',
WindowsRegistry = 'WindowsRegistry',
}

const mapping = new Map<NativePythonEnvironmentKind, PythonEnvKind>([
[NativePythonEnvironmentKind.Conda, PythonEnvKind.Conda],
[NativePythonEnvironmentKind.GlobalPaths, PythonEnvKind.OtherGlobal],
[NativePythonEnvironmentKind.Pyenv, PythonEnvKind.Pyenv],
[NativePythonEnvironmentKind.PyenvVirtualEnv, PythonEnvKind.Pyenv],
[NativePythonEnvironmentKind.Pipenv, PythonEnvKind.Pipenv],
[NativePythonEnvironmentKind.Poetry, PythonEnvKind.Poetry],
[NativePythonEnvironmentKind.VirtualEnv, PythonEnvKind.VirtualEnv],
[NativePythonEnvironmentKind.VirtualEnvWrapper, PythonEnvKind.VirtualEnvWrapper],
[NativePythonEnvironmentKind.Venv, PythonEnvKind.Venv],
[NativePythonEnvironmentKind.WindowsRegistry, PythonEnvKind.System],
[NativePythonEnvironmentKind.WindowsStore, PythonEnvKind.MicrosoftStore],
[NativePythonEnvironmentKind.Homebrew, PythonEnvKind.System],
[NativePythonEnvironmentKind.LinuxGlobal, PythonEnvKind.System],
[NativePythonEnvironmentKind.MacCommandLineTools, PythonEnvKind.System],
[NativePythonEnvironmentKind.MacPythonOrg, PythonEnvKind.System],
[NativePythonEnvironmentKind.MacXCode, PythonEnvKind.System],
]);

export function categoryToKind(category?: NativePythonEnvironmentKind, logger?: LogOutputChannel): PythonEnvKind {
if (!category) {
return PythonEnvKind.Unknown;
}
const kind = mapping.get(category);
if (kind) {
return kind;
}

if (logger) {
logger.error(`Unknown Python Environment category '${category}' from Native Locator.`);
} else {
traceError(`Unknown Python Environment category '${category}' from Native Locator.`);
}
return PythonEnvKind.Unknown;
}
Loading
Loading