-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve virtual env detection + #807 (#831)
* Fix pylint search * Handle quote escapes in strings * Escapes in strings * CR feedback * Missing pip * Test * Tests * Tests * Mac python path * Tests * Tests * Test * "Go To Python object" doesn't work * Proper detection and type population in virtual env * Test fixes * Simplify venv check * Remove duplicates * Test * Discover pylintrc better + tests * Undo change * CR feedback * Set interprereter before checking install * Fix typo and path compare on Windows * Rename method * #815 - 'F' in flake8 means warning
- Loading branch information
Mikhail Arkhipov
authored
Feb 20, 2018
1 parent
6eabde4
commit 7894ae6
Showing
19 changed files
with
212 additions
and
143 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,26 @@ | ||
import { injectable, multiInject } from 'inversify'; | ||
import { IVirtualEnvironmentIdentifier, IVirtualEnvironmentManager } from './types'; | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { inject, injectable } from 'inversify'; | ||
import { IProcessService } from '../../common/process/types'; | ||
import { IServiceContainer } from '../../ioc/types'; | ||
import { IVirtualEnvironmentManager } from './types'; | ||
|
||
@injectable() | ||
export class VirtualEnvironmentManager implements IVirtualEnvironmentManager { | ||
constructor(@multiInject(IVirtualEnvironmentIdentifier) private envs: IVirtualEnvironmentIdentifier[]) { | ||
private processService: IProcessService; | ||
constructor(@inject(IServiceContainer) serviceContainer: IServiceContainer) { | ||
this.processService = serviceContainer.get<IProcessService>(IProcessService); | ||
} | ||
public detect(pythonPath: string): Promise<IVirtualEnvironmentIdentifier | undefined> { | ||
const promises = this.envs | ||
.map(item => item.detect(pythonPath) | ||
.then(result => { | ||
return { env: item, result }; | ||
})); | ||
|
||
return Promise.all(promises) | ||
.then(results => { | ||
const env = results.find(items => items.result === true); | ||
return env ? env.env : undefined; | ||
}); | ||
public async getEnvironmentName(pythonPath: string): Promise<string> { | ||
// https://stackoverflow.com/questions/1871549/determine-if-python-is-running-inside-virtualenv | ||
const output = await this.processService.exec(pythonPath, ['-c', 'import sys;print(hasattr(sys, "real_prefix"))']); | ||
if (output.stdout.length > 0) { | ||
const result = output.stdout.trim(); | ||
if (result === 'True') { | ||
return 'virtualenv'; | ||
} | ||
} | ||
return ''; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,15 +1,7 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { InterpreterType } from '../contracts'; | ||
export const IVirtualEnvironmentIdentifier = Symbol('IVirtualEnvironment'); | ||
|
||
export interface IVirtualEnvironmentIdentifier { | ||
readonly name: string; | ||
readonly type: InterpreterType.VEnv | InterpreterType.VirtualEnv; | ||
detect(pythonPath: string): Promise<boolean>; | ||
} | ||
export const IVirtualEnvironmentManager = Symbol('VirtualEnvironmentManager'); | ||
export interface IVirtualEnvironmentManager { | ||
detect(pythonPath: string): Promise<IVirtualEnvironmentIdentifier | undefined>; | ||
getEnvironmentName(pythonPath: string): Promise<string>; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.