Skip to content

Commit 35e85de

Browse files
committed
Remove IS_WINDOWS constant in favor of PlatformService
1 parent 7e72067 commit 35e85de

File tree

6 files changed

+12
-17
lines changed

6 files changed

+12
-17
lines changed

src/client/common/configSettings.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { ITestingSettings } from '../testing/configuration/types';
2323
import { IWorkspaceService } from './application/types';
2424
import { WorkspaceService } from './application/workspace';
2525
import { DEFAULT_INTERPRETER_SETTING, isTestExecution } from './constants';
26-
import { IS_WINDOWS } from './platform/constants';
2726
import {
2827
IAutoCompleteSettings,
2928
IDefaultLanguageServer,
@@ -41,6 +40,7 @@ import {
4140
import { debounceSync } from './utils/decorators';
4241
import { SystemVariables } from './variables/systemVariables';
4342
import { getOSType, OSType } from './utils/platform';
43+
import { PlatformService } from './platform/platformService';
4444

4545
const untildify = require('untildify');
4646

@@ -623,6 +623,7 @@ function getAbsolutePath(pathToCheck: string, rootDir: string | undefined): stri
623623
}
624624

625625
function getPythonExecutable(pythonPath: string): string {
626+
const plaform = new PlatformService();
626627
pythonPath = untildify(pythonPath) as string;
627628

628629
// If only 'python'.
@@ -654,7 +655,7 @@ function getPythonExecutable(pythonPath: string): string {
654655

655656
for (let executableName of KnownPythonExecutables) {
656657
// Suffix with 'python' for linux and 'osx', and 'python.exe' for 'windows'.
657-
if (IS_WINDOWS) {
658+
if (plaform.isWindows) {
658659
executableName = `${executableName}.exe`;
659660
if (isValidPythonPath(path.join(pythonPath, executableName))) {
660661
return path.join(pythonPath, executableName);

src/client/common/platform/constants.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/client/common/serviceRegistry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ import { ProductInstaller } from './installer/productInstaller';
5757
import { InterpreterPathService } from './interpreterPathService';
5858
import { BrowserService } from './net/browser';
5959
import { PersistentStateFactory } from './persistentState';
60-
import { IS_WINDOWS } from './platform/constants';
6160
import { PathUtils } from './platform/pathUtils';
6261
import { CurrentProcess } from './process/currentProcess';
6362
import { ProcessLogger } from './process/logger';
@@ -91,9 +90,10 @@ import { Random } from './utils/random';
9190
import { ContextKeyManager } from './application/contextKeyManager';
9291
import { CreatePythonFileCommandHandler } from './application/commands/createPythonFile';
9392
import { RequireJupyterPrompt } from '../jupyter/requireJupyterPrompt';
93+
import { PlatformService } from './platform/platformService';
9494

9595
export function registerTypes(serviceManager: IServiceManager): void {
96-
serviceManager.addSingletonInstance<boolean>(IsWindows, IS_WINDOWS);
96+
serviceManager.addSingletonInstance<boolean>(IsWindows, new PlatformService().isWindows);
9797

9898
serviceManager.addSingleton<IActiveResourceService>(IActiveResourceService, ActiveResourceService);
9999
serviceManager.addSingleton<IInterpreterPathService>(IInterpreterPathService, InterpreterPathService);

src/client/linters/pydocstyle.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import '../common/extensions';
44
import { Product } from '../common/types';
55
import { IServiceContainer } from '../ioc/types';
66
import { traceError } from '../logging';
7-
import { IS_WINDOWS } from '../common/platform/constants';
87
import { BaseLinter } from './baseLinter';
98
import { ILintMessage, LintMessageSeverity } from './types';
9+
import { PlatformService } from '../common/platform/platformService';
1010

1111
export class PyDocStyle extends BaseLinter {
1212
constructor(serviceContainer: IServiceContainer) {
@@ -30,6 +30,7 @@ export class PyDocStyle extends BaseLinter {
3030
_regEx: string,
3131
): Promise<ILintMessage[]> {
3232
let outputLines = output.split(/\r?\n/g);
33+
const platform = new PlatformService();
3334
const baseFileName = path.basename(document.uri.fsPath);
3435

3536
// Remember, the first line of the response contains the file name and line number, the next line contains the error message.
@@ -47,7 +48,7 @@ export class PyDocStyle extends BaseLinter {
4748
.filter((value, index) => index < maxLines && value.indexOf(':') >= 0)
4849
.map((line) => {
4950
// Windows will have a : after the drive letter (e.g. c:\).
50-
if (IS_WINDOWS) {
51+
if (platform.isWindows) {
5152
return line.substring(line.indexOf(`${baseFileName}:`) + baseFileName.length + 1).trim();
5253
}
5354
return line.substring(line.indexOf(':') + 1).trim();

src/test/common/configSettings.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as assert from 'assert';
22
import * as path from 'path';
33
import * as vscode from 'vscode';
4-
import { IS_WINDOWS } from '../../client/common/platform/constants';
54
import { SystemVariables } from '../../client/common/variables/systemVariables';
65
import { getExtensionSettings } from '../extensionSettings';
76
import { initialize } from './../initialize';
7+
import { PlatformService } from '../../client/common/platform/platformService';
88

99
const workspaceRoot = path.join(__dirname, '..', '..', '..', 'src', 'test');
1010

@@ -15,6 +15,7 @@ suite('Configuration Settings', () => {
1515
test('Check Values', (done) => {
1616
const systemVariables: SystemVariables = new SystemVariables(undefined, workspaceRoot);
1717

18+
const platform = new PlatformService();
1819
const pythonConfig = vscode.workspace.getConfiguration('python', (null as any) as vscode.Uri);
1920
const pythonSettings = getExtensionSettings(vscode.Uri.file(workspaceRoot));
2021
Object.keys(pythonSettings).forEach((key) => {
@@ -27,7 +28,7 @@ suite('Configuration Settings', () => {
2728
}
2829

2930
const pythonSettingValue = (pythonSettings as any)[key] as string;
30-
if (key.endsWith('Path') && IS_WINDOWS) {
31+
if (key.endsWith('Path') && platform.isWindows) {
3132
assert.strictEqual(
3233
settingValue.toUpperCase(),
3334
pythonSettingValue.toUpperCase(),

src/test/serviceRegistry.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { Container } from 'inversify';
55
import { anything, instance, mock, when } from 'ts-mockito';
66
import * as TypeMoq from 'typemoq';
77
import { Disposable, Memento } from 'vscode';
8-
import { IS_WINDOWS } from '../client/common/platform/constants';
98
import { FileSystem } from '../client/common/platform/fileSystem';
109
import { PathUtils } from '../client/common/platform/pathUtils';
1110
import { PlatformService } from '../client/common/platform/platformService';
@@ -195,7 +194,7 @@ export class IocContainer {
195194
}
196195

197196
public registerMockProcess(): void {
198-
this.serviceManager.addSingletonInstance<boolean>(IsWindows, IS_WINDOWS);
197+
this.serviceManager.addSingletonInstance<boolean>(IsWindows, new PlatformService().isWindows);
199198

200199
this.serviceManager.addSingleton<IPathUtils>(IPathUtils, PathUtils);
201200
this.serviceManager.addSingleton<ICurrentProcess>(ICurrentProcess, MockProcess);

0 commit comments

Comments
 (0)