forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
DonJayamanne
merged 86 commits into
microsoft:master
from
DonJayamanne:activateEnvInTerminal
Jan 23, 2018
Merged
Changes from 81 commits
Commits
Show all changes
86 commits
Select commit
Hold shift + click to select a range
ecc1ca9
Fix Microsoft/vscode#37627 (#1368)
octref 7c5778c
Version 0.7.0 of extension (#1381)
DonJayamanne 9d1bf82
Update README.md
DonJayamanne ffba179
Update README.md
DonJayamanne 905c713
sync fork with upstream
DonJayamanne acc2109
fix readme
DonJayamanne d470523
Merge branch 'master' of https://github.com/Microsoft/vscode-python
DonJayamanne d392e8b
merged upstream
DonJayamanne 92f775f
Merge remote-tracking branch 'upstream/master'
DonJayamanne 32a6e53
Merge remote-tracking branch 'upstream/master'
DonJayamanne 4b30f2c
Merge remote-tracking branch 'upstream/master'
DonJayamanne e396752
Merge remote-tracking branch 'upstream/master'
DonJayamanne eff4792
Merge remote-tracking branch 'upstream/master'
DonJayamanne 4553c28
Merge remote-tracking branch 'upstream/master'
DonJayamanne 3c6520a
Merge remote-tracking branch 'upstream/master'
DonJayamanne 966e516
Merge remote-tracking branch 'upstream/master'
DonJayamanne 63d2d65
Merge remote-tracking branch 'upstream/master'
DonJayamanne f6d469e
Merge remote-tracking branch 'upstream/master'
DonJayamanne 029e055
Merge remote-tracking branch 'upstream/master'
DonJayamanne e8c71c0
Merge remote-tracking branch 'upstream/master'
DonJayamanne 51cf9d2
Merge remote-tracking branch 'upstream/master'
DonJayamanne 7aadc43
Merge remote-tracking branch 'upstream/master'
DonJayamanne f0f5c59
Merge remote-tracking branch 'upstream/master'
DonJayamanne b2b9da9
Merge remote-tracking branch 'upstream/master'
DonJayamanne 30a4091
Merge remote-tracking branch 'upstream/master'
DonJayamanne b16d2f9
Merge remote-tracking branch 'upstream/master'
DonJayamanne c8db345
Merge remote-tracking branch 'upstream/master'
DonJayamanne 0df7f16
Merge remote-tracking branch 'upstream/master'
DonJayamanne 3ccc881
Merge remote-tracking branch 'upstream/master'
DonJayamanne bb0709e
Merge remote-tracking branch 'upstream/master'
DonJayamanne 2c19004
Merge remote-tracking branch 'upstream/master'
DonJayamanne 8f224ab
Merge remote-tracking branch 'upstream/master'
DonJayamanne 41b7080
Merge remote-tracking branch 'upstream/master'
DonJayamanne dab38dc
Merge remote-tracking branch 'upstream/master'
DonJayamanne ae22dd4
Merge remote-tracking branch 'upstream/master'
DonJayamanne d2340d2
Merge remote-tracking branch 'upstream/master'
DonJayamanne 52bb7ae
Merge remote-tracking branch 'upstream/master'
DonJayamanne b6b2531
Merge remote-tracking branch 'upstream/master'
DonJayamanne 8d8d2fc
Merge remote-tracking branch 'upstream/master'
DonJayamanne c425a55
Merge remote-tracking branch 'upstream/master'
DonJayamanne 3963217
Merge remote-tracking branch 'upstream/master'
DonJayamanne a696f2a
Merge remote-tracking branch 'upstream/master'
DonJayamanne a31e659
Merge remote-tracking branch 'upstream/master'
DonJayamanne 2663cd5
Merge remote-tracking branch 'upstream/master'
DonJayamanne 7c85e0b
Merge remote-tracking branch 'upstream/master'
DonJayamanne beb82c2
Merge remote-tracking branch 'upstream/master'
DonJayamanne 01e722a
Merge remote-tracking branch 'upstream/master'
DonJayamanne 06cf61c
first set
DonJayamanne 83148c1
tests for terminal services
DonJayamanne b336bd1
remove unsed var
DonJayamanne 5489575
refactor execution of code in terminals
DonJayamanne 7de62aa
revert change to tests grep
DonJayamanne 36d2aa5
removed duplicate type definition
DonJayamanne 686aca9
ensure title is set
DonJayamanne ddc46c9
revert retry count
DonJayamanne 4571e48
account for PYTHONPATH in current test environment (existing machine)
DonJayamanne d84da8e
Merge remote-tracking branch 'upstream/master'
DonJayamanne c8b7185
terminal service can only be created through factory
DonJayamanne 5c6e50c
add method to get active interpeter info
DonJayamanne 78da3e1
Merge remote-tracking branch 'upstream/master'
DonJayamanne efba660
refactor conda service
DonJayamanne 8d67246
fix tests
DonJayamanne d9a23fd
incremental
DonJayamanne b735c7e
added activation scripts
DonJayamanne 2262a6f
merged
DonJayamanne 2ebe2e6
fix terminal tests
DonJayamanne 0b71c44
fix linter error
DonJayamanne fc8d5b5
revert changes
DonJayamanne 9593d24
refactor REPL provider to use new terminal services
DonJayamanne fdc03e5
refactor activation commands
DonJayamanne 7d82c77
revert change
DonJayamanne 685b683
Merge remote-tracking branch 'upstream/master'
DonJayamanne c165901
merged master
DonJayamanne fb6142a
fix detection of conda tests
DonJayamanne 0ff33e9
tests for bash,cshell and fish activation scripts
DonJayamanne 7ba90db
better test suite names
DonJayamanne faf48b5
added more tests
DonJayamanne 605fabe
added tests for env activation
DonJayamanne 96a4571
added tests for activation commands
DonJayamanne a8b4e7c
fix linter errors
DonJayamanne 001fc30
unit tests for repl provider
DonJayamanne b9d503b
fix code review comments
DonJayamanne 264e52a
extension method to quote strings for cmd args
DonJayamanne 3e7c1aa
give preference to scripts based on shell
DonJayamanne 2985dad
fix types of script files supported by shells
DonJayamanne 8bf8a17
activate terminal before displaying it
DonJayamanne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/client/common/terminal/environmentActivationProviders/baseActivationProvider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { injectable } from 'inversify'; | ||
import * as path from 'path'; | ||
import { PythonInterpreter } from '../../../interpreter/contracts'; | ||
import { IServiceContainer } from '../../../ioc/types'; | ||
import { IFileSystem } from '../../platform/types'; | ||
import { TerminalShellType } from '../types'; | ||
import { ITerminalActivationCommandProvider } from '../types'; | ||
|
||
@injectable() | ||
export abstract class BaseActivationCommandProvider implements ITerminalActivationCommandProvider { | ||
constructor(protected readonly serviceContainer: IServiceContainer) { } | ||
|
||
public abstract isShellSupported(targetShell: TerminalShellType): boolean; | ||
public abstract getActivationCommands(interpreter: PythonInterpreter, targetShell: TerminalShellType): Promise<string | string[] | undefined>; | ||
|
||
protected async findScriptFile(interpreter: PythonInterpreter, scriptFileNames: string[]): Promise<string | undefined> { | ||
const fs = this.serviceContainer.get<IFileSystem>(IFileSystem); | ||
|
||
for (const scriptFileName of scriptFileNames) { | ||
// Generate scripts are found in the same directory as the interpreter. | ||
const scriptFile = path.join(path.dirname(interpreter.path), scriptFileName); | ||
const found = await fs.fileExistsAsync(scriptFile); | ||
if (found) { | ||
return scriptFile; | ||
} | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/client/common/terminal/environmentActivationProviders/bash.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { inject, injectable } from 'inversify'; | ||
import { PythonInterpreter } from '../../../interpreter/contracts'; | ||
import { IServiceContainer } from '../../../ioc/types'; | ||
import { TerminalShellType } from '../types'; | ||
import { BaseActivationCommandProvider } from './baseActivationProvider'; | ||
|
||
@injectable() | ||
export class Bash extends BaseActivationCommandProvider { | ||
constructor( @inject(IServiceContainer) serviceContainer: IServiceContainer) { | ||
super(serviceContainer); | ||
} | ||
public isShellSupported(targetShell: TerminalShellType): boolean { | ||
return targetShell === TerminalShellType.bash || | ||
targetShell === TerminalShellType.cshell || | ||
targetShell === TerminalShellType.fish; | ||
} | ||
public async getActivationCommands(interpreter: PythonInterpreter, targetShell: TerminalShellType): Promise<string | string[] | undefined> { | ||
const scriptFile = await this.findScriptFile(interpreter, ['activate', 'activate.sh', 'activate.csh', 'activate.fish']); | ||
if (!scriptFile) { | ||
return; | ||
} | ||
const quotedScriptFile = scriptFile.indexOf(' ') > 0 ? `"${scriptFile}"` : scriptFile; | ||
const envName = interpreter.envName ? interpreter.envName! : ''; | ||
// In the case of conda environments, the name of the environment must be provided. | ||
// E.g. `source acrtivate <envname>`. | ||
return `source ${quotedScriptFile} ${envName}`.trim(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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