-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Log commands run by the discovery component in the output channel #17670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Log commands run by the discovery component in the output channel. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,6 +58,7 @@ export class ProcessService extends EventEmitter implements IProcessService { | |
| } | ||
|
|
||
| public shellExec(command: string, options: ShellOptions = {}): Promise<ExecutionResult<string>> { | ||
| this.emit('exec', command, undefined, options); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Emitting here logs the command. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there going to be commands logged more than once? #7160
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not for the discovery component as it doesn't use Python execution factory.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created a separate PR to fix the other issue #17697 |
||
| return shellExec(command, options, this.env, this.processesToKill); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| 'use strict'; | ||
|
|
||
| import { WorkspaceService } from '../common/application/workspace'; | ||
| import { LogLevel } from './levels'; | ||
|
|
||
| type LoggingLevelSettingType = 'off' | 'error' | 'warn' | 'info' | 'debug'; | ||
|
|
||
| /** | ||
| * Uses Workspace service to query for `python.logging.level` setting and returns it. | ||
| */ | ||
| export function getLoggingLevel(): LogLevel | 'off' { | ||
| const workspace = new WorkspaceService(); | ||
| const value = workspace.getConfiguration('python').get<LoggingLevelSettingType>('logging.level'); | ||
| return convertSettingTypeToLogLevel(value); | ||
| } | ||
|
|
||
| function convertSettingTypeToLogLevel(setting: LoggingLevelSettingType | undefined): LogLevel | 'off' { | ||
| switch (setting) { | ||
| case 'info': { | ||
| return LogLevel.Info; | ||
| } | ||
| case 'warn': { | ||
| return LogLevel.Warn; | ||
| } | ||
| case 'off': { | ||
| return 'off'; | ||
| } | ||
| case 'debug': { | ||
| return LogLevel.Debug; | ||
| } | ||
| default: { | ||
| return LogLevel.Error; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,14 +4,12 @@ | |
| import * as fsapi from 'fs-extra'; | ||
| import * as path from 'path'; | ||
| import * as vscode from 'vscode'; | ||
| import { ExecutionResult, ShellOptions, SpawnOptions } from '../../common/process/types'; | ||
| import { ExecutionResult, IProcessServiceFactory, ShellOptions, SpawnOptions } from '../../common/process/types'; | ||
| import { IExperimentService, IDisposable, IConfigurationService } from '../../common/types'; | ||
| import { chain, iterable } from '../../common/utils/async'; | ||
| import { normalizeFilename } from '../../common/utils/filesystem'; | ||
| import { getOSType, OSType } from '../../common/utils/platform'; | ||
| import { IServiceContainer } from '../../ioc/types'; | ||
| import { plainExec, shellExec } from '../../common/process/rawProcessApis'; | ||
| import { BufferDecoder } from '../../common/process/decoder'; | ||
|
|
||
| let internalServiceContainer: IServiceContainer; | ||
| export function initializeExternalDependencies(serviceContainer: IServiceContainer): void { | ||
|
|
@@ -20,39 +18,14 @@ export function initializeExternalDependencies(serviceContainer: IServiceContain | |
|
|
||
| // processes | ||
|
|
||
| /** | ||
| * Specialized version of the more generic shellExecute function to use only in | ||
| * cases where we don't need to pass custom environment variables read from env | ||
| * files or execution options. | ||
| * | ||
| * Also ensures to kill the processes created after execution. | ||
| */ | ||
| export async function shellExecute(command: string, options: ShellOptions = {}): Promise<ExecutionResult<string>> { | ||
| const disposables = new Set<IDisposable>(); | ||
| return shellExec(command, options, undefined, disposables).finally(() => { | ||
| // Ensure the process we started is cleaned up. | ||
| disposables.forEach((p) => { | ||
| try { | ||
| p.dispose(); | ||
| } catch { | ||
| // ignore. | ||
| } | ||
| }); | ||
| }); | ||
| const service = await internalServiceContainer.get<IProcessServiceFactory>(IProcessServiceFactory).create(); | ||
| return service.shellExec(command, options); | ||
| } | ||
|
|
||
| /** | ||
| * Specialized version of the more generic exec function to use only in | ||
| * cases where we don't need to pass custom environment variables read from | ||
| * env files. | ||
| */ | ||
| export async function exec( | ||
| file: string, | ||
| args: string[], | ||
| options: SpawnOptions = {}, | ||
| disposables?: Set<IDisposable>, | ||
| ): Promise<ExecutionResult<string>> { | ||
| return plainExec(file, args, options, new BufferDecoder(), undefined, disposables); | ||
| export async function exec(file: string, args: string[], options: SpawnOptions = {}): Promise<ExecutionResult<string>> { | ||
| const service = await internalServiceContainer.get<IProcessServiceFactory>(IProcessServiceFactory).create(); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return service.exec(file, args, options); | ||
| } | ||
|
|
||
| // filesystem | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c:/is the same asC:/on windows, this was not being respected when comparing.