Skip to content

Commit f85d591

Browse files
authored
Start TensorBoard sessions with user-level python.tensorBoard.logDirectory (#15588)
1 parent 5d1a4ad commit f85d591

File tree

6 files changed

+53
-3
lines changed

6 files changed

+53
-3
lines changed

news/1 Enhancements/15476.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add optional user-level `python.tensorBoard.logDirectory` setting. When starting a TensorBoard session, use this setting if it is present instead of prompting the user to select a log directory.

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,11 @@
16501650
"default": "",
16511651
"scope": "resource"
16521652
},
1653+
"python.tensorBoard.logDirectory": {
1654+
"type": "string",
1655+
"description": "Set this setting to your preferred TensorBoard log directory to skip log directory prompt when starting TensorBoard.",
1656+
"scope": "application"
1657+
},
16531658
"python.terminal.activateEnvironment": {
16541659
"type": "boolean",
16551660
"default": true,

src/client/common/configSettings.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
ILoggingSettings,
4141
IPythonSettings,
4242
ISortImportSettings,
43+
ITensorBoardSettings,
4344
ITerminalSettings,
4445
IWorkspaceSymbolSettings,
4546
LoggingLevelSettingType,
@@ -119,6 +120,8 @@ export class PythonSettings implements IPythonSettings {
119120

120121
public autoComplete!: IAutoCompleteSettings;
121122

123+
public tensorBoard: ITensorBoardSettings | undefined;
124+
122125
public testing!: ITestingSettings;
123126

124127
public terminal!: ITerminalSettings;
@@ -582,6 +585,7 @@ export class PythonSettings implements IPythonSettings {
582585
}
583586

584587
this.insidersChannel = pythonSettings.get<ExtensionChannels>('insidersChannel')!;
588+
this.tensorBoard = pythonSettings.get<ITensorBoardSettings>('tensorBoard');
585589
}
586590

587591
// eslint-disable-next-line class-methods-use-this

src/client/common/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ export interface IPythonSettings {
212212
readonly defaultInterpreterPath: string;
213213
readonly logging: ILoggingSettings;
214214
readonly useIsolation: boolean;
215+
readonly tensorBoard: ITensorBoardSettings | undefined;
216+
}
217+
218+
export interface ITensorBoardSettings {
219+
readonly logDirectory: string | undefined;
215220
}
216221
export interface ISortImportSettings {
217222
readonly path: string;

src/client/tensorBoard/tensorBoardSession.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class TensorBoardSession {
7474
if (!tensorBoardWasInstalled) {
7575
return;
7676
}
77-
const logDir = await this.askUserForLogDir();
77+
const logDir = await this.getLogDirectory();
7878
if (!logDir) {
7979
return;
8080
}
@@ -251,7 +251,15 @@ export class TensorBoardSession {
251251
// Display a quickpick asking the user to acknowledge our autopopulated log directory or
252252
// select a new one using the file picker. Default this to the folder that is open in
253253
// the editor, if any, then the directory that the active text editor is in, if any.
254-
private async askUserForLogDir(): Promise<string | undefined> {
254+
private async getLogDirectory(): Promise<string | undefined> {
255+
// See if the user told us to always use a specific log directory
256+
const setting = this.workspaceService.getConfiguration('python.tensorBoard');
257+
const settingValue = setting.get<string>('logDirectory');
258+
if (settingValue) {
259+
traceInfo(`Using log directory specified by python.tensorBoard.logDirectory setting: ${settingValue}`);
260+
return settingValue;
261+
}
262+
// No log directory in settings. Ask the user which directory to use
255263
const logDir = this.autopopulateLogDirectoryPath();
256264
const useCurrentWorkingDirectory = TensorBoard.useCurrentWorkingDirectory();
257265
const selectAFolder = TensorBoard.selectAFolder();

src/test/tensorBoard/tensorBoardSession.test.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { assert } from 'chai';
22
import Sinon, * as sinon from 'sinon';
33
import { SemVer } from 'semver';
44
import { anything } from 'ts-mockito';
5-
import { IApplicationShell, ICommandManager } from '../../client/common/application/types';
5+
import { workspace, WorkspaceConfiguration } from 'vscode';
66
import {
77
IExperimentService,
88
IInstaller,
@@ -11,6 +11,7 @@ import {
1111
ProductInstallStatus,
1212
} from '../../client/common/types';
1313
import { Common, TensorBoard } from '../../client/common/utils/localize';
14+
import { IApplicationShell, ICommandManager } from '../../client/common/application/types';
1415
import { IServiceManager } from '../../client/ioc/types';
1516
import { TensorBoardEntrypoint, TensorBoardEntrypointTrigger } from '../../client/tensorBoard/constants';
1617
import { TensorBoardSession } from '../../client/tensorBoard/tensorBoardSession';
@@ -43,6 +44,8 @@ suite('TensorBoard session creation', async () => {
4344
let commandManager: ICommandManager;
4445
let experimentService: IExperimentService;
4546
let installer: IInstaller;
47+
let initialValue: string | undefined;
48+
let workspaceConfiguration: WorkspaceConfiguration;
4649

4750
suiteSetup(function () {
4851
if (process.env.CI_PYTHON_VERSION === '2.7') {
@@ -69,9 +72,13 @@ suite('TensorBoard session creation', async () => {
6972
applicationShell = serviceManager.get<IApplicationShell>(IApplicationShell);
7073
commandManager = serviceManager.get<ICommandManager>(ICommandManager);
7174
installer = serviceManager.get<IInstaller>(IInstaller);
75+
workspaceConfiguration = workspace.getConfiguration('python.tensorBoard');
76+
initialValue = workspaceConfiguration.get('logDirectory');
77+
await workspaceConfiguration.update('logDirectory', undefined, true);
7278
});
7379

7480
teardown(async () => {
81+
await workspaceConfiguration.update('logDirectory', initialValue, true);
7582
await closeActiveWindows();
7683
sandbox.restore();
7784
});
@@ -408,4 +415,24 @@ suite('TensorBoard session creation', async () => {
408415
assert.ok(session.panel?.visible, 'Webview panel not shown, expected successful session creation');
409416
});
410417
});
418+
test('If python.tensorBoard.logDirectory is provided, do not prompt user to pick a log directory', async () => {
419+
const selectDirectoryStub = sandbox
420+
.stub(applicationShell, 'showQuickPick')
421+
.resolves({ label: TensorBoard.useCurrentWorkingDirectory() });
422+
errorMessageStub = sandbox.stub(applicationShell, 'showErrorMessage');
423+
await workspaceConfiguration.update('logDirectory', 'logs/fit', true);
424+
425+
const session = (await commandManager.executeCommand(
426+
'python.launchTensorBoard',
427+
TensorBoardEntrypoint.palette,
428+
TensorBoardEntrypointTrigger.palette,
429+
)) as TensorBoardSession;
430+
431+
assert.ok(session.panel?.visible, 'Expected successful session creation but webpanel not shown');
432+
assert.ok(errorMessageStub.notCalled, 'Expected successful session creation but error message was shown');
433+
assert.ok(
434+
selectDirectoryStub.notCalled,
435+
'Prompted user to select log directory although setting was specified',
436+
);
437+
});
411438
});

0 commit comments

Comments
 (0)