Skip to content

Commit

Permalink
Debugging promise resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartik Raj committed Dec 17, 2018
1 parent d1b981b commit d7410d1
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 24 deletions.
10 changes: 10 additions & 0 deletions build/ci/templates/virtual_env_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@ jobs:
condition: and(succeeded(), eq(variables['Platform'], 'Linux'))
- bash: |
echo "SHELL: $SHELL, shell: $shell, ARGV[0]: $0, PS1: $PS1, prompt: $prompt"
if test -z "$(type -p)" ; then echo bash ; else echo sh ; fi
displayName: 'Echo shell'
env:
DISPLAY: :10
- task: Npm@1
displayName: 'run $(TestSuiteName)'
inputs:
Expand Down
7 changes: 5 additions & 2 deletions src/client/common/terminal/activator/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ export class BaseTerminalActivator implements ITerminalActivator {
const deferred = createDeferred<boolean>();
this.activatedTerminals.set(terminal, deferred.promise);
const shellPath = this.helper.getTerminalShellPath();
// // tslint:disable-next-line:no-console
// console.log(shellPath);
// const shellPath = '/usr/bin/bash';
const terminalShellType = !shellPath || shellPath.length === 0 ? TerminalShellType.other : this.helper.identifyTerminalShell(shellPath);

const activationCommamnds = await this.helper.getEnvironmentActivationCommands(terminalShellType, resource);
// tslint:disable-next-line:no-console
console.log('Base.ts returned command', activationCommamnds);
console.log('in base.ts, terminalShellType', terminalShellType);
const activationCommamnds = await this.helper.getEnvironmentActivationCommands(terminalShellType, resource);
let activated = false;
if (activationCommamnds) {
for (const command of activationCommamnds!) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ export class PowershellTerminalActivationFailedHandler implements ITerminalActiv
}
// Check if we can activate in Command Prompt.
const activationCommands = await this.helper.getEnvironmentActivationCommands(TerminalShellType.commandPrompt, resource);
// tslint:disable-next-line:no-console
console.log('In powershellFailed.ts');
// tslint:disable-next-line:no-console
console.log(activationCommands);
if (!activationCommands || !Array.isArray(activationCommands) || activationCommands.length === 0) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ export abstract class BaseActivationCommandProvider implements ITerminalActivati
public abstract isShellSupported(targetShell: TerminalShellType): boolean;
public getActivationCommands(resource: Uri | undefined, targetShell: TerminalShellType): Promise<string[] | undefined> {
const pythonPath = this.serviceContainer.get<IConfigurationService>(IConfigurationService).getSettings(resource).pythonPath;
// tslint:disable-next-line:no-console
console.log('In baseActivation.ts', pythonPath);
return this.getActivationCommandsForInterpreter(pythonPath, targetShell);
}
public abstract getActivationCommandsForInterpreter(pythonPath: string, targetShell: TerminalShellType): Promise<string[] | undefined>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ export class Bash extends BaseActivationCommandProvider {
}
public async getActivationCommandsForInterpreter(pythonPath: string, targetShell: TerminalShellType): Promise<string[] | undefined> {
const scriptFile = await this.findScriptFile(pythonPath, this.getScriptsInOrderOfPreference(targetShell));
// tslint:disable-next-line:no-console
console.log('In bash.ts', pythonPath, '---', scriptFile, scriptFile.fileToCommandArgument());
if (!scriptFile) {
// tslint:disable-next-line:no-console
console.log('I should not be here');
return;
}
return [`source ${scriptFile.fileToCommandArgument()}`];
Expand Down
5 changes: 0 additions & 5 deletions src/client/common/terminal/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export class TerminalHelper implements ITerminalHelper {
public getTerminalShellPath(): string {
const workspace = this.serviceContainer.get<IWorkspaceService>(IWorkspaceService);
const shellConfig = workspace.getConfiguration('terminal.integrated.shell');

const platformService = this.serviceContainer.get<IPlatformService>(IPlatformService);
let osSection = '';
if (platformService.isWindows) {
Expand Down Expand Up @@ -91,8 +90,6 @@ export class TerminalHelper implements ITerminalHelper {
if (isCondaEnvironment) {
const condaActivationProvider = new CondaActivationCommandProvider(this.serviceContainer);
const activationCommands = await condaActivationProvider.getActivationCommands(resource, terminalShellType);
// tslint:disable-next-line:no-console
console.log('In conda helper.ts', activationCommands);
if (Array.isArray(activationCommands)) {
return activationCommands;
}
Expand All @@ -104,8 +101,6 @@ export class TerminalHelper implements ITerminalHelper {

for (const provider of supportedProviders) {
const activationCommands = await provider.getActivationCommands(resource, terminalShellType);
// tslint:disable-next-line:no-console
console.log('In helper.ts', activationCommands);
if (Array.isArray(activationCommands)) {
return activationCommands;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { expect } from 'chai';
import * as fs from 'fs-extra';
import * as os from 'os';
import * as path from 'path';
import * as vscode from 'vscode';
import { PYTHON_VIRTUAL_ENVS_LOCATION } from '../../../ciConstants';
Expand All @@ -13,6 +14,7 @@ import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../../../constants';
import { sleep } from '../../../core';
import { initialize, initializeTest } from '../../../initialize';

// tslint:disable-next-line:max-func-body-length
suite('Activation of Environments in Terminal', () => {
const file = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'testMultiRootWkspc', 'smokeTests', 'testExecInTerminal.py');
const outputFile = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'testMultiRootWkspc', 'smokeTests', 'testExecInTerminal.log');
Expand All @@ -26,12 +28,17 @@ suite('Activation of Environments in Terminal', () => {
virtualEnvPath: string;
};
let envPaths: EnvPath;
let defaultShell;
const defaultShell = {
Windows: '',
Linux: '',
MacOS: ''
};
let terminalSettings;
suiteSetup(async () => {
envPaths = await fs.readJson(envsLocation);
terminalSettings = vscode.workspace.getConfiguration('terminal', vscode.workspace.workspaceFolders[0].uri);
defaultShell = terminalSettings.inspect('integrated.shell.windows').globalValue;
defaultShell.Windows = terminalSettings.inspect('integrated.shell.windows').globalValue;
defaultShell.Linux = terminalSettings.inspect('integrated.shell.linux').globalValue;
await initialize();
});
setup(async () => {
Expand All @@ -42,7 +49,8 @@ suite('Activation of Environments in Terminal', () => {
suiteTeardown(revertSettings);
async function revertSettings() {
await updateSetting('terminal.activateEnvironment', undefined , vscode.workspace.workspaceFolders[0].uri, vscode.ConfigurationTarget.WorkspaceFolder);
await terminalSettings.update('integrated.shell.windows', defaultShell, vscode.ConfigurationTarget.Global);
await terminalSettings.update('integrated.shell.windows', defaultShell.Windows, vscode.ConfigurationTarget.Global);
await terminalSettings.update('integrated.shell.linux', defaultShell.Linux, vscode.ConfigurationTarget.Global);
await restorePythonPathInWorkspaceRoot();
}
async function cleanUp() {
Expand All @@ -51,17 +59,43 @@ suite('Activation of Environments in Terminal', () => {
}
}
async function testActivation(envPath){
// tslint:disable-next-line:no-console
console.log(`start1 ${envPath}`);
await updateSetting('terminal.activateEnvironment', true, vscode.workspace.workspaceFolders[0].uri, vscode.ConfigurationTarget.WorkspaceFolder);
// tslint:disable-next-line:no-console
console.log('start2');
await setPythonPathInWorkspaceRoot(envPath);
// const pyPath = vscode.workspace.getConfiguration('python', vscode.workspace.workspaceFolders[0].uri);
// // tslint:disable-next-line:no-console
// console.log(`Set pythonPath to ${pyPath.inspect('pythonPath').workspaceFolderValue}`);
// tslint:disable-next-line:no-console
console.log('start3');
const pyPath = vscode.workspace.getConfiguration('python', vscode.workspace.workspaceFolders[0].uri);
// tslint:disable-next-line:no-console
console.log(`Set pythonPath to ${pyPath.inspect('pythonPath').workspaceFolderValue}`);
if (os.platform() === 'linux'){
// tslint:disable-next-line:no-console
console.log('OS is linux, updating terminal shell Path');
await terminalSettings.update('integrated.shell.linux', '\\usr\\bin\\bash', vscode.ConfigurationTarget.Global);
}
// tslint:disable-next-line:no-console
console.log('Create terminal');
const terminal = vscode.window.createTerminal();
// tslint:disable-next-line:no-console
console.log('Waiting for activation');
await sleep(waitTimeForActivation);
// tslint:disable-next-line:no-console
console.log('Done waiting for activation');
// tslint:disable-next-line:no-console
console.log('Sending text');
terminal.sendText(`python ${file}`, true);
// tslint:disable-next-line:no-console
console.log('Waiting for output');
await waitForCondition(() => fs.pathExists(outputFile), 5_000, '\'testExecInTerminal.log\' file not created');
// tslint:disable-next-line:no-console
console.log('Read output file');
const content = await fs.readFile(outputFile, 'utf-8');

// tslint:disable-next-line:no-console
console.log('Done Reading');
// tslint:disable-next-line:no-console
console.log('Expect file content: ', content, 'to equal envPath: ', envPath);
expect(content).to.equal(envPath);
}
async function testNonActivation(){
Expand Down

0 comments on commit d7410d1

Please sign in to comment.