Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Disables the use of a terminal to activate an environment
  • Loading branch information
DonJayamanne committed Feb 6, 2020
commit b519fe3f74db9acdd8f974f1a568d1cd018ce3d8
10 changes: 9 additions & 1 deletion src/client/interpreter/activation/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { IPlatformService } from '../../common/platform/types';
import { IProcessServiceFactory } from '../../common/process/types';
import { ITerminalHelper, TerminalShellType } from '../../common/terminal/types';
import { ICurrentProcess, IDisposable, Resource } from '../../common/types';
import { cacheResourceSpecificInterpreterData, clearCachedResourceSpecificIngterpreterData } from '../../common/utils/decorators';
import { OSType } from '../../common/utils/platform';
import { IEnvironmentVariablesProvider } from '../../common/variables/types';
import { EXTENSION_ROOT_DIR } from '../../constants';
Expand All @@ -21,6 +22,7 @@ import { PythonInterpreter } from '../contracts';
import { IEnvironmentActivationService } from './types';

const getEnvironmentPrefix = 'e8b39361-0157-4923-80e1-22d70d46dee6';
const cacheDuration = 10 * 60 * 1000;
export const getEnvironmentTimeout = 30000;

// The shell under which we'll execute activation scripts.
Expand All @@ -40,13 +42,16 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
@inject(IProcessServiceFactory) private processServiceFactory: IProcessServiceFactory,
@inject(ICurrentProcess) private currentProcess: ICurrentProcess,
@inject(IEnvironmentVariablesProvider) private readonly envVarsService: IEnvironmentVariablesProvider
) {}
) {
this.envVarsService.onDidEnvironmentVariablesChange(this.onDidEnvironmentVariablesChange, this, this.disposables);
}

public dispose(): void {
this.disposables.forEach(d => d.dispose());
}
@traceDecorators.verbose('getActivatedEnvironmentVariables', LogOptions.Arguments)
@captureTelemetry(EventName.PYTHON_INTERPRETER_ACTIVATION_ENVIRONMENT_VARIABLES, { failed: false }, true)
@cacheResourceSpecificInterpreterData('ActivatedEnvironmentVariables', cacheDuration)
public async getActivatedEnvironmentVariables(resource: Resource, interpreter?: PythonInterpreter, allowExceptions?: boolean): Promise<NodeJS.ProcessEnv | undefined> {
const shellInfo = defaultShells[this.platform.osType];
if (!shellInfo) {
Expand Down Expand Up @@ -110,6 +115,9 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
}
}
}
protected onDidEnvironmentVariablesChange(affectedResource: Resource) {
clearCachedResourceSpecificIngterpreterData('ActivatedEnvironmentVariables', affectedResource);
}
protected fixActivationCommands(commands: string[]): string[] {
// Replace 'source ' with '. ' as that works in shell exec
return commands.map(cmd => cmd.replace(/^source\s+/, '. '));
Expand Down
3 changes: 1 addition & 2 deletions src/client/interpreter/serviceRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { PreWarmActivatedEnvironmentVariables } from './activation/preWarmVariab
import { EnvironmentActivationService } from './activation/service';
import { TerminalEnvironmentActivationService } from './activation/terminalEnvironmentActivationService';
import { IEnvironmentActivationService } from './activation/types';
import { WrapperEnvironmentActivationService } from './activation/wrapperEnvironmentActivationService';
import { InterpreterAutoSelectionService } from './autoSelection/index';
import { InterpreterAutoSeletionProxyService } from './autoSelection/proxy';
import { CachedInterpretersAutoSelectionRule } from './autoSelection/rules/cached';
Expand Down Expand Up @@ -155,5 +154,5 @@ export function registerTypes(serviceManager: IServiceManager) {
serviceManager.addSingleton<IInterpreterAutoSeletionProxyService>(IInterpreterAutoSeletionProxyService, InterpreterAutoSeletionProxyService);
serviceManager.addSingleton<IEnvironmentActivationService>(EnvironmentActivationService, EnvironmentActivationService);
serviceManager.addSingleton<IEnvironmentActivationService>(TerminalEnvironmentActivationService, TerminalEnvironmentActivationService);
serviceManager.addSingleton<IEnvironmentActivationService>(IEnvironmentActivationService, WrapperEnvironmentActivationService);
serviceManager.addSingleton<IEnvironmentActivationService>(IEnvironmentActivationService, EnvironmentActivationService);
}