From d7aa9536538788e53d46a5ab73183e95c9a95b2e Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Mon, 18 Dec 2017 11:23:32 -0800 Subject: [PATCH 1/4] import reflect-metadata once per extension --- src/client/common/envFileParser.ts | 1 - src/client/common/installer/condaInstaller.ts | 1 - src/client/common/installer/installer.ts | 1 - src/client/common/installer/moduleInstaller.ts | 1 - src/client/common/installer/pipInstaller.ts | 1 - src/client/common/logger.ts | 1 - src/client/common/persistentState.ts | 1 - src/client/common/platform/pathUtils.ts | 1 - src/client/common/platform/registry.ts | 1 - src/client/common/process/decoder.ts | 1 - src/client/common/process/proc.ts | 1 - src/client/common/process/pythonExecutionFactory.ts | 1 - src/client/common/process/pythonProcess.ts | 1 - src/client/common/process/serviceRegistry.ts | 2 -- src/client/common/serviceRegistry.ts | 1 - src/client/common/terminal/service.ts | 1 - src/client/common/variables/environment.ts | 1 - src/client/common/variables/environmentVariablesProvider.ts | 1 - src/client/common/variables/serviceRegistry.ts | 2 -- src/client/debugger/Main.ts | 1 - src/client/extension.ts | 5 +++++ src/client/formatters/helper.ts | 1 - src/client/formatters/serviceRegistry.ts | 1 - src/client/interpreter/interpreterVersion.ts | 1 - .../interpreter/locators/services/KnownPathsService.ts | 1 - .../interpreter/locators/services/condaEnvFileService.ts | 1 - src/client/interpreter/locators/services/condaEnvService.ts | 1 - src/client/interpreter/locators/services/condaLocator.ts | 1 - .../interpreter/locators/services/currentPathService.ts | 1 - .../interpreter/locators/services/virtualEnvService.ts | 1 - src/client/interpreter/serviceRegistry.ts | 1 - src/client/interpreter/virtualEnvs/venv.ts | 1 - src/client/interpreter/virtualEnvs/virtualEnv.ts | 1 - src/client/linters/helper.ts | 1 - src/client/linters/serviceRegistry.ts | 1 - src/client/unittests/common/debugLauncher.ts | 1 - src/client/unittests/common/services/storageService.ts | 1 - src/client/unittests/common/services/testResultsService.ts | 1 - .../common/services/workspaceTestManagerService.ts | 1 - src/client/unittests/common/testUtils.ts | 1 - .../unittests/common/testVisitors/flatteningVisitor.ts | 1 - .../common/testVisitors/folderGenerationVisitor.ts | 1 - .../unittests/common/testVisitors/resultResetVisitor.ts | 1 - src/client/unittests/nosetest/main.ts | 1 - src/client/unittests/nosetest/services/discoveryService.ts | 1 - src/client/unittests/nosetest/services/parserService.ts | 1 - src/client/unittests/pytest/services/discoveryService.ts | 1 - src/client/unittests/pytest/services/parserService.ts | 1 - src/client/unittests/serviceRegistry.ts | 1 - src/client/unittests/unittest/services/discoveryService.ts | 1 - src/client/unittests/unittest/services/parserService.ts | 1 - src/test/index.ts | 1 + src/test/mocks/proc.ts | 1 - src/test/mocks/terminalService.ts | 1 - src/test/serviceRegistry.ts | 1 - src/test/unittests/mocks.ts | 1 - src/test/unittests/serviceRegistry.ts | 6 +----- 57 files changed, 7 insertions(+), 61 deletions(-) diff --git a/src/client/common/envFileParser.ts b/src/client/common/envFileParser.ts index cc0013abffde..18ac1655ee51 100644 --- a/src/client/common/envFileParser.ts +++ b/src/client/common/envFileParser.ts @@ -1,5 +1,4 @@ import * as fs from 'fs-extra'; -import 'reflect-metadata'; import { PathUtils } from './platform/pathUtils'; import { EnvironmentVariablesService } from './variables/environment'; import { EnvironmentVariables } from './variables/types'; diff --git a/src/client/common/installer/condaInstaller.ts b/src/client/common/installer/condaInstaller.ts index ed1c523d09e8..f51ebdd3ecc4 100644 --- a/src/client/common/installer/condaInstaller.ts +++ b/src/client/common/installer/condaInstaller.ts @@ -3,7 +3,6 @@ import { inject, injectable } from 'inversify'; import * as path from 'path'; -import 'reflect-metadata'; import { Uri } from 'vscode'; import { ICondaLocatorService, IInterpreterLocatorService, INTERPRETER_LOCATOR_SERVICE, InterpreterType } from '../../interpreter/contracts'; import { CONDA_RELATIVE_PY_PATH } from '../../interpreter/locators/services/conda'; diff --git a/src/client/common/installer/installer.ts b/src/client/common/installer/installer.ts index a78405d0670a..c232047e141e 100644 --- a/src/client/common/installer/installer.ts +++ b/src/client/common/installer/installer.ts @@ -1,7 +1,6 @@ import { inject, injectable, named } from 'inversify'; import * as os from 'os'; import * as path from 'path'; -import 'reflect-metadata'; import { ConfigurationTarget, QuickPickItem, Uri, window, workspace } from 'vscode'; import * as vscode from 'vscode'; import { IFormatterHelper } from '../../formatters/types'; diff --git a/src/client/common/installer/moduleInstaller.ts b/src/client/common/installer/moduleInstaller.ts index f20e6f498602..25bbd88d55cb 100644 --- a/src/client/common/installer/moduleInstaller.ts +++ b/src/client/common/installer/moduleInstaller.ts @@ -2,7 +2,6 @@ // Licensed under the MIT License. import { injectable } from 'inversify'; -import 'reflect-metadata'; import { Uri } from 'vscode'; import { IServiceContainer } from '../../ioc/types'; import { PythonSettings } from '../configSettings'; diff --git a/src/client/common/installer/pipInstaller.ts b/src/client/common/installer/pipInstaller.ts index 6379453bc1d9..fe522521a491 100644 --- a/src/client/common/installer/pipInstaller.ts +++ b/src/client/common/installer/pipInstaller.ts @@ -2,7 +2,6 @@ // Licensed under the MIT License. import { inject, injectable } from 'inversify'; -import 'reflect-metadata'; import { Uri, workspace } from 'vscode'; import { IServiceContainer } from '../../ioc/types'; import { IPythonExecutionFactory } from '../process/types'; diff --git a/src/client/common/logger.ts b/src/client/common/logger.ts index a0c9f886e53f..0c3047dda72d 100644 --- a/src/client/common/logger.ts +++ b/src/client/common/logger.ts @@ -1,5 +1,4 @@ import { injectable } from 'inversify'; -import 'reflect-metadata'; import { ILogger } from './types'; const PREFIX = 'Python Extension: '; diff --git a/src/client/common/persistentState.ts b/src/client/common/persistentState.ts index fb505c97826a..37e19af5f0fa 100644 --- a/src/client/common/persistentState.ts +++ b/src/client/common/persistentState.ts @@ -4,7 +4,6 @@ 'use strict'; import { inject, injectable, named } from 'inversify'; -import 'reflect-metadata'; import { Memento } from 'vscode'; import { GLOBAL_MEMENTO, IMemento, IPersistentState, IPersistentStateFactory, WORKSPACE_MEMENTO } from './types'; diff --git a/src/client/common/platform/pathUtils.ts b/src/client/common/platform/pathUtils.ts index b9f1779d8c63..893bdae38c7d 100644 --- a/src/client/common/platform/pathUtils.ts +++ b/src/client/common/platform/pathUtils.ts @@ -1,5 +1,4 @@ import { inject, injectable } from 'inversify'; -import 'reflect-metadata'; import { IPathUtils, IsWindows } from '../types'; import { NON_WINDOWS_PATH_VARIABLE_NAME, WINDOWS_PATH_VARIABLE_NAME } from './constants'; diff --git a/src/client/common/platform/registry.ts b/src/client/common/platform/registry.ts index f82e95713976..0ceec56c11d7 100644 --- a/src/client/common/platform/registry.ts +++ b/src/client/common/platform/registry.ts @@ -1,5 +1,4 @@ import { injectable } from 'inversify'; -import 'reflect-metadata'; import * as Registry from 'winreg'; import { Architecture, IRegistry, RegistryHive } from './types'; diff --git a/src/client/common/process/decoder.ts b/src/client/common/process/decoder.ts index e3a35a458ab4..4e03b48501d0 100644 --- a/src/client/common/process/decoder.ts +++ b/src/client/common/process/decoder.ts @@ -3,7 +3,6 @@ import * as iconv from 'iconv-lite'; import { injectable } from 'inversify'; -import 'reflect-metadata'; import { DEFAULT_ENCODING } from './constants'; import { IBufferDecoder } from './types'; diff --git a/src/client/common/process/proc.ts b/src/client/common/process/proc.ts index 059302c9d349..46118a4c3c10 100644 --- a/src/client/common/process/proc.ts +++ b/src/client/common/process/proc.ts @@ -3,7 +3,6 @@ import { spawn } from 'child_process'; import { inject, injectable } from 'inversify'; -import 'reflect-metadata'; import * as Rx from 'rxjs'; import { Disposable } from 'vscode'; import { createDeferred } from '../helpers'; diff --git a/src/client/common/process/pythonExecutionFactory.ts b/src/client/common/process/pythonExecutionFactory.ts index 4465f63c924d..45ed4bf55bcf 100644 --- a/src/client/common/process/pythonExecutionFactory.ts +++ b/src/client/common/process/pythonExecutionFactory.ts @@ -2,7 +2,6 @@ // Licensed under the MIT License. import { inject, injectable } from 'inversify'; -import 'reflect-metadata'; import { Uri } from 'vscode'; import { PythonSettings } from '../configSettings'; import { IEnvironmentVariablesProvider } from '../variables/types'; diff --git a/src/client/common/process/pythonProcess.ts b/src/client/common/process/pythonProcess.ts index 6221597ab61a..ed8b68c2765f 100644 --- a/src/client/common/process/pythonProcess.ts +++ b/src/client/common/process/pythonProcess.ts @@ -2,7 +2,6 @@ // Licensed under the MIT License. import { injectable } from 'inversify'; -import 'reflect-metadata'; import { ErrorUtils } from '../errors/errorUtils'; import { ModuleNotInstalledError } from '../errors/moduleNotInstalledError'; import { EnvironmentVariables } from '../variables/types'; diff --git a/src/client/common/process/serviceRegistry.ts b/src/client/common/process/serviceRegistry.ts index 1e9e6191322f..8aa96e56a911 100644 --- a/src/client/common/process/serviceRegistry.ts +++ b/src/client/common/process/serviceRegistry.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -// tslint:disable-next-line:no-import-side-effect -import 'reflect-metadata'; import { IServiceManager } from '../../ioc/types'; import { BufferDecoder } from './decoder'; import { ProcessService } from './proc'; diff --git a/src/client/common/serviceRegistry.ts b/src/client/common/serviceRegistry.ts index 3368f4df0ff7..2121e58d95a7 100644 --- a/src/client/common/serviceRegistry.ts +++ b/src/client/common/serviceRegistry.ts @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -import 'reflect-metadata'; import { IServiceManager } from '../ioc/types'; import { CondaInstaller } from './installer/condaInstaller'; import { Installer } from './installer/installer'; diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index 116632d6b8ec..62f541169255 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -2,7 +2,6 @@ // Licensed under the MIT License. import { inject, injectable } from 'inversify'; -import 'reflect-metadata'; import { Disposable, Terminal, Uri, window, workspace } from 'vscode'; import { IServiceContainer } from '../../ioc/types'; import { IDisposableRegistry, IsWindows } from '../types'; diff --git a/src/client/common/variables/environment.ts b/src/client/common/variables/environment.ts index 26c00ecbe241..5abcda7f9482 100644 --- a/src/client/common/variables/environment.ts +++ b/src/client/common/variables/environment.ts @@ -4,7 +4,6 @@ import * as fs from 'fs-extra'; import { inject, injectable } from 'inversify'; import * as path from 'path'; -import 'reflect-metadata'; import { IPathUtils } from '../types'; import { EnvironmentVariables, IEnvironmentVariablesService } from './types'; diff --git a/src/client/common/variables/environmentVariablesProvider.ts b/src/client/common/variables/environmentVariablesProvider.ts index 0648ca5b9f60..049aa5515e18 100644 --- a/src/client/common/variables/environmentVariablesProvider.ts +++ b/src/client/common/variables/environmentVariablesProvider.ts @@ -2,7 +2,6 @@ // Licensed under the MIT License. import { inject, injectable } from 'inversify'; -import 'reflect-metadata'; import { Disposable, FileSystemWatcher, Uri, workspace } from 'vscode'; import { PythonSettings } from '../configSettings'; import { NON_WINDOWS_PATH_VARIABLE_NAME, WINDOWS_PATH_VARIABLE_NAME } from '../platform/constants'; diff --git a/src/client/common/variables/serviceRegistry.ts b/src/client/common/variables/serviceRegistry.ts index eb2d368edce8..957f462e52eb 100644 --- a/src/client/common/variables/serviceRegistry.ts +++ b/src/client/common/variables/serviceRegistry.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -// tslint:disable-next-line:no-import-side-effect -import 'reflect-metadata'; import { IServiceManager } from '../../ioc/types'; import { EnvironmentVariablesService } from './environment'; import { EnvironmentVariablesProvider } from './environmentVariablesProvider'; diff --git a/src/client/debugger/Main.ts b/src/client/debugger/Main.ts index adc8b7b587d1..9ff88164fab0 100644 --- a/src/client/debugger/Main.ts +++ b/src/client/debugger/Main.ts @@ -2,7 +2,6 @@ import * as fs from "fs"; import * as path from "path"; -import 'reflect-metadata'; import { DebugSession, Handles, InitializedEvent, OutputEvent, Scope, Source, StackFrame, StoppedEvent, TerminatedEvent, Thread } from "vscode-debugadapter"; import { ThreadEvent } from "vscode-debugadapter"; import { DebugProtocol } from "vscode-debugprotocol"; diff --git a/src/client/extension.ts b/src/client/extension.ts index 80714ecf4713..d2f753dbef60 100644 --- a/src/client/extension.ts +++ b/src/client/extension.ts @@ -1,4 +1,9 @@ 'use strict'; +// This line should always be right on top. +if (Reflect.metadata === undefined) { + // tslint:disable-next-line:no-require-imports no-var-requires + require('reflect-metadata'); +} import { Container } from 'inversify'; import * as os from 'os'; import * as vscode from 'vscode'; diff --git a/src/client/formatters/helper.ts b/src/client/formatters/helper.ts index 180ed3433932..31de83ebe505 100644 --- a/src/client/formatters/helper.ts +++ b/src/client/formatters/helper.ts @@ -2,7 +2,6 @@ // Licensed under the MIT License. import { injectable } from 'inversify'; -import 'reflect-metadata'; import { IFormattingSettings } from '../common/configSettings'; import { Product } from '../common/types'; import { FormatterId, FormatterSettingsPropertyNames, IFormatterHelper } from './types'; diff --git a/src/client/formatters/serviceRegistry.ts b/src/client/formatters/serviceRegistry.ts index a4d12e313582..196e6c806b5f 100644 --- a/src/client/formatters/serviceRegistry.ts +++ b/src/client/formatters/serviceRegistry.ts @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -import 'reflect-metadata'; import { IServiceManager } from '../ioc/types'; import { FormatterHelper } from './helper'; import { IFormatterHelper } from './types'; diff --git a/src/client/interpreter/interpreterVersion.ts b/src/client/interpreter/interpreterVersion.ts index 3d4c11ebc4d0..12a7aa60e139 100644 --- a/src/client/interpreter/interpreterVersion.ts +++ b/src/client/interpreter/interpreterVersion.ts @@ -1,6 +1,5 @@ import * as child_process from 'child_process'; import { injectable } from 'inversify'; -import 'reflect-metadata'; import { getInterpreterVersion } from '../common/utils'; import { IInterpreterVersionService } from './contracts'; diff --git a/src/client/interpreter/locators/services/KnownPathsService.ts b/src/client/interpreter/locators/services/KnownPathsService.ts index 6f767c5e847c..10b3d44f9679 100644 --- a/src/client/interpreter/locators/services/KnownPathsService.ts +++ b/src/client/interpreter/locators/services/KnownPathsService.ts @@ -1,7 +1,6 @@ import { inject, injectable } from 'inversify'; import * as _ from 'lodash'; import * as path from 'path'; -import 'reflect-metadata'; import { Uri } from 'vscode'; import { fsExistsAsync, IS_WINDOWS } from '../../../common/utils'; import { IInterpreterLocatorService, IInterpreterVersionService, IKnownSearchPathsForInterpreters, InterpreterType } from '../../contracts'; diff --git a/src/client/interpreter/locators/services/condaEnvFileService.ts b/src/client/interpreter/locators/services/condaEnvFileService.ts index 23d7d87f1efc..5ca921911afa 100644 --- a/src/client/interpreter/locators/services/condaEnvFileService.ts +++ b/src/client/interpreter/locators/services/condaEnvFileService.ts @@ -1,7 +1,6 @@ import * as fs from 'fs-extra'; import { inject, injectable } from 'inversify'; import * as path from 'path'; -import 'reflect-metadata'; import { Uri } from 'vscode'; import { IS_WINDOWS } from '../../../common/configSettings'; import { diff --git a/src/client/interpreter/locators/services/condaEnvService.ts b/src/client/interpreter/locators/services/condaEnvService.ts index f02fd30c48c7..370ac3df7ccb 100644 --- a/src/client/interpreter/locators/services/condaEnvService.ts +++ b/src/client/interpreter/locators/services/condaEnvService.ts @@ -2,7 +2,6 @@ import * as child_process from 'child_process'; import * as fs from 'fs-extra'; import { inject, injectable } from 'inversify'; import * as path from 'path'; -import 'reflect-metadata'; import { Uri } from 'vscode'; import { VersionUtils } from '../../../common/versionUtils'; import { ICondaLocatorService, IInterpreterLocatorService, IInterpreterVersionService, InterpreterType, PythonInterpreter } from '../../contracts'; diff --git a/src/client/interpreter/locators/services/condaLocator.ts b/src/client/interpreter/locators/services/condaLocator.ts index 759283d4909e..b866cf3727e3 100644 --- a/src/client/interpreter/locators/services/condaLocator.ts +++ b/src/client/interpreter/locators/services/condaLocator.ts @@ -2,7 +2,6 @@ import * as child_process from 'child_process'; import * as fs from 'fs-extra'; import { inject, injectable, named, optional } from 'inversify'; import * as path from 'path'; -import 'reflect-metadata'; import { IProcessService } from '../../../common/process/types'; import { IsWindows } from '../../../common/types'; import { VersionUtils } from '../../../common/versionUtils'; diff --git a/src/client/interpreter/locators/services/currentPathService.ts b/src/client/interpreter/locators/services/currentPathService.ts index 0f3ee31758c3..31f9dd070cbc 100644 --- a/src/client/interpreter/locators/services/currentPathService.ts +++ b/src/client/interpreter/locators/services/currentPathService.ts @@ -2,7 +2,6 @@ import * as child_process from 'child_process'; import { inject, injectable } from 'inversify'; import * as _ from 'lodash'; import * as path from 'path'; -import 'reflect-metadata'; import { Uri } from 'vscode'; import { PythonSettings } from '../../../common/configSettings'; import { IInterpreterLocatorService, IInterpreterVersionService, InterpreterType } from '../../contracts'; diff --git a/src/client/interpreter/locators/services/virtualEnvService.ts b/src/client/interpreter/locators/services/virtualEnvService.ts index 070bf673d6cd..8b859fb2facb 100644 --- a/src/client/interpreter/locators/services/virtualEnvService.ts +++ b/src/client/interpreter/locators/services/virtualEnvService.ts @@ -1,7 +1,6 @@ import { inject, injectable } from 'inversify'; import * as _ from 'lodash'; import * as path from 'path'; -import 'reflect-metadata'; import { Uri, workspace } from 'vscode'; import { fsReaddirAsync, IS_WINDOWS } from '../../../common/utils'; import { IInterpreterLocatorService, IInterpreterVersionService, IKnownSearchPathsForVirtualEnvironments, InterpreterType, PythonInterpreter } from '../../contracts'; diff --git a/src/client/interpreter/serviceRegistry.ts b/src/client/interpreter/serviceRegistry.ts index 56ade6625d40..699d36471153 100644 --- a/src/client/interpreter/serviceRegistry.ts +++ b/src/client/interpreter/serviceRegistry.ts @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -import 'reflect-metadata'; import { IsWindows } from '../common/types'; import { IServiceManager } from '../ioc/types'; import { diff --git a/src/client/interpreter/virtualEnvs/venv.ts b/src/client/interpreter/virtualEnvs/venv.ts index 3659abc3a9ee..934014c2d6c4 100644 --- a/src/client/interpreter/virtualEnvs/venv.ts +++ b/src/client/interpreter/virtualEnvs/venv.ts @@ -1,6 +1,5 @@ import { injectable } from 'inversify'; import * as path from 'path'; -import 'reflect-metadata'; import { fsExistsAsync } from '../../common/utils'; import { InterpreterType } from '../contracts'; import { IVirtualEnvironmentIdentifier } from './types'; diff --git a/src/client/interpreter/virtualEnvs/virtualEnv.ts b/src/client/interpreter/virtualEnvs/virtualEnv.ts index 193f6072a2dc..e2c78f9e2e6e 100644 --- a/src/client/interpreter/virtualEnvs/virtualEnv.ts +++ b/src/client/interpreter/virtualEnvs/virtualEnv.ts @@ -1,6 +1,5 @@ import { injectable } from 'inversify'; import * as path from 'path'; -import 'reflect-metadata'; import { fsExistsAsync } from '../../common/utils'; import { InterpreterType } from '../contracts'; import { IVirtualEnvironmentIdentifier } from './types'; diff --git a/src/client/linters/helper.ts b/src/client/linters/helper.ts index 0c94cba4787d..7a2f9bb96a92 100644 --- a/src/client/linters/helper.ts +++ b/src/client/linters/helper.ts @@ -1,6 +1,5 @@ import { injectable } from 'inversify'; import * as path from 'path'; -import 'reflect-metadata'; import { Uri } from 'vscode'; import { ILintingSettings, PythonSettings } from '../common/configSettings'; import { ExecutionInfo, Product } from '../common/types'; diff --git a/src/client/linters/serviceRegistry.ts b/src/client/linters/serviceRegistry.ts index 62c7ab349d28..8ca230d32e9b 100644 --- a/src/client/linters/serviceRegistry.ts +++ b/src/client/linters/serviceRegistry.ts @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -import 'reflect-metadata'; import { IServiceManager } from '../ioc/types'; import { LinterHelper } from './helper'; import { ILinterHelper } from './types'; diff --git a/src/client/unittests/common/debugLauncher.ts b/src/client/unittests/common/debugLauncher.ts index 4e408a51fa34..33877125a052 100644 --- a/src/client/unittests/common/debugLauncher.ts +++ b/src/client/unittests/common/debugLauncher.ts @@ -1,7 +1,6 @@ import * as getFreePort from 'get-port'; import { inject, injectable } from 'inversify'; import * as os from 'os'; -import 'reflect-metadata'; import { debug, Uri, workspace } from 'vscode'; import { PythonSettings } from '../../common/configSettings'; import { IPythonExecutionFactory } from '../../common/process/types'; diff --git a/src/client/unittests/common/services/storageService.ts b/src/client/unittests/common/services/storageService.ts index 399396a842db..14945216bf78 100644 --- a/src/client/unittests/common/services/storageService.ts +++ b/src/client/unittests/common/services/storageService.ts @@ -1,5 +1,4 @@ import { inject, injectable } from 'inversify'; -import 'reflect-metadata'; import { Disposable, Uri, workspace } from 'vscode'; import { IDisposableRegistry } from '../../../common/types'; import { ITestCollectionStorageService, Tests } from './../types'; diff --git a/src/client/unittests/common/services/testResultsService.ts b/src/client/unittests/common/services/testResultsService.ts index 02e5f048e52d..67e91826339d 100644 --- a/src/client/unittests/common/services/testResultsService.ts +++ b/src/client/unittests/common/services/testResultsService.ts @@ -1,5 +1,4 @@ import { inject, injectable, named } from 'inversify'; -import 'reflect-metadata'; import { TestResultResetVisitor } from './../testVisitors/resultResetVisitor'; import { ITestResultsService, ITestVisitor, TestFile, TestFolder, Tests, TestStatus, TestSuite } from './../types'; diff --git a/src/client/unittests/common/services/workspaceTestManagerService.ts b/src/client/unittests/common/services/workspaceTestManagerService.ts index e217410accc5..443c0614bf1f 100644 --- a/src/client/unittests/common/services/workspaceTestManagerService.ts +++ b/src/client/unittests/common/services/workspaceTestManagerService.ts @@ -1,5 +1,4 @@ import { inject, injectable, named } from 'inversify'; -import 'reflect-metadata'; import { Disposable, OutputChannel, Uri, workspace } from 'vscode'; import { IDisposableRegistry, IOutputChannel } from '../../../common/types'; import { TEST_OUTPUT_CHANNEL } from './../constants'; diff --git a/src/client/unittests/common/testUtils.ts b/src/client/unittests/common/testUtils.ts index 18c730283b52..463027fc3244 100644 --- a/src/client/unittests/common/testUtils.ts +++ b/src/client/unittests/common/testUtils.ts @@ -1,6 +1,5 @@ import { inject, injectable, named } from 'inversify'; import * as path from 'path'; -import 'reflect-metadata'; import * as vscode from 'vscode'; import { Uri, workspace } from 'vscode'; import { window } from 'vscode'; diff --git a/src/client/unittests/common/testVisitors/flatteningVisitor.ts b/src/client/unittests/common/testVisitors/flatteningVisitor.ts index 5a0178a2437f..c59d6f9d5cce 100644 --- a/src/client/unittests/common/testVisitors/flatteningVisitor.ts +++ b/src/client/unittests/common/testVisitors/flatteningVisitor.ts @@ -1,5 +1,4 @@ import { injectable } from 'inversify'; -import 'reflect-metadata'; import { convertFileToPackage } from '../testUtils'; import { FlattenedTestFunction, diff --git a/src/client/unittests/common/testVisitors/folderGenerationVisitor.ts b/src/client/unittests/common/testVisitors/folderGenerationVisitor.ts index 0f518c35b91f..df5a43e6adf3 100644 --- a/src/client/unittests/common/testVisitors/folderGenerationVisitor.ts +++ b/src/client/unittests/common/testVisitors/folderGenerationVisitor.ts @@ -1,6 +1,5 @@ import { injectable } from 'inversify'; import * as path from 'path'; -import 'reflect-metadata'; import { ITestVisitor, TestFile, TestFolder, TestFunction, TestSuite } from '../types'; @injectable() diff --git a/src/client/unittests/common/testVisitors/resultResetVisitor.ts b/src/client/unittests/common/testVisitors/resultResetVisitor.ts index 79fdffd7e961..6929d9386fa9 100644 --- a/src/client/unittests/common/testVisitors/resultResetVisitor.ts +++ b/src/client/unittests/common/testVisitors/resultResetVisitor.ts @@ -1,5 +1,4 @@ import { injectable } from 'inversify'; -import 'reflect-metadata'; import { ITestVisitor, TestFile, TestFolder, TestFunction, TestStatus, TestSuite } from '../types'; @injectable() diff --git a/src/client/unittests/nosetest/main.ts b/src/client/unittests/nosetest/main.ts index 228e68efae65..5ffae0b80cd3 100644 --- a/src/client/unittests/nosetest/main.ts +++ b/src/client/unittests/nosetest/main.ts @@ -1,5 +1,4 @@ import { inject, injectable } from 'inversify'; -import 'reflect-metadata'; import { Uri } from 'vscode'; import { PythonSettings } from '../../common/configSettings'; import { Product } from '../../common/types'; diff --git a/src/client/unittests/nosetest/services/discoveryService.ts b/src/client/unittests/nosetest/services/discoveryService.ts index ebbf09a5a131..acd651189b6d 100644 --- a/src/client/unittests/nosetest/services/discoveryService.ts +++ b/src/client/unittests/nosetest/services/discoveryService.ts @@ -2,7 +2,6 @@ // Licensed under the MIT License. import { inject, injectable, named } from 'inversify'; -import 'reflect-metadata'; import { CancellationTokenSource } from 'vscode'; import { IServiceContainer } from '../../../ioc/types'; import { NOSETEST_PROVIDER } from '../../common/constants'; diff --git a/src/client/unittests/nosetest/services/parserService.ts b/src/client/unittests/nosetest/services/parserService.ts index d9e824716813..fc706ec67606 100644 --- a/src/client/unittests/nosetest/services/parserService.ts +++ b/src/client/unittests/nosetest/services/parserService.ts @@ -4,7 +4,6 @@ import { inject, injectable } from 'inversify'; import * as os from 'os'; import * as path from 'path'; -import 'reflect-metadata'; import { convertFileToPackage, extractBetweenDelimiters } from '../../common/testUtils'; import { ITestsHelper, ITestsParser, ParserOptions, TestDiscoveryOptions, TestFile, TestFunction, Tests, TestStatus, TestSuite } from '../../common/types'; diff --git a/src/client/unittests/pytest/services/discoveryService.ts b/src/client/unittests/pytest/services/discoveryService.ts index 8160316bb5f3..c3fc02e131be 100644 --- a/src/client/unittests/pytest/services/discoveryService.ts +++ b/src/client/unittests/pytest/services/discoveryService.ts @@ -2,7 +2,6 @@ // Licensed under the MIT License. import { inject, injectable, named } from 'inversify'; -import 'reflect-metadata'; import { CancellationTokenSource } from 'vscode'; import { IServiceContainer } from '../../../ioc/types'; import { PYTEST_PROVIDER, UNITTEST_PROVIDER } from '../../common/constants'; diff --git a/src/client/unittests/pytest/services/parserService.ts b/src/client/unittests/pytest/services/parserService.ts index 3d5a97c36042..f0fad3b88b12 100644 --- a/src/client/unittests/pytest/services/parserService.ts +++ b/src/client/unittests/pytest/services/parserService.ts @@ -4,7 +4,6 @@ import { inject, injectable } from 'inversify'; import * as os from 'os'; import * as path from 'path'; -import 'reflect-metadata'; import { convertFileToPackage, extractBetweenDelimiters } from '../../common/testUtils'; import { ITestsHelper, ITestsParser, ParserOptions, TestDiscoveryOptions, TestFile, TestFunction, Tests, TestStatus, TestSuite } from '../../common/types'; diff --git a/src/client/unittests/serviceRegistry.ts b/src/client/unittests/serviceRegistry.ts index 82eae9be62d1..d500c67070dd 100644 --- a/src/client/unittests/serviceRegistry.ts +++ b/src/client/unittests/serviceRegistry.ts @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -import 'reflect-metadata'; import { Uri } from 'vscode'; import { IServiceContainer, IServiceManager } from '../ioc/types'; import { NOSETEST_PROVIDER, PYTEST_PROVIDER, UNITTEST_PROVIDER } from './common/constants'; diff --git a/src/client/unittests/unittest/services/discoveryService.ts b/src/client/unittests/unittest/services/discoveryService.ts index f323272cec04..cff7561c4420 100644 --- a/src/client/unittests/unittest/services/discoveryService.ts +++ b/src/client/unittests/unittest/services/discoveryService.ts @@ -2,7 +2,6 @@ // Licensed under the MIT License. import { inject, injectable, named } from 'inversify'; -import 'reflect-metadata'; import { IServiceContainer } from '../../../ioc/types'; import { UNITTEST_PROVIDER } from '../../common/constants'; import { Options, run } from '../../common/runner'; diff --git a/src/client/unittests/unittest/services/parserService.ts b/src/client/unittests/unittest/services/parserService.ts index c9270c43fbee..8c26d2ea05d0 100644 --- a/src/client/unittests/unittest/services/parserService.ts +++ b/src/client/unittests/unittest/services/parserService.ts @@ -3,7 +3,6 @@ import { inject, injectable } from 'inversify'; import * as path from 'path'; -import 'reflect-metadata'; import { ITestsHelper, ITestsParser, TestDiscoveryOptions, TestFile, TestFunction, Tests, TestStatus, TestSuite } from '../../common/types'; type UnitTestParserOptions = TestDiscoveryOptions & { startDirectory: string }; diff --git a/src/test/index.ts b/src/test/index.ts index 4d3b12a351ca..b4c43bfc6c0b 100644 --- a/src/test/index.ts +++ b/src/test/index.ts @@ -1,3 +1,4 @@ +import 'reflect-metadata'; import * as testRunner from 'vscode/lib/testrunner'; import { MochaSetupOptions } from 'vscode/lib/testrunner'; import { IS_MULTI_ROOT_TEST } from './initialize'; diff --git a/src/test/mocks/proc.ts b/src/test/mocks/proc.ts index ce6489556151..90a8fab492c0 100644 --- a/src/test/mocks/proc.ts +++ b/src/test/mocks/proc.ts @@ -1,7 +1,6 @@ import { spawn } from 'child_process'; import { EventEmitter } from 'events'; import { decorate, inject, injectable } from 'inversify'; -import 'reflect-metadata'; import * as Rx from 'rxjs'; import { Disposable } from 'vscode'; import { ExecutionResult, IBufferDecoder, IProcessService, ObservableExecutionResult, Output, SpawnOptions } from '../../client/common/process/types'; diff --git a/src/test/mocks/terminalService.ts b/src/test/mocks/terminalService.ts index 07e5d3e766a9..5935c40a6297 100644 --- a/src/test/mocks/terminalService.ts +++ b/src/test/mocks/terminalService.ts @@ -1,5 +1,4 @@ import { injectable } from 'inversify'; -import 'reflect-metadata'; import { createDeferred, Deferred } from '../../client/common/helpers'; import { ITerminalService } from '../../client/common/terminal/types'; diff --git a/src/test/serviceRegistry.ts b/src/test/serviceRegistry.ts index 159a26b579e1..ab787ff35eb9 100644 --- a/src/test/serviceRegistry.ts +++ b/src/test/serviceRegistry.ts @@ -2,7 +2,6 @@ // Licensed under the MIT License. import { Container } from 'inversify'; -import 'reflect-metadata'; import { Disposable, Memento, OutputChannel } from 'vscode'; import { STANDARD_OUTPUT_CHANNEL } from '../client/common/constants'; import { BufferDecoder } from '../client/common/process/decoder'; diff --git a/src/test/unittests/mocks.ts b/src/test/unittests/mocks.ts index 53bd496f471e..80efacd0f282 100644 --- a/src/test/unittests/mocks.ts +++ b/src/test/unittests/mocks.ts @@ -1,6 +1,5 @@ import { EventEmitter } from 'events'; import { injectable } from 'inversify'; -import 'reflect-metadata'; import { CancellationToken, Disposable, Uri } from 'vscode'; import { createDeferred, Deferred } from '../../client/common/helpers'; import { Product } from '../../client/common/types'; diff --git a/src/test/unittests/serviceRegistry.ts b/src/test/unittests/serviceRegistry.ts index b9fc642c6b62..5243d6b77936 100644 --- a/src/test/unittests/serviceRegistry.ts +++ b/src/test/unittests/serviceRegistry.ts @@ -1,11 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -import { MockUnitTestSocketServer } from './mocks'; - -import 'reflect-metadata'; import { Uri } from 'vscode'; import { IServiceContainer } from '../../client/ioc/types'; import { NOSETEST_PROVIDER, PYTEST_PROVIDER, UNITTEST_PROVIDER } from '../../client/unittests/common/constants'; @@ -28,6 +23,7 @@ import { TestManager as UnitTestTestManager } from '../../client/unittests/unitt import { TestDiscoveryService as UnitTestTestDiscoveryService } from '../../client/unittests/unittest/services/discoveryService'; import { TestsParser as UnitTestTestsParser } from '../../client/unittests/unittest/services/parserService'; import { IocContainer } from '../serviceRegistry'; +import { MockUnitTestSocketServer } from './mocks'; export class UnitTestIocContainer extends IocContainer { constructor() { From 9802c4b80ab8f7fba4520392b05f156b95ad6a2c Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Mon, 18 Dec 2017 11:53:34 -0800 Subject: [PATCH 2/4] import reflect-metadata once per extension --- src/client/debugger/Main.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/client/debugger/Main.ts b/src/client/debugger/Main.ts index 9ff88164fab0..293caf985d54 100644 --- a/src/client/debugger/Main.ts +++ b/src/client/debugger/Main.ts @@ -1,5 +1,10 @@ "use strict"; +// This line should always be right on top. +if (Reflect.metadata === undefined) { + // tslint:disable-next-line:no-require-imports no-var-requires + require('reflect-metadata'); +} import * as fs from "fs"; import * as path from "path"; import { DebugSession, Handles, InitializedEvent, OutputEvent, Scope, Source, StackFrame, StoppedEvent, TerminatedEvent, Thread } from "vscode-debugadapter"; From ed6f6d9c07a90bd13199a68e42a92d8f008b2180 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Mon, 18 Dec 2017 12:05:46 -0800 Subject: [PATCH 3/4] fully qualify path module --- pythonFiles/PythonTools/visualstudio_py_launcher_nodebug.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pythonFiles/PythonTools/visualstudio_py_launcher_nodebug.py b/pythonFiles/PythonTools/visualstudio_py_launcher_nodebug.py index 6a526aa04a52..7285d6d8558b 100644 --- a/pythonFiles/PythonTools/visualstudio_py_launcher_nodebug.py +++ b/pythonFiles/PythonTools/visualstudio_py_launcher_nodebug.py @@ -114,7 +114,7 @@ def handle_exception(exc_type, exc_value, exc_tb): tb = traceback.extract_tb(exc_tb) for i in [0, -1]: while tb: - frame_file = path.normcase(tb[i][0]) + frame_file = os.path.normcase(tb[i][0]) if not any(is_same_py_file(frame_file, f) for f in do_not_debug): break del tb[i] From 5001b938bc20e1be8cb8ec3dab5d5040e6bdcae8 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Mon, 18 Dec 2017 13:24:55 -0800 Subject: [PATCH 4/4] update changelog and version --- CHANGELOG.md | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eae077f695cb..4f5bb1c04206 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Version 0.9.1 (18 December 2017) + +* Fixes the compatibility issue with the [Visual Studio Code Tools for AI +](https://marketplace.visualstudio.com/items?itemName=ms-toolsai.vscode-ai) extension by conditionally importing `reflect-metadata` [#432](https://github.com/Microsoft/vscode-python/issues/432) +* Display runtime errors encountered when running a python program without debugging [#454](https://github.com/Microsoft/vscode-python/issues/454) + ## Version 0.9.0 (14 December 2017) * Translated the commands to simplified Chinese [#240](https://github.com/Microsoft/vscode-python/pull/240) (thanks [Wai Sui kei](https://github.com/WaiSiuKei)) diff --git a/package.json b/package.json index 32dd7cb95ae6..3de7f359d9ee 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "python", "displayName": "Python", "description": "Linting, Debugging (multi-threaded, remote), Intellisense, code formatting, refactoring, unit tests, snippets, and more.", - "version": "0.9.0", + "version": "0.9.1", "publisher": "ms-python", "author": { "name": "Microsoft Corporation"