Skip to content

Commit d3a29e0

Browse files
Remove process and factory
1 parent c2b1fa8 commit d3a29e0

File tree

9 files changed

+38
-331
lines changed

9 files changed

+38
-331
lines changed

package-lock.json

Lines changed: 1 addition & 32 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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
"category": "Debugpy",
5050
"command": "debugpy.viewOutput",
5151
"icon": {
52-
"dark": "resources/dark/repl.svg",
53-
"light": "resources/light/repl.svg"
52+
"dark": "resources/dark/repl.svg",
53+
"light": "resources/light/repl.svg"
5454
},
5555
"title": "%debugpy.command.viewOutput.title%"
5656
}
@@ -474,8 +474,6 @@
474474
"jsonc-parser": "^3.2.0",
475475
"lodash": "^4.17.21",
476476
"reflect-metadata": "^0.1.13",
477-
"rxjs": "^6.5.4",
478-
"rxjs-compat": "^6.5.4",
479477
"vscode-debugadapter": "^1.51.0",
480478
"vscode-debugprotocol": "^1.51.0",
481479
"vscode-languageclient": "^8.0.2"

src/extension/common/process/logger.ts

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,37 @@
44
'use strict';
55

66
import { Logging } from '../utils/localize';
7-
import { IProcessLogger, SpawnOptions } from './types';
7+
import { SpawnOptions } from './types';
88
import { escapeRegExp } from 'lodash';
99
import { traceLog } from '../log/logging';
1010
import { getWorkspaceFolders } from '../vscodeapi';
1111
import { getOSType, getUserHomeDir, OSType } from '../platform';
1212
import { replaceAll, toCommandArgumentForPythonExt, trimQuotes } from '../stringUtils';
1313

14-
export class ProcessLogger implements IProcessLogger {
15-
constructor() {}
14+
export function logProcess(fileOrCommand: string, args?: string[], options?: SpawnOptions) {
15+
let command = args
16+
? [fileOrCommand, ...args].map((e) => toCommandArgumentForPythonExt(trimQuotes(e))).join(' ')
17+
: fileOrCommand;
18+
const info = [`> ${getDisplayCommands(command)}`];
19+
if (options && options.cwd) {
20+
info.push(`${Logging.currentWorkingDirectory} ${getDisplayCommands(options.cwd as string)}`);
21+
}
1622

17-
public logProcess(fileOrCommand: string, args?: string[], options?: SpawnOptions) {
18-
let command = args
19-
? [fileOrCommand, ...args].map((e) => toCommandArgumentForPythonExt(trimQuotes(e))).join(' ')
20-
: fileOrCommand;
21-
const info = [`> ${this.getDisplayCommands(command)}`];
22-
if (options && options.cwd) {
23-
info.push(`${Logging.currentWorkingDirectory} ${this.getDisplayCommands(options.cwd as string)}`);
24-
}
23+
info.forEach((line) => {
24+
traceLog(line);
25+
});
26+
}
2527

26-
info.forEach((line) => {
27-
traceLog(line);
28-
});
28+
function getDisplayCommands(command: string): string {
29+
const workspaceFolders = getWorkspaceFolders();
30+
if (workspaceFolders && workspaceFolders.length === 1) {
31+
command = replaceMatchesWithCharacter(command, workspaceFolders[0].uri.fsPath, '.');
2932
}
30-
31-
private getDisplayCommands(command: string): string {
32-
const workspaceFolders = getWorkspaceFolders();
33-
if (workspaceFolders && workspaceFolders.length === 1) {
34-
command = replaceMatchesWithCharacter(command, workspaceFolders[0].uri.fsPath, '.');
35-
}
36-
const home = getUserHomeDir();
37-
if (home) {
38-
command = replaceMatchesWithCharacter(command, home, '~');
39-
}
40-
return command;
33+
const home = getUserHomeDir();
34+
if (home) {
35+
command = replaceMatchesWithCharacter(command, home, '~');
4136
}
37+
return command;
4238
}
4339

4440
/**

src/extension/common/process/proc.ts

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

src/extension/common/process/processFactory.ts

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

src/extension/common/process/rawProcessApis.ts

Lines changed: 2 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
import { exec, execSync, spawn } from 'child_process';
4+
import { execSync, spawn } from 'child_process';
55
import { Readable } from 'stream';
6-
import { Observable } from 'rxjs/Observable';
76
import { IDisposable } from '../types';
87
import { createDeferred } from '../utils/async';
98
import { EnvironmentVariables } from '../variables/types';
109
import { DEFAULT_ENCODING } from './constants';
11-
import { ExecutionResult, ObservableExecutionResult, Output, ShellOptions, SpawnOptions, StdErrError } from './types';
10+
import { ExecutionResult, ShellOptions, SpawnOptions, StdErrError } from './types';
1211
import { noop } from '../utils/misc';
1312
import { decodeBuffer } from './decoder';
14-
import { traceVerbose } from '../log/logging';
1513

1614
function getDefaultOptions<T extends ShellOptions | SpawnOptions>(options: T, defaultEnv?: EnvironmentVariables): T {
1715
const defaultOptions = { ...options };
@@ -45,42 +43,6 @@ function getDefaultOptions<T extends ShellOptions | SpawnOptions>(options: T, de
4543
return defaultOptions;
4644
}
4745

48-
export function shellExec(
49-
command: string,
50-
options: ShellOptions = {},
51-
defaultEnv?: EnvironmentVariables,
52-
disposables?: Set<IDisposable>,
53-
): Promise<ExecutionResult<string>> {
54-
const shellOptions = getDefaultOptions(options, defaultEnv);
55-
traceVerbose(`Shell Exec: ${command} with options: ${JSON.stringify(shellOptions, null, 4)}`);
56-
return new Promise((resolve, reject) => {
57-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
58-
const callback = (e: any, stdout: any, stderr: any) => {
59-
if (e && e !== null) {
60-
reject(e);
61-
} else if (shellOptions.throwOnStdErr && stderr && stderr.length) {
62-
reject(new Error(stderr));
63-
} else {
64-
stdout = filterOutputUsingCondaRunMarkers(stdout);
65-
// Make sure stderr is undefined if we actually had none. This is checked
66-
// elsewhere because that's how exec behaves.
67-
resolve({ stderr: stderr && stderr.length > 0 ? stderr : undefined, stdout });
68-
}
69-
};
70-
const proc = exec(command, shellOptions, callback); // NOSONAR
71-
const disposable: IDisposable = {
72-
dispose: () => {
73-
if (!proc.killed) {
74-
proc.kill();
75-
}
76-
},
77-
};
78-
if (disposables) {
79-
disposables.add(disposable);
80-
}
81-
});
82-
}
83-
8446
export function plainExec(
8547
file: string,
8648
args: string[],
@@ -162,96 +124,6 @@ function filterOutputUsingCondaRunMarkers(stdout: string) {
162124
return filteredOut !== undefined ? filteredOut : stdout;
163125
}
164126

165-
function removeCondaRunMarkers(out: string) {
166-
out = out.replace('>>>PYTHON-EXEC-OUTPUT\r\n', '').replace('>>>PYTHON-EXEC-OUTPUT\n', '');
167-
return out.replace('<<<PYTHON-EXEC-OUTPUT\r\n', '').replace('<<<PYTHON-EXEC-OUTPUT\n', '');
168-
}
169-
170-
export function execObservable(
171-
file: string,
172-
args: string[],
173-
options: SpawnOptions = {},
174-
defaultEnv?: EnvironmentVariables,
175-
disposables?: Set<IDisposable>,
176-
): ObservableExecutionResult<string> {
177-
const spawnOptions = getDefaultOptions(options, defaultEnv);
178-
const encoding = spawnOptions.encoding ? spawnOptions.encoding : 'utf8';
179-
const proc = spawn(file, args, spawnOptions);
180-
let procExited = false;
181-
const disposable: IDisposable = {
182-
dispose() {
183-
if (proc && !proc.killed && !procExited) {
184-
killPid(proc.pid!);
185-
}
186-
if (proc) {
187-
proc.unref();
188-
}
189-
},
190-
};
191-
disposables?.add(disposable);
192-
193-
const output = new Observable<Output<string>>((subscriber) => {
194-
const internalDisposables: IDisposable[] = [];
195-
196-
// eslint-disable-next-line @typescript-eslint/ban-types
197-
const on = (ee: Readable | null, name: string, fn: Function) => {
198-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
199-
ee?.on(name, fn as any);
200-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
201-
internalDisposables.push({ dispose: () => ee?.removeListener(name, fn as any) as any });
202-
};
203-
204-
if (options.token) {
205-
internalDisposables.push(
206-
options.token.onCancellationRequested(() => {
207-
if (!procExited && !proc.killed) {
208-
proc.kill();
209-
procExited = true;
210-
}
211-
}),
212-
);
213-
}
214-
215-
const sendOutput = (source: 'stdout' | 'stderr', data: Buffer) => {
216-
let out = decodeBuffer([data], encoding);
217-
if (source === 'stderr' && options.throwOnStdErr) {
218-
subscriber.error(new StdErrError(out));
219-
} else {
220-
// Because all of output is not retrieved at once, filtering out the
221-
// actual output using markers is not possible. Hence simply remove
222-
// the markers and return original output.
223-
out = removeCondaRunMarkers(out);
224-
subscriber.next({ source, out });
225-
}
226-
};
227-
228-
on(proc.stdout, 'data', (data: Buffer) => sendOutput('stdout', data));
229-
on(proc.stderr, 'data', (data: Buffer) => sendOutput('stderr', data));
230-
231-
proc.once('close', () => {
232-
procExited = true;
233-
subscriber.complete();
234-
internalDisposables.forEach((d) => d.dispose());
235-
});
236-
proc.once('exit', () => {
237-
procExited = true;
238-
subscriber.complete();
239-
internalDisposables.forEach((d) => d.dispose());
240-
});
241-
proc.once('error', (ex) => {
242-
procExited = true;
243-
subscriber.error(ex);
244-
internalDisposables.forEach((d) => d.dispose());
245-
});
246-
});
247-
248-
return {
249-
proc,
250-
out: output,
251-
dispose: disposable.dispose,
252-
};
253-
}
254-
255127
export function killPid(pid: number): void {
256128
try {
257129
if (process.platform === 'win32') {

0 commit comments

Comments
 (0)