Skip to content

Commit c425a55

Browse files
committed
Merge remote-tracking branch 'upstream/master'
* upstream/master: Refactor parsing of environment variables (after 439) (#466) Refactor extension to remove old way of spawning python processes (#439)
2 parents 8d8d2fc + 576d50d commit c425a55

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1521
-1357
lines changed

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ function getFilesToProcess(options) {
309309
// If we need only modified files, then filter the glob.
310310
if (options && options.mode === 'changes') {
311311
return gulp.src(all, gulpSrcOptions)
312-
.pipe(gitmodified('M', 'A', 'D', 'R', 'C', 'U', '??'));
312+
.pipe(gitmodified(['M', 'A', 'D', 'R', 'C', 'U', '??']));
313313
}
314314

315315
if (options && options.mode === 'staged') {

package-lock.json

Lines changed: 115 additions & 110 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,6 +1559,7 @@
15591559
"@types/mocha": "^2.2.43",
15601560
"@types/node": "^6.0.40",
15611561
"@types/semver": "^5.4.0",
1562+
"@types/shortid": "0.0.29",
15621563
"@types/sinon": "^2.3.2",
15631564
"@types/uuid": "^3.3.27",
15641565
"@types/winreg": "^1.2.30",
@@ -1578,6 +1579,7 @@
15781579
"mocha": "^2.3.3",
15791580
"relative": "^3.0.2",
15801581
"retyped-diff-match-patch-tsd-ambient": "^1.0.0-0",
1582+
"shortid": "^2.2.8",
15811583
"sinon": "^2.3.6",
15821584
"tslint": "^5.7.0",
15831585
"tslint-eslint-rules": "^4.1.1",

src/client/common/configSettings.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { EventEmitter } from 'events';
55
import * as path from 'path';
66
import * as vscode from 'vscode';
77
import { Uri } from 'vscode';
8-
import { InterpreterInfoCache } from './interpreterInfoCache';
98
import { SystemVariables } from './variables/systemVariables';
109

1110
// tslint:disable-next-line:no-require-imports no-var-requires
@@ -188,12 +187,10 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
188187
// tslint:disable-next-line:no-unsafe-any
189188
this.disposables.forEach(disposable => disposable.dispose());
190189
this.disposables = [];
191-
InterpreterInfoCache.clear();
192190
}
193191

194192
// tslint:disable-next-line:cyclomatic-complexity max-func-body-length
195193
private initializeSettings() {
196-
InterpreterInfoCache.clear();
197194
const workspaceRoot = this.workspaceRoot.fsPath;
198195
const systemVariables: SystemVariables = new SystemVariables(this.workspaceRoot ? this.workspaceRoot.fsPath : undefined);
199196
const pythonSettings = vscode.workspace.getConfiguration('python', this.workspaceRoot);

src/client/common/decorators.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import * as _ from 'lodash';
2+
3+
type AsyncVoidAction = (...params: {}[]) => Promise<void>;
4+
type VoidAction = (...params: {}[]) => void;
5+
6+
/**
7+
* Debounces a function execution. Function must return either a void or a promise that resolves to a void.
8+
* @export
9+
* @param {number} [wait] Wait time.
10+
* @returns void
11+
*/
12+
export function debounce(wait?: number) {
13+
// tslint:disable-next-line:no-any no-function-expression
14+
return function (_target: any, _propertyName: string, descriptor: TypedPropertyDescriptor<VoidAction> | TypedPropertyDescriptor<AsyncVoidAction>) {
15+
const originalMethod = descriptor.value!;
16+
// tslint:disable-next-line:no-invalid-this no-any
17+
(descriptor as any).value = _.debounce(function () { return originalMethod.apply(this, arguments); }, wait);
18+
};
19+
}
20+
21+
/**
22+
* Swallows exceptions thrown by a function. Function must return either a void or a promise that resolves to a void.
23+
* @export
24+
* @param {string} [scopeName] Scope for the error message to be logged along with the error.
25+
* @returns void
26+
*/
27+
export function swallowExceptions(scopeName: string) {
28+
// tslint:disable-next-line:no-any no-function-expression
29+
return function (_target: any, propertyName: string, descriptor: TypedPropertyDescriptor<VoidAction> | TypedPropertyDescriptor<AsyncVoidAction>) {
30+
const originalMethod = descriptor.value!;
31+
const errorMessage = `Python Extension (Error in ${scopeName}, method:${propertyName}):`;
32+
// tslint:disable-next-line:no-any no-function-expression
33+
descriptor.value = function (...args: any[]) {
34+
try {
35+
// tslint:disable-next-line:no-invalid-this no-use-before-declare no-unsafe-any
36+
const result = originalMethod.apply(this, args);
37+
38+
// If method being wrapped returns a promise then wait and swallow errors.
39+
if (result && typeof result.then === 'function' && typeof result.catch === 'function') {
40+
return (result as Promise<void>).catch(error => console.error(errorMessage, error));
41+
}
42+
} catch (error) {
43+
console.error(errorMessage, error);
44+
}
45+
};
46+
};
47+
}

src/client/common/interpreterInfoCache.ts

Lines changed: 0 additions & 54 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { injectable } from 'inversify';
2+
import { ICurrentProcess } from '../types';
3+
import { EnvironmentVariables } from '../variables/types';
4+
5+
@injectable()
6+
export class CurrentProcess implements ICurrentProcess {
7+
public get env(): EnvironmentVariables {
8+
return process.env;
9+
}
10+
}

src/client/common/process/pythonExecutionFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class PythonExecutionFactory implements IPythonExecutionFactory {
1414
@inject(IEnvironmentVariablesProvider) private envVarsService: IEnvironmentVariablesProvider) { }
1515
public async create(resource?: Uri): Promise<IPythonExecutionService> {
1616
const settings = PythonSettings.getInstance(resource);
17-
return this.envVarsService.getEnvironmentVariables(true, resource)
17+
return this.envVarsService.getEnvironmentVariables(resource)
1818
.then(customEnvVars => {
1919
return new PythonExecutionService(this.procService, settings.pythonPath, customEnvVars);
2020
});

src/client/common/serviceRegistry.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import { IS_64_BIT, IS_WINDOWS } from './platform/constants';
1212
import { PathUtils } from './platform/pathUtils';
1313
import { RegistryImplementation } from './platform/registry';
1414
import { IRegistry } from './platform/types';
15+
import { CurrentProcess } from './process/currentProcess';
1516
import { TerminalService } from './terminal/service';
1617
import { ITerminalService } from './terminal/types';
17-
import { IInstaller, ILogger, IPathUtils, IPersistentStateFactory, Is64Bit, IsWindows } from './types';
18+
import { ICurrentProcess, IInstaller, ILogger, IPathUtils, IPersistentStateFactory, Is64Bit, IsWindows } from './types';
1819

1920
export function registerTypes(serviceManager: IServiceManager) {
2021
serviceManager.addSingletonInstance<boolean>(IsWindows, IS_WINDOWS);
@@ -27,6 +28,7 @@ export function registerTypes(serviceManager: IServiceManager) {
2728
serviceManager.addSingleton<ILogger>(ILogger, Logger);
2829
serviceManager.addSingleton<ITerminalService>(ITerminalService, TerminalService);
2930
serviceManager.addSingleton<IPathUtils>(IPathUtils, PathUtils);
31+
serviceManager.addSingleton<ICurrentProcess>(ICurrentProcess, CurrentProcess);
3032

3133
if (IS_WINDOWS) {
3234
serviceManager.addSingleton<IRegistry>(IRegistry, RegistryImplementation);

src/client/common/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT License.
44

55
import { Uri } from 'vscode';
6+
import { EnvironmentVariables } from './variables/types';
67
export const IOutputChannel = Symbol('IOutputChannel');
78
export const IDocumentSymbolProvider = Symbol('IDocumentSymbolProvider');
89
export const IsWindows = Symbol('IS_WINDOWS');
@@ -80,3 +81,8 @@ export const IPathUtils = Symbol('IPathUtils');
8081
export interface IPathUtils {
8182
getPathVariableName(): 'Path' | 'PATH';
8283
}
84+
85+
export const ICurrentProcess = Symbol('ICurrentProcess');
86+
export interface ICurrentProcess {
87+
env: EnvironmentVariables;
88+
}

0 commit comments

Comments
 (0)