-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes to failing functional tests (#67)
* Fixes to failing functional tests * Fixes
- Loading branch information
1 parent
44897e2
commit c280df1
Showing
7 changed files
with
61 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,65 @@ | ||
import { injectable } from 'inversify'; | ||
/* eslint-disable implicit-arrow-linebreak */ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { EventEmitter, Uri } from 'vscode'; | ||
import { injectable } from 'inversify'; | ||
import { Event, EventEmitter, Uri } from 'vscode'; | ||
import { getInterpreterInfo } from '.'; | ||
import { Resource } from '../../client/common/types'; | ||
import { IInterpreterService } from '../../client/interpreter/contracts'; | ||
import { PythonEnvironment } from '../../client/pythonEnvironments/info'; | ||
|
||
let interpretersCache: Promise<PythonEnvironment[]> | undefined; | ||
@injectable() | ||
export class InterpreterService implements IInterpreterService { | ||
public readonly onDidChangeInterpreter = new EventEmitter<void>().event; | ||
public readonly didChangeInterpreter = new EventEmitter<void>(); | ||
|
||
public get onDidChangeInterpreter(): Event<void> { | ||
return this.didChangeInterpreter.event; | ||
} | ||
|
||
private readonly customInterpretersPerUri = new Map<string, string>(); | ||
|
||
public async getInterpreters(_resource?: Uri): Promise<PythonEnvironment[]> { | ||
const [active, globalInterpreter] = await Promise.all([ | ||
getInterpreterInfo(process.env.CI_PYTHON_PATH as string), | ||
getInterpreterInfo('python') | ||
]); | ||
const interpreters: PythonEnvironment[] = []; | ||
if (active) { | ||
interpreters.push(active); | ||
} | ||
if (globalInterpreter) { | ||
interpreters.push(globalInterpreter); | ||
if (interpretersCache) { | ||
return interpretersCache; | ||
} | ||
return interpreters; | ||
interpretersCache = getAllInterpreters(); | ||
return interpretersCache; | ||
} | ||
|
||
public async getActiveInterpreter(_resource?: Uri): Promise<PythonEnvironment | undefined> { | ||
return getInterpreterInfo(process.env.CI_PYTHON_PATH || 'python'); | ||
public async getActiveInterpreter(resource?: Uri): Promise<PythonEnvironment | undefined> { | ||
const pythonPath = this.customInterpretersPerUri.has(resource?.fsPath || '') | ||
? this.customInterpretersPerUri.get(resource?.fsPath || '')! | ||
: process.env.CI_PYTHON_PATH || 'python'; | ||
return getInterpreterInfo(pythonPath); | ||
} | ||
|
||
public async getInterpreterDetails(pythonPath: string, _resource?: Uri): Promise<undefined | PythonEnvironment> { | ||
return getInterpreterInfo(pythonPath); | ||
} | ||
|
||
public initialize(): void { | ||
// Noop. | ||
public updateInterpreter(resource: Resource, pythonPath: string): void { | ||
if (pythonPath.trim().length > 0) { | ||
this.customInterpretersPerUri.set(resource?.fsPath || '', pythonPath); | ||
} | ||
this.didChangeInterpreter.fire(); | ||
} | ||
} | ||
|
||
async function getAllInterpreters(): Promise<PythonEnvironment[]> { | ||
const allInterpreters = await Promise.all([ | ||
getInterpreterInfo(process.env.CI_PYTHON_PATH as string), | ||
getInterpreterInfo(process.env.CI_PYTHON_PATH2 as string), | ||
getInterpreterInfo('python') | ||
]); | ||
const interpreters: PythonEnvironment[] = []; | ||
const items = new Set<string>(); | ||
allInterpreters.forEach((item) => { | ||
if (item && !items.has(item.path)) { | ||
items.add(item.path); | ||
interpreters.push(item); | ||
} | ||
}); | ||
return interpreters; | ||
} |