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

Faster activation of Python environments such as Conda #8342

Merged
merged 8 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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 .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,6 @@ module.exports = {
'src/client/common/installer/pipEnvInstaller.ts',
'src/client/common/installer/productService.ts',
'src/client/common/installer/pipInstaller.ts',
'src/client/common/process/currentProcess.ts',
'src/client/common/process/pythonToolService.ts',
'src/client/common/process/internal/scripts/testing_tools.ts',
'src/client/common/process/logger.ts',
Expand Down
36 changes: 2 additions & 34 deletions src/client/api/pythonApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { isCI } from '../common/constants';
import { trackPackageInstalledIntoInterpreter } from '../common/installer/productInstaller';
import { ProductNames } from '../common/installer/productNames';
import { InterpreterUri } from '../common/installer/types';
import { traceError, traceInfo, traceInfoIfCI } from '../common/logger';
import { traceInfo, traceInfoIfCI } from '../common/logger';
import { getDisplayPath } from '../common/platform/fs-paths';
import {
GLOBAL_MEMENTO,
Expand All @@ -32,14 +32,11 @@ import {
import { createDeferred } from '../common/utils/async';
import * as localize from '../common/utils/localize';
import { isResource, noop } from '../common/utils/misc';
import { StopWatch } from '../common/utils/stopWatch';
import { PythonExtension, Telemetry } from '../datascience/constants';
import { InterpreterPackages } from '../datascience/telemetry/interpreterPackages';
import { IEnvironmentActivationService } from '../interpreter/activation/types';
import { IInterpreterQuickPickItem, IInterpreterSelector } from '../interpreter/configuration/types';
import { IInterpreterService } from '../interpreter/contracts';
import { logValue, TraceOptions } from '../logging/trace';
import { EnvironmentType, PythonEnvironment } from '../pythonEnvironments/info';
import { PythonEnvironment } from '../pythonEnvironments/info';
import { areInterpreterPathsSame } from '../pythonEnvironments/info/interpreter';
import { captureTelemetry, sendTelemetryEvent } from '../telemetry';
import {
Expand All @@ -52,7 +49,6 @@ import {
JupyterProductToInstall,
PythonApi
} from './types';
import { traceDecorators } from '../logging';

/* eslint-disable max-classes-per-file */
@injectable()
Expand Down Expand Up @@ -289,34 +285,6 @@ export class PythonInstaller implements IPythonInstaller {
}
}

// eslint-disable-next-line max-classes-per-file
@injectable()
export class EnvironmentActivationService implements IEnvironmentActivationService {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to a separate file (logic is more complex now)

constructor(@inject(IPythonApiProvider) private readonly apiProvider: IPythonApiProvider) {}
@traceDecorators.verbose('Getting activated env variables', TraceOptions.BeforeCall | TraceOptions.Arguments)
public async getActivatedEnvironmentVariables(
resource: Resource,
@logValue<PythonEnvironment>('path') interpreter?: PythonEnvironment
): Promise<NodeJS.ProcessEnv | undefined> {
const stopWatch = new StopWatch();
const env = await this.apiProvider
.getApi()
.then((api) => api.getActivatedEnvironmentVariables(resource, interpreter, false));

const envType = interpreter?.envType;
sendTelemetryEvent(Telemetry.GetActivatedEnvironmentVariables, stopWatch.elapsedTime, {
envType,
failed: Object.keys(env || {}).length === 0
});
// We must get actiavted env variables for Conda env, if not running stuff against conda will not work.
// Hence we must log these as errors (so we can see them in jupyter logs).
if (!env && envType === EnvironmentType.Conda) {
traceError(`Failed to get activated conda env variables for ${interpreter?.envName}: ${interpreter?.path}`);
}
return env;
}
}

// eslint-disable-next-line max-classes-per-file
@injectable()
export class InterpreterSelector implements IInterpreterSelector {
Expand Down
2 changes: 1 addition & 1 deletion src/client/api/serviceRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
'use strict';

import { IExtensionSingleActivationService } from '../activation/types';
import { EnvironmentActivationService } from '../common/process/interpreterActivation';
import { IEnvironmentActivationService } from '../interpreter/activation/types';
import { IInterpreterSelector } from '../interpreter/configuration/types';
import { IInterpreterService } from '../interpreter/contracts';
import { InterpreterStatusBarVisibility } from '../interpreter/display/visibilityFilter';
import { IServiceManager } from '../ioc/types';
import {
EnvironmentActivationService,
InterpreterSelector,
InterpreterService,
LanguageServerProvider,
Expand Down
2 changes: 1 addition & 1 deletion src/client/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export type PythonApi = {
*/
getActivatedEnvironmentVariables(
resource: Resource,
interpreter?: PythonEnvironment,
interpreter: PythonEnvironment,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is never undefined, we always pass this around, hence changed this to not be nullable.
Makes the code cleaner

allowExceptions?: boolean
): Promise<NodeJS.ProcessEnv | undefined>;
/**
Expand Down
13 changes: 13 additions & 0 deletions src/client/common/process/currentProcess.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';

import { injectable } from 'inversify';
import { EnvironmentVariables } from '../variables/types';

@injectable()
export class CurrentProcess {
public get env(): EnvironmentVariables {
return (process.env as any) as EnvironmentVariables;
}
}
Loading