Skip to content

Commit 29a72b4

Browse files
evanphilipEvan Philip
andauthored
Extend scope of "python.tensorBoard.logDirectory" and support variable substitution (microsoft#20103)
Fixes microsoft/vscode-jupyter#8802 Credit: @PillarsZhang [patch-by-zhang](https://github.com/PillarsZhang/vscode-python/tree/patch-by-zhang) Co-authored-by: Evan Philip <[email protected]>
1 parent f671b9b commit 29a72b4

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@
10231023
"python.tensorBoard.logDirectory": {
10241024
"default": "",
10251025
"description": "%python.tensorBoard.logDirectory.description%",
1026-
"scope": "application",
1026+
"scope": "resource",
10271027
"type": "string"
10281028
},
10291029
"python.terminal.activateEnvInCurrentTerminal": {

src/client/common/configSettings.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,13 @@ export class PythonSettings implements IPythonSettings {
504504
optOutFrom: [],
505505
};
506506

507-
this.tensorBoard = pythonSettings.get<ITensorBoardSettings>('tensorBoard');
507+
const tensorBoardSettings = systemVariables.resolveAny(
508+
pythonSettings.get<ITensorBoardSettings>('tensorBoard'),
509+
)!;
510+
this.tensorBoard = tensorBoardSettings || { logDirectory: '' };
511+
if (this.tensorBoard.logDirectory) {
512+
this.tensorBoard.logDirectory = getAbsolutePath(this.tensorBoard.logDirectory, workspaceRoot);
513+
}
508514
}
509515

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

src/client/common/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export interface IPythonSettings {
205205
}
206206

207207
export interface ITensorBoardSettings {
208-
readonly logDirectory: string | undefined;
208+
logDirectory: string | undefined;
209209
}
210210
export interface ISortImportSettings {
211211
readonly path: string;

src/client/tensorBoard/tensorBoardSession.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
ProductInstallStatus,
3636
Product,
3737
IPersistentState,
38+
IConfigurationService,
3839
} from '../common/types';
3940
import { createDeferred, sleep } from '../common/utils/async';
4041
import { Common, TensorBoard } from '../common/utils/localize';
@@ -100,6 +101,7 @@ export class TensorBoardSession {
100101
private readonly applicationShell: IApplicationShell,
101102
private readonly globalMemento: IPersistentState<ViewColumn>,
102103
private readonly multiStepFactory: IMultiStepInputFactory,
104+
private readonly configurationService: IConfigurationService,
103105
) {}
104106

105107
public get onDidDispose(): Event<TensorBoardSession> {
@@ -341,10 +343,10 @@ export class TensorBoardSession {
341343
// the editor, if any, then the directory that the active text editor is in, if any.
342344
private async getLogDirectory(): Promise<string | undefined> {
343345
// See if the user told us to always use a specific log directory
344-
const setting = this.workspaceService.getConfiguration('python.tensorBoard');
345-
const settingValue = setting.get<string>('logDirectory');
346+
const settings = this.configurationService.getSettings();
347+
const settingValue = settings.tensorBoard?.logDirectory;
346348
if (settingValue) {
347-
traceInfo(`Using log directory specified by python.tensorBoard.logDirectory setting: ${settingValue}`);
349+
traceInfo(`Using log directory resolved by python.tensorBoard.logDirectory setting: ${settingValue}`);
348350
return settingValue;
349351
}
350352
// No log directory in settings. Ask the user which directory to use

src/client/tensorBoard/tensorBoardSessionProvider.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ import { IApplicationShell, ICommandManager, IWorkspaceService } from '../common
99
import { Commands } from '../common/constants';
1010
import { ContextKey } from '../common/contextKey';
1111
import { IPythonExecutionFactory } from '../common/process/types';
12-
import { IDisposableRegistry, IInstaller, IPersistentState, IPersistentStateFactory } from '../common/types';
12+
import {
13+
IDisposableRegistry,
14+
IInstaller,
15+
IPersistentState,
16+
IPersistentStateFactory,
17+
IConfigurationService,
18+
} from '../common/types';
1319
import { IMultiStepInputFactory } from '../common/utils/multiStepInput';
1420
import { IInterpreterService } from '../interpreter/contracts';
1521
import { traceError, traceInfo } from '../logging';
@@ -42,6 +48,7 @@ export class TensorBoardSessionProvider implements IExtensionSingleActivationSer
4248
@inject(IPythonExecutionFactory) private readonly pythonExecFactory: IPythonExecutionFactory,
4349
@inject(IPersistentStateFactory) private stateFactory: IPersistentStateFactory,
4450
@inject(IMultiStepInputFactory) private readonly multiStepFactory: IMultiStepInputFactory,
51+
@inject(IConfigurationService) private readonly configurationService: IConfigurationService,
4552
) {
4653
this.preferredViewGroupMemento = this.stateFactory.createGlobalPersistentState<ViewColumn>(
4754
PREFERRED_VIEWGROUP,
@@ -102,6 +109,7 @@ export class TensorBoardSessionProvider implements IExtensionSingleActivationSer
102109
this.applicationShell,
103110
this.preferredViewGroupMemento,
104111
this.multiStepFactory,
112+
this.configurationService,
105113
);
106114
newSession.onDidChangeViewState(() => this.updateTensorBoardSessionContext(), this, this.disposables);
107115
newSession.onDidDispose((e) => this.didDisposeSession(e), this, this.disposables);

0 commit comments

Comments
 (0)