Skip to content

Commit

Permalink
Remove IS_WINDOWS constant in favor of PlatformService
Browse files Browse the repository at this point in the history
  • Loading branch information
cpinamtz committed Apr 30, 2023
1 parent 7e72067 commit 35e85de
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 17 deletions.
5 changes: 3 additions & 2 deletions src/client/common/configSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { ITestingSettings } from '../testing/configuration/types';
import { IWorkspaceService } from './application/types';
import { WorkspaceService } from './application/workspace';
import { DEFAULT_INTERPRETER_SETTING, isTestExecution } from './constants';
import { IS_WINDOWS } from './platform/constants';
import {
IAutoCompleteSettings,
IDefaultLanguageServer,
Expand All @@ -41,6 +40,7 @@ import {
import { debounceSync } from './utils/decorators';
import { SystemVariables } from './variables/systemVariables';
import { getOSType, OSType } from './utils/platform';
import { PlatformService } from './platform/platformService';

const untildify = require('untildify');

Expand Down Expand Up @@ -623,6 +623,7 @@ function getAbsolutePath(pathToCheck: string, rootDir: string | undefined): stri
}

function getPythonExecutable(pythonPath: string): string {
const plaform = new PlatformService();
pythonPath = untildify(pythonPath) as string;

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

for (let executableName of KnownPythonExecutables) {
// Suffix with 'python' for linux and 'osx', and 'python.exe' for 'windows'.
if (IS_WINDOWS) {
if (plaform.isWindows) {
executableName = `${executableName}.exe`;
if (isValidPythonPath(path.join(pythonPath, executableName))) {
return path.join(pythonPath, executableName);
Expand Down
7 changes: 0 additions & 7 deletions src/client/common/platform/constants.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/client/common/serviceRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ import { ProductInstaller } from './installer/productInstaller';
import { InterpreterPathService } from './interpreterPathService';
import { BrowserService } from './net/browser';
import { PersistentStateFactory } from './persistentState';
import { IS_WINDOWS } from './platform/constants';
import { PathUtils } from './platform/pathUtils';
import { CurrentProcess } from './process/currentProcess';
import { ProcessLogger } from './process/logger';
Expand Down Expand Up @@ -91,9 +90,10 @@ import { Random } from './utils/random';
import { ContextKeyManager } from './application/contextKeyManager';
import { CreatePythonFileCommandHandler } from './application/commands/createPythonFile';
import { RequireJupyterPrompt } from '../jupyter/requireJupyterPrompt';
import { PlatformService } from './platform/platformService';

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

serviceManager.addSingleton<IActiveResourceService>(IActiveResourceService, ActiveResourceService);
serviceManager.addSingleton<IInterpreterPathService>(IInterpreterPathService, InterpreterPathService);
Expand Down
5 changes: 3 additions & 2 deletions src/client/linters/pydocstyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import '../common/extensions';
import { Product } from '../common/types';
import { IServiceContainer } from '../ioc/types';
import { traceError } from '../logging';
import { IS_WINDOWS } from '../common/platform/constants';
import { BaseLinter } from './baseLinter';
import { ILintMessage, LintMessageSeverity } from './types';
import { PlatformService } from '../common/platform/platformService';

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

// Remember, the first line of the response contains the file name and line number, the next line contains the error message.
Expand All @@ -47,7 +48,7 @@ export class PyDocStyle extends BaseLinter {
.filter((value, index) => index < maxLines && value.indexOf(':') >= 0)
.map((line) => {
// Windows will have a : after the drive letter (e.g. c:\).
if (IS_WINDOWS) {
if (platform.isWindows) {
return line.substring(line.indexOf(`${baseFileName}:`) + baseFileName.length + 1).trim();
}
return line.substring(line.indexOf(':') + 1).trim();
Expand Down
5 changes: 3 additions & 2 deletions src/test/common/configSettings.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as assert from 'assert';
import * as path from 'path';
import * as vscode from 'vscode';
import { IS_WINDOWS } from '../../client/common/platform/constants';
import { SystemVariables } from '../../client/common/variables/systemVariables';
import { getExtensionSettings } from '../extensionSettings';
import { initialize } from './../initialize';
import { PlatformService } from '../../client/common/platform/platformService';

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

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

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

const pythonSettingValue = (pythonSettings as any)[key] as string;
if (key.endsWith('Path') && IS_WINDOWS) {
if (key.endsWith('Path') && platform.isWindows) {
assert.strictEqual(
settingValue.toUpperCase(),
pythonSettingValue.toUpperCase(),
Expand Down
3 changes: 1 addition & 2 deletions src/test/serviceRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Container } from 'inversify';
import { anything, instance, mock, when } from 'ts-mockito';
import * as TypeMoq from 'typemoq';
import { Disposable, Memento } from 'vscode';
import { IS_WINDOWS } from '../client/common/platform/constants';
import { FileSystem } from '../client/common/platform/fileSystem';
import { PathUtils } from '../client/common/platform/pathUtils';
import { PlatformService } from '../client/common/platform/platformService';
Expand Down Expand Up @@ -195,7 +194,7 @@ export class IocContainer {
}

public registerMockProcess(): void {
this.serviceManager.addSingletonInstance<boolean>(IsWindows, IS_WINDOWS);
this.serviceManager.addSingletonInstance<boolean>(IsWindows, new PlatformService().isWindows);

this.serviceManager.addSingleton<IPathUtils>(IPathUtils, PathUtils);
this.serviceManager.addSingleton<ICurrentProcess>(ICurrentProcess, MockProcess);
Expand Down

0 comments on commit 35e85de

Please sign in to comment.