Skip to content
Closed
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
392 changes: 6 additions & 386 deletions .github/workflows/pr-check.yml

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion src/client/common/interpreterPathService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
IPythonSettings,
Resource,
} from './types';
import { sleep } from './utils/async';

export const workspaceKeysForWhichTheCopyIsDone_Key = 'workspaceKeysForWhichTheCopyIsDone_Key';
export const workspaceFolderKeysForWhichTheCopyIsDone_Key = 'workspaceFolderKeysForWhichTheCopyIsDone_Key';
Expand Down Expand Up @@ -53,6 +54,11 @@ export class InterpreterPathService implements IInterpreterPathService {

public async onDidChangeConfiguration(event: ConfigurationChangeEvent) {
if (event.affectsConfiguration(`python.${defaultInterpreterPathSetting}`)) {
await sleep(1000);
const x = this.workspaceService
.getConfiguration('python', this.workspaceService.workspaceFolders![0].uri)
.inspect<string>('defaultInterpreterPath')!;
console.log(x.globalValue);
this._didChangeInterpreterEmitter.fire({ uri: undefined, configTarget: ConfigurationTarget.Global });
}
}
Expand All @@ -72,7 +78,7 @@ export class InterpreterPathService implements IInterpreterPathService {
);
}
const defaultInterpreterPath = this.workspaceService
.getConfiguration('python', resource)!
.getConfiguration('python', this.workspaceService.workspaceFolders![0].uri)!
.inspect<string>('defaultInterpreterPath')!;
return {
globalValue: defaultInterpreterPath.globalValue,
Expand Down
1 change: 1 addition & 0 deletions src/client/common/process/pythonEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class PythonEnvironment {
public async getExecutablePath(): Promise<string> {
// If we've passed the python file, then return the file.
// This is because on mac if using the interpreter /usr/bin/python2.7 we can get a different value for the path
console.log('Getting exec path...');
if (await this.deps.isValidExecutable(this.pythonPath)) {
return this.pythonPath;
}
Expand Down
10 changes: 9 additions & 1 deletion src/client/common/terminal/activator/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

'use strict';

import { Terminal } from 'vscode';
import { env, Terminal } from 'vscode';
import { createDeferred, sleep } from '../../utils/async';
import { ITerminalActivator, ITerminalHelper, TerminalActivationOptions, TerminalShellType } from '../types';

Expand All @@ -26,16 +26,24 @@ export class BaseTerminalActivator implements ITerminalActivator {
options?.resource,
options?.interpreter,
);
console.log('Got the activation commands', JSON.stringify(activationCommands));
let activated = false;
if (activationCommands) {
for (const command of activationCommands) {
terminal.show(options?.preserveFocus);
if ('shellPath' in terminal.creationOptions && terminal.creationOptions.shellPath) {
console.log('Shell path is', terminal.creationOptions.shellPath);
}
console.log(`Shell path returned by vscode API`, env.shell);
console.log(`Sending ${command} to terminal`, terminal.creationOptions.name);
terminal.sendText(command);
await this.waitForCommandToProcess(terminalShellType);
activated = true;
}
}
console.log('Activation complete', activated);
deferred.resolve(activated);
console.timeEnd('Time taken to send command');
return activated;
}
protected async waitForCommandToProcess(_shell: TerminalShellType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ abstract class BaseActivationCommandProvider implements ITerminalActivationComma
resource: Uri | undefined,
targetShell: TerminalShellType,
): Promise<string[] | undefined> {
console.log('Log everywhere1');
const pythonPath = this.serviceContainer.get<IConfigurationService>(IConfigurationService).getSettings(resource)
.pythonPath;
console.log('Log everywhere2');
return this.getActivationCommandsForInterpreter(pythonPath, targetShell);
}
public abstract getActivationCommandsForInterpreter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ export class CommandPromptAndPowerShell extends VenvBaseActivationCommandProvide
pythonPath: string,
targetShell: TerminalShellType,
): Promise<string[] | undefined> {
console.log('Finding the script file for', pythonPath, targetShell);
const scriptFile = await this.findScriptFile(pythonPath, targetShell);
if (!scriptFile) {
console.log('Not script file found');
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class CondaActivationCommandProvider implements ITerminalActivationComman
resource: Uri | undefined,
targetShell: TerminalShellType,
): Promise<string[] | undefined> {
console.log('Should not be here1');
const { pythonPath } = this.configService.getSettings(resource);
return this.getActivationCommandsForInterpreter(pythonPath, targetShell);
}
Expand All @@ -62,23 +63,29 @@ export class CondaActivationCommandProvider implements ITerminalActivationComman
pythonPath: string,
targetShell: TerminalShellType,
): Promise<string[] | undefined> {
console.time('Time to get codna env info');
const condaLocatorService = (await inDiscoveryExperiment(this.experimentService))
? this.pyenvs
: this.serviceContainer.get<ICondaLocatorService>(ICondaLocatorService);
const envInfo = await condaLocatorService.getCondaEnvironment(pythonPath);
console.timeEnd('Time to get codna env info');
if (!envInfo) {
return undefined;
}

const condaEnv = envInfo.name.length > 0 ? envInfo.name : envInfo.path;

console.time('Time to get codna version');
// Algorithm differs based on version
// Old version, just call activate directly.
// New version, call activate from the same path as our python path, then call it again to activate our environment.
// -- note that the 'default' conda location won't allow activate to work for the environment sometimes.
const versionInfo = await this.condaService.getCondaVersion();
console.timeEnd('Time to get codna version');
console.log('Conda version', JSON.stringify(versionInfo));
if (versionInfo && versionInfo.major >= CondaRequiredMajor) {
// Conda added support for powershell in 4.6.
console.time('Time to get commands');
if (
versionInfo.minor >= CondaRequiredMinorForPowerShell &&
(targetShell === TerminalShellType.powershell || targetShell === TerminalShellType.powershellCore)
Expand All @@ -91,6 +98,7 @@ export class CondaActivationCommandProvider implements ITerminalActivationComman
if (interpreterPath) {
const activatePath = path.join(path.dirname(interpreterPath), 'activate').fileToCommandArgument();
const firstActivate = this.platform.isWindows ? activatePath : `source ${activatePath}`;
console.timeEnd('Time to get commands');
return [firstActivate, `conda activate ${condaEnv.toCommandArgument()}`];
}
}
Expand All @@ -106,6 +114,7 @@ export class CondaActivationCommandProvider implements ITerminalActivationComman
return getFishCommands(condaEnv, await this.condaService.getCondaFile());

default:
console.log('Naruto boi get lost');
if (this.platform.isWindows) {
return this.getWindowsCommands(condaEnv);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class PipEnvActivationCommandProvider implements ITerminalActivationComma
}

public async getActivationCommands(resource: Uri | undefined): Promise<string[] | undefined> {
console.log('Should not be here2');
const interpreter = await this.interpreterService.getActiveInterpreter(resource);
if (!interpreter || interpreter.envType !== EnvironmentType.Pipenv) {
return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Uri } from 'vscode';
import { IInterpreterService } from '../../../interpreter/contracts';
import { IServiceContainer } from '../../../ioc/types';
import { EnvironmentType } from '../../../pythonEnvironments/info';
import { IConfigurationService } from '../../types';
import { ITerminalActivationCommandProvider, TerminalShellType } from '../types';

@injectable()
Expand All @@ -19,12 +20,18 @@ export class PyEnvActivationCommandProvider implements ITerminalActivationComman
}

public async getActivationCommands(resource: Uri | undefined, _: TerminalShellType): Promise<string[] | undefined> {
console.log('Should not be here3');
const lalal = this.serviceContainer.get<IConfigurationService>(IConfigurationService).getSettings(resource)
.pythonPath;
console.log('Log lalalala', lalal);
const interpreter = await this.serviceContainer
.get<IInterpreterService>(IInterpreterService)
.getActiveInterpreter(resource);
console.log('Log interpreters', interpreter);
if (!interpreter || interpreter.envType !== EnvironmentType.Pyenv || !interpreter.envName) {
return;
}
console.log('not here');

return [`pyenv shell ${interpreter.envName.toCommandArgument()}`];
}
Expand Down
22 changes: 21 additions & 1 deletion src/client/common/terminal/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export class TerminalHelper implements ITerminalHelper {
providers: ITerminalActivationCommandProvider[],
): Promise<string[] | undefined> {
const settings = this.configurationService.getSettings(resource);
console.log('Do we have the right python?', settings.pythonPath);

const experimentService = this.serviceContainer.get<IExperimentService>(IExperimentService);
const condaService = (await inDiscoveryExperiment(experimentService))
Expand All @@ -140,26 +141,45 @@ export class TerminalHelper implements ITerminalHelper {
? interpreter.envType === EnvironmentType.Conda
: await condaService.isCondaEnvironment(settings.pythonPath);
if (isCondaEnvironment) {
console.log('I am a conda environment', interpreter);
console.time('Time taken to get activation commands for conda');
const activationCommands = interpreter
? await this.conda.getActivationCommandsForInterpreter(interpreter.path, terminalShellType)
: await this.conda.getActivationCommands(resource, terminalShellType);
console.timeEnd('Time taken to get activation commands for conda');

if (Array.isArray(activationCommands)) {
console.log('Should not be here', JSON.stringify(activationCommands));
return activationCommands;
}
}
console.log('Now let us check the supported providers for', terminalShellType, 'haaaa', settings.pythonPath);

// Search from the list of providers.
const supportedProviders = providers.filter((provider) => provider.isShellSupported(terminalShellType));
console.log('Log it', supportedProviders, supportedProviders.length, providers.length);

// const provider = supportedProviders[0];
// console.log('Check the provider', provider, interpreter, 'haaaa', settings.pythonPath);
// const activationCommands = interpreter
// ? await provider.getActivationCommandsForInterpreter(interpreter.path, terminalShellType)
// : await provider.getActivationCommands(resource, terminalShellType);
// console.log('Activation commands found', JSON.stringify(activationCommands));
// if (Array.isArray(activationCommands) && activationCommands.length > 0) {
// return activationCommands;
// }

for (const provider of supportedProviders) {
console.log('Check the provider', provider, interpreter, 'haaaa', settings.pythonPath);
const activationCommands = interpreter
? await provider.getActivationCommandsForInterpreter(interpreter.path, terminalShellType)
: await provider.getActivationCommands(resource, terminalShellType);

console.log('Activation commands found', JSON.stringify(activationCommands));
if (Array.isArray(activationCommands) && activationCommands.length > 0) {
return activationCommands;
}
}

console.log('Could not find anything');
}
}
14 changes: 12 additions & 2 deletions src/client/interpreter/interpreterService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,21 @@ export class InterpreterService implements Disposable, IInterpreterService {
this._pythonPathSetting = pySettings.pythonPath;
if (this.experimentsManager.inExperimentSync(DeprecatePythonPath.experiment)) {
disposables.push(
this.interpreterPathService.onDidChange((i) => {
this.interpreterPathService.onDidChange(async (i) => {
await sleep(1000);
this._onConfigChanged(i.uri);
}),
);
} else {
const workspacesUris: (Uri | undefined)[] = workspaceService.hasWorkspaceFolders
? workspaceService.workspaceFolders!.map((workspace) => workspace.uri)
: [undefined];
const disposable = workspaceService.onDidChangeConfiguration((e) => {
const disposable = workspaceService.onDidChangeConfiguration(async (e) => {
const workspaceUriIndex = workspacesUris.findIndex((uri) =>
e.affectsConfiguration('python.pythonPath', uri),
);
const workspaceUri = workspaceUriIndex === -1 ? undefined : workspacesUris[workspaceUriIndex];
await sleep(1000);
this._onConfigChanged(workspaceUri);
});
disposables.push(disposable);
Expand Down Expand Up @@ -184,13 +186,16 @@ export class InterpreterService implements Disposable, IInterpreterService {

public async getActiveInterpreter(resource?: Uri): Promise<PythonEnvironment | undefined> {
// During shutdown we might not be able to get items out of the service container.
console.log('Interpreter service enter');
const pythonExecutionFactory = this.serviceContainer.tryGet<IPythonExecutionFactory>(IPythonExecutionFactory);
const pythonExecutionService = pythonExecutionFactory
? await pythonExecutionFactory.create({ resource })
: undefined;
console.log('Interpreter service pythonexec', pythonExecutionService);
const fullyQualifiedPath = pythonExecutionService
? await pythonExecutionService.getExecutablePath().catch(() => undefined)
: undefined;
console.log('Interpreter service fullpath', fullyQualifiedPath);
// Python path is invalid or python isn't installed.
if (!fullyQualifiedPath) {
return undefined;
Expand All @@ -203,14 +208,18 @@ export class InterpreterService implements Disposable, IInterpreterService {
pythonPath: string,
resource?: Uri,
): Promise<StoredPythonEnvironment | undefined> {
console.log('I am here to get details');
if (await inDiscoveryExperiment(this.experimentService)) {
console.log('I chose discovery experiment');
const info = await this.pyenvs.getInterpreterDetails(pythonPath);
console.log('Got the info!', JSON.stringify(info));
if (!info.displayName) {
// Set display name for the environment returned by component if it's not set (this should eventually go away)
info.displayName = await this.getDisplayName(info, resource);
}
return info;
}
console.log('I did not choose discovery experiment');

// If we don't have the fully qualified path, then get it.
if (path.basename(pythonPath) === pythonPath) {
Expand Down Expand Up @@ -325,6 +334,7 @@ export class InterpreterService implements Disposable, IInterpreterService {
this.didChangeInterpreterConfigurationEmitter.fire(resource);
// Check if we actually changed our python path
const pySettings = this.configService.getSettings(resource);
console.log('Interpreter', pySettings.pythonPath, this._pythonPathSetting);
if (this._pythonPathSetting === '' || this._pythonPathSetting !== pySettings.pythonPath) {
this._pythonPathSetting = pySettings.pythonPath;
this.didChangeInterpreterEmitter.fire();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ export class CachingLocator extends LazyResourceBasedLocator {
}

protected async doResolveEnv(env: string | PythonEnvInfo): Promise<PythonEnvInfo | undefined> {
console.log('Imma resolve');
let matchingEnvs = this.filterMatchingEnvsFromCache(env);
if (matchingEnvs.length > 0) {
console.log('Imma cache');
return pickBestEnv(matchingEnvs);
}
console.log('Imma fallback');
// Fall back to the underlying locator.
const resolved = await this.locator.resolveEnv(env);
if (resolved !== undefined) {
Expand Down
Loading