Skip to content

Leverage ComponentAdapter.getInterpreterInformation in PythonPathUpdaterService #15134

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

Merged
merged 3 commits into from
Jan 14, 2021
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
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ src/client/interpreter/configuration/interpreterSelector/commands/setInterpreter
src/client/interpreter/configuration/interpreterSelector/commands/resetInterpreter.ts
src/client/interpreter/configuration/interpreterSelector/commands/setShebangInterpreter.ts
src/client/interpreter/configuration/interpreterSelector/interpreterSelector.ts
src/client/interpreter/configuration/pythonPathUpdaterService.ts
src/client/interpreter/configuration/pythonPathUpdaterServiceFactory.ts
src/client/interpreter/configuration/services/globalUpdaterService.ts
src/client/interpreter/configuration/services/workspaceUpdaterService.ts
Expand Down
40 changes: 22 additions & 18 deletions src/client/interpreter/configuration/pythonPathUpdaterService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@ import { InterpreterInformation } from '../../pythonEnvironments/info';
import { sendTelemetryEvent } from '../../telemetry';
import { EventName } from '../../telemetry/constants';
import { PythonInterpreterTelemetry } from '../../telemetry/types';
import { IInterpreterVersionService } from '../contracts';
import { IComponentAdapter } from '../contracts';
import { IPythonPathUpdaterServiceFactory, IPythonPathUpdaterServiceManager } from './types';

@injectable()
export class PythonPathUpdaterService implements IPythonPathUpdaterServiceManager {
private readonly pythonPathSettingsUpdaterFactory: IPythonPathUpdaterServiceFactory;
private readonly interpreterVersionService: IInterpreterVersionService;

private readonly executionFactory: IPythonExecutionFactory;

private readonly componentAdapter: IComponentAdapter;

constructor(@inject(IServiceContainer) serviceContainer: IServiceContainer) {
this.pythonPathSettingsUpdaterFactory = serviceContainer.get<IPythonPathUpdaterServiceFactory>(
IPythonPathUpdaterServiceFactory,
);
this.interpreterVersionService = serviceContainer.get<IInterpreterVersionService>(IInterpreterVersionService);
this.executionFactory = serviceContainer.get<IPythonExecutionFactory>(IPythonExecutionFactory);
this.componentAdapter = serviceContainer.get<IComponentAdapter>(IComponentAdapter);
}

public async updatePythonPath(
pythonPath: string | undefined,
configTarget: ConfigurationTarget,
Expand All @@ -47,6 +51,7 @@ export class PythonPathUpdaterService implements IPythonPathUpdaterServiceManage
traceError('Python Extension: sendTelemetry', ex),
);
}

private async sendTelemetry(
duration: number,
failed: boolean,
Expand All @@ -58,27 +63,26 @@ export class PythonPathUpdaterService implements IPythonPathUpdaterServiceManage
trigger,
};
if (!failed && pythonPath) {
const processService = await this.executionFactory.create({ pythonPath });
const infoPromise = processService
.getInterpreterInformation()
.catch<InterpreterInformation | undefined>(() => undefined);
const pipVersionPromise = this.interpreterVersionService
.getPipVersion(pythonPath)
.then((value) => (value.length === 0 ? undefined : value))
.catch<string>(() => '');
const [info, pipVersion] = await Promise.all([infoPromise, pipVersionPromise]);
if (info) {
telemetryProperties.architecture = info.architecture;
if (info.version) {
// Ask for info using the new discovery code first.
// If it returns undefined, fallback on the old code.
const interpreterInfo = await this.componentAdapter.getInterpreterInformation(pythonPath);
if (interpreterInfo && interpreterInfo.version) {
telemetryProperties.pythonVersion = interpreterInfo.version.raw;
} else {
const processService = await this.executionFactory.create({ pythonPath });
const info = await processService
.getInterpreterInformation()
.catch<InterpreterInformation | undefined>(() => undefined);

if (info && info.version) {
telemetryProperties.pythonVersion = info.version.raw;
}
}
if (pipVersion) {
telemetryProperties.pipVersion = pipVersion;
}
}

sendTelemetryEvent(EventName.PYTHON_INTERPRETER, duration, telemetryProperties);
}

private getPythonUpdaterService(configTarget: ConfigurationTarget, wkspace?: Uri) {
switch (configTarget) {
case ConfigurationTarget.Global: {
Expand Down
13 changes: 0 additions & 13 deletions src/client/telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { AppinsightsKey, isTestExecution, isUnitTestExecution, PVSC_EXTENSION_ID
import { traceError, traceInfo } from '../common/logger';
import { Telemetry } from '../common/startPage/constants';
import type { TerminalShellType } from '../common/terminal/types';
import { Architecture } from '../common/utils/platform';
import { StopWatch } from '../common/utils/stopWatch';
import { DebugConfigurationType } from '../debugger/extension/types';
import { ConsoleType, TriggerType } from '../debugger/types';
Expand Down Expand Up @@ -933,18 +932,6 @@ export interface IEventNamePropertyMapping {
* @type {string}
*/
pythonVersion?: string;
/**
* The version of pip module installed in the python interpreter
*
* @type {string}
*/
pipVersion?: string;
/**
* The bit-ness of the python interpreter represented using architecture.
*
* @type {Architecture}
*/
architecture?: Architecture;
};
[EventName.PYTHON_INTERPRETER_ACTIVATION_ENVIRONMENT_VARIABLES]: {
/**
Expand Down