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

Activate environment in terminal #614

Merged
merged 86 commits into from
Jan 23, 2018

Conversation

DonJayamanne
Copy link

Fixes #383

octref and others added 30 commits November 3, 2017 13:11
* 'master' of https://github.com/Microsoft/vscode-python:
  Fixes #56 list all environments (#219)
  Fixes #57 Disable activation on debugging (#220)
  Fixes #26 Do not run linters when linters are disabled (#222)
* upstream/master:
  Fix typo in README.md (#252)
  Disable linter without workspaces (#241)
* upstream/master:
  Fix feedback service (#246)
  Fix django context initializer (#248)
  disable generation of tags file upon extension load (#264)
* upstream/master:
  Resolve pythonPath before comparing it to shebang (#273)
* upstream/master:
  Fixes #22 to Detect anaconda from known locations  (#221)
  Use workspaceFolder token instead of workspaceRoot (#267)
  Fix registry lookup response (#224)
  Fix issues when running without debugging and debugged code terminates (#249)
* upstream/master:
  Fix debugging tests (#304)
* upstream/master:
  Remove jupyter functionality in favor of Jupyter extension (#302)
  Drop Python 2 URLs (#307)
* upstream/master:
  Remove setting python.formatting.formatOnSave in favor of the vs code setting (#312)
* upstream/master:
  Remove setting linting.lintOnTextChange as it was never implemented (#315)
* upstream/master:
  Fix travis build error (#326)
* upstream/master:
  add new npm deps with improved gulp for dev (#328)
* upstream/master:
  Update version of inversify package (#329)
* upstream/master:
  Document our dev process (#330)
* upstream/master:
  Document contribution to the code along with coding standards (#321)
* upstream/master:
  Add Simplified Chinese translation of commands (#240)
* upstream/master:
  Fix package.json (#347)
* upstream/master:
  #34, #110 - suppress Intellisense in strings and comments (#339)
  Re-factor code python execution framework  (#345)
* upstream/master:
  Fix linters to make use of the new python code execution framework (#360)
  Update the versioning scheme (#356)
  Make npm happy in regards to line endings (#357)
* upstream/master:
  Ensure python path is not set if already set in user settings (#369)
  Use 'an' rather than 'a' before vowel words (#373)
* upstream/master:
  Use new environment variable parser (#362)
@codecov
Copy link

codecov bot commented Jan 23, 2018

Codecov Report

Merging #614 into master will increase coverage by 2.6%.
The diff coverage is 90.25%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #614     +/-   ##
=========================================
+ Coverage   58.06%   60.67%   +2.6%     
=========================================
  Files         225      228      +3     
  Lines       10152    10125     -27     
  Branches     1751     1753      +2     
=========================================
+ Hits         5895     6143    +248     
+ Misses       4252     3977    -275     
  Partials        5        5
Impacted Files Coverage Δ
src/client/common/application/types.ts 100% <ø> (ø) ⬆️
src/client/terminals/types.ts 100% <ø> (ø) ⬆️
src/client/interpreter/locators/services/conda.ts 100% <ø> (ø) ⬆️
src/client/common/platform/types.ts 100% <ø> (ø) ⬆️
...erminals/codeExecution/djangoShellCodeExecution.ts 100% <100%> (ø) ⬆️
src/client/interpreter/display/index.ts 97.43% <100%> (-0.44%) ⬇️
src/client/extension.ts 93.95% <100%> (-0.09%) ⬇️
src/client/common/terminal/types.ts 100% <100%> (ø) ⬆️
src/client/terminals/serviceRegistry.ts 100% <100%> (ø) ⬆️
src/client/providers/replProvider.ts 100% <100%> (+40%) ⬆️
... and 51 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ba069d2...8bf8a17. Read the comment docs.

@DonJayamanne
Copy link
Author

@brettcannon @MikhailArkhipov
I'm finishing up some minor issues and tests.
Please could you review this.

import { IFileSystem, IPlatformService } from './types';

@injectable()
export class FileSystem implements IFileSystem {
constructor( @inject(IServiceContainer) private platformService: IPlatformService) { }
constructor( @inject(IPlatformService) private platformService: IPlatformService) { }

Choose a reason for hiding this comment

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

Up to you, there is always a discussion if one should pass container or just minimal service(s). However, if we are to switch to our own container implementation, it may not be injectable so we'll have to pass around container anyway.

Copy link
Author

Choose a reason for hiding this comment

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

I agree, just didn't want to change existing code.
The plan going forward is to only pass the service container

}
public async getActivationCommands(interpreter: PythonInterpreter, targetShell: TerminalShellType): Promise<string | string[] | undefined> {
// Dependending on the target shell, look for the preferred script file.
const scriptsInOrderOfPreference = targetShell === TerminalShellType.commandPrompt ? ['activate.bat', 'activate.ps1'] : ['activate.ps1', 'activate.bat'];

Choose a reason for hiding this comment

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

activate.cmd ?

Copy link
Author

Choose a reason for hiding this comment

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

I couldn't find such a file in the python virtual environment directories.

Choose a reason for hiding this comment

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

OK. bat is usually old DOS thing, XP, win7 used to use cmd. Poweshell comes with Win10 preinstalled I think.

return;
}

const quotedScriptFile = scriptFile.indexOf(' ') > 0 ? `"${scriptFile}"` : scriptFile;

Choose a reason for hiding this comment

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

Looks like sequence used several times, perhaps move to findScriptFile ?

Copy link
Author

Choose a reason for hiding this comment

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

Don't think thats right. The find shoudl only return the file, this is responsible for building the command for execution, and when a file has a space, then we need to quote it.
Can create a separate helper such as "quoteFilePath"

// import { IServiceContainer } from '../../../ioc/types';
// import { TerminalShellType } from '../types';
// import { BaseActivationCommandProvider } from './baseActivationProvider';

Choose a reason for hiding this comment

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

tslint hates all-comments

Copy link
Author

Choose a reason for hiding this comment

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

oop

Copy link
Author

Choose a reason for hiding this comment

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

supposed to be removed.

const supportedProviders = providers.filter(provider => provider.isShellSupported(terminalShellType));

for (const provider of supportedProviders) {
const activationCommands = await provider.getActivationCommands(interperterInfo, terminalShellType);

Choose a reason for hiding this comment

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

So we pick just the first one, right?

Copy link
Author

Choose a reason for hiding this comment

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

Yes.

return this.terminalServices.get(id)!;
}
private getTerminalId(resource?: Uri, title?: string): string {
const terminalTitle = title ? title! : '';

Choose a reason for hiding this comment

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

Bang probably not needed

Choose a reason for hiding this comment

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

Perhaps something generic title, like 'Python'?

Copy link
Author

Choose a reason for hiding this comment

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

Fixed.


export interface ITerminalActivationCommandProvider {
isShellSupported(targetShell: TerminalShellType): boolean;
getActivationCommands(interpreter: PythonInterpreter, targetShell: TerminalShellType): Promise<string | string[] | undefined>;

Choose a reason for hiding this comment

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

Might be simpler to have it always return an array, fewer cases to handle for the caller

Copy link
Author

Choose a reason for hiding this comment

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

👍

@DonJayamanne DonJayamanne merged commit 0253995 into microsoft:master Jan 23, 2018
@DonJayamanne DonJayamanne changed the title WIP - Activate environment in terminal Activate environment in terminal Jan 23, 2018
@DonJayamanne DonJayamanne deleted the activateEnvInTerminal branch January 25, 2018 19:33
@lock lock bot locked as resolved and limited conversation to collaborators Jul 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Automatic Environment Activation in Terminal
3 participants