Skip to content

Commit ad00496

Browse files
authored
Handle non-standard experiment pipeline configurations (#4264)
* add pipeline model for stages data * start to move functionality across to pipeline * move check or add pipeline into pipeline class (no-verify) * move check or add pipeline tests into mocha * fix test pipeline builders * stub experiments for all getters * move reader stubs into build dependencies * add stubs for on did update * refactor pipeline collection * refactor workspace experiments * add more unit tests for pipeline collection
1 parent 46d8fd0 commit ad00496

File tree

35 files changed

+889
-822
lines changed

35 files changed

+889
-822
lines changed

extension/src/cli/dvc/reader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const autoRegisteredCommands = {
3838
GLOBAL_VERSION: 'globalVersion',
3939
PLOTS_DIFF: 'plotsDiff',
4040
ROOT: 'root',
41-
STAGE_LIST: 'listStages',
41+
STAGE_LIST: 'stageList',
4242
VERSION: 'version'
4343
} as const
4444

@@ -144,7 +144,7 @@ export class DvcReader extends DvcCli {
144144
return this.executeProcess(options)
145145
}
146146

147-
public async listStages(cwd: string): Promise<string | undefined> {
147+
public async stageList(cwd: string): Promise<string | undefined> {
148148
try {
149149
return await this.executeDvcProcess(cwd, Command.STAGE, SubCommand.LIST)
150150
} catch {}

extension/src/data/index.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ export abstract class BaseData<
2020
T extends
2121
| { data: PlotsOutputOrError; revs: string[] }
2222
| ExperimentsOutput
23-
| string
23+
| { dag: string; stages: { [pipeline: string]: string | undefined } }
2424
> extends DeferredDisposable {
2525
public readonly onDidUpdate: Event<T>
26-
public readonly onDidChangeDvcYaml: Event<void>
2726

2827
protected readonly dvcRoot: string
2928
protected readonly processManager: ProcessManager
@@ -36,10 +35,6 @@ export abstract class BaseData<
3635
new EventEmitter()
3736
)
3837

39-
private readonly dvcYamlChanged: EventEmitter<void> = this.dispose.track(
40-
new EventEmitter<void>()
41-
)
42-
4338
constructor(
4439
dvcRoot: string,
4540
internalCommands: InternalCommands,
@@ -56,8 +51,6 @@ export abstract class BaseData<
5651
this.onDidUpdate = this.updated.event
5752
this.staticFiles = staticFiles
5853

59-
this.onDidChangeDvcYaml = this.dvcYamlChanged.event
60-
6154
this.watchFiles()
6255

6356
this.waitForInitialData()
@@ -96,13 +89,9 @@ export abstract class BaseData<
9689
) {
9790
void this.managedUpdate(path)
9891
}
99-
100-
if (path.endsWith('dvc.yaml')) {
101-
this.dvcYamlChanged.fire()
102-
}
10392
}
10493
)
10594
}
10695

107-
abstract managedUpdate(path?: string): Promise<unknown>
96+
abstract managedUpdate(path?: string): Promise<void>
10897
}

extension/src/experiments/index.ts

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import { ConfigKey, getConfigValue, setUserConfigValue } from '../vscode/config'
4444
import { checkSignalFile, pollSignalFileForProcess } from '../fileSystem'
4545
import { DVCLIVE_ONLY_RUNNING_SIGNAL_FILE } from '../cli/dvc/constants'
4646
import { Response } from '../vscode/response'
47+
import { Pipeline } from '../pipeline'
4748

4849
export const ExperimentsScale = {
4950
...omit(ColumnType, 'TIMESTAMP'),
@@ -64,8 +65,9 @@ export class Experiments extends BaseRepository<TableData> {
6465

6566
public readonly viewKey = ViewKey.EXPERIMENTS
6667

67-
private readonly data: ExperimentsData
68+
private readonly pipeline: Pipeline
6869

70+
private readonly data: ExperimentsData
6971
private readonly experiments: ExperimentsModel
7072
private readonly columns: ColumnsModel
7173

@@ -96,17 +98,16 @@ export class Experiments extends BaseRepository<TableData> {
9698
private dvcLiveOnlyCleanupInitialized = false
9799
private dvcLiveOnlySignalFile: string
98100

99-
private readonly addStage: () => Promise<boolean>
100101
private readonly selectBranches: (
101102
branchesSelected: string[]
102103
) => Promise<string[] | undefined>
103104

104105
constructor(
105106
dvcRoot: string,
106107
internalCommands: InternalCommands,
108+
pipeline: Pipeline,
107109
resourceLocator: ResourceLocator,
108110
workspaceState: Memento,
109-
addStage: () => Promise<boolean>,
110111
selectBranches: (
111112
branchesSelected: string[]
112113
) => Promise<string[] | undefined>,
@@ -120,7 +121,7 @@ export class Experiments extends BaseRepository<TableData> {
120121
)
121122

122123
this.internalCommands = internalCommands
123-
this.addStage = addStage
124+
this.pipeline = pipeline
124125
this.selectBranches = selectBranches
125126

126127
this.onDidChangeIsExperimentsFileFocused = this.experimentsFileFocused.event
@@ -146,11 +147,6 @@ export class Experiments extends BaseRepository<TableData> {
146147
)
147148

148149
this.dispose.track(this.data.onDidUpdate(data => this.setState(data)))
149-
this.dispose.track(
150-
this.data.onDidChangeDvcYaml(() =>
151-
this.webviewMessages.changeHasConfig(true)
152-
)
153-
)
154150

155151
this.dispose.track(
156152
workspace.onDidChangeConfiguration((event: ConfigurationChangeEvent) => {
@@ -437,20 +433,30 @@ export class Experiments extends BaseRepository<TableData> {
437433
public async modifyWorkspaceParamsAndRun(
438434
commandId: ModifiedExperimentAndRunCommandId
439435
) {
436+
const cwd = await this.getPipelineCwd()
437+
if (!cwd) {
438+
return
439+
}
440+
440441
const paramsToModify = await this.pickAndModifyParams()
441442
if (!paramsToModify) {
442443
return
443444
}
444445

445446
await this.internalCommands.executeCommand<string>(
446447
commandId,
447-
this.dvcRoot,
448+
cwd,
448449
...paramsToModify
449450
)
450451
return this.notifyChanged()
451452
}
452453

453454
public async modifyWorkspaceParamsAndQueue() {
455+
const cwd = await this.getPipelineCwd()
456+
if (!cwd) {
457+
return
458+
}
459+
454460
const paramsToModify = await this.pickAndModifyParams()
455461
if (!paramsToModify) {
456462
return
@@ -459,7 +465,7 @@ export class Experiments extends BaseRepository<TableData> {
459465
await Toast.showOutput(
460466
this.internalCommands.executeCommand<string>(
461467
AvailableCommands.EXP_QUEUE,
462-
this.dvcRoot,
468+
cwd,
463469
...paramsToModify
464470
)
465471
)
@@ -521,16 +527,26 @@ export class Experiments extends BaseRepository<TableData> {
521527
return this.columns.getRelativeMetricsFiles()
522528
}
523529

530+
public getPipelineCwd() {
531+
return this.pipeline.getCwd()
532+
}
533+
524534
protected sendInitialWebviewData() {
525535
return this.webviewMessages.sendWebviewMessage()
526536
}
527537

528538
private setupInitialData() {
529539
const waitForInitialData = this.dispose.track(
530-
this.onDidChangeExperiments(() => {
540+
this.onDidChangeExperiments(async () => {
541+
await this.pipeline.isReady()
531542
this.deferred.resolve()
532543
this.dispose.untrack(waitForInitialData)
533544
waitForInitialData.dispose()
545+
this.dispose.track(
546+
this.pipeline.onDidUpdate(() =>
547+
this.webviewMessages.sendWebviewMessage()
548+
)
549+
)
534550
})
535551
)
536552
}
@@ -555,15 +571,10 @@ export class Experiments extends BaseRepository<TableData> {
555571
this.dvcRoot,
556572
this.experiments,
557573
this.columns,
574+
this.pipeline,
558575
() => this.getWebview(),
559576
() => this.notifyChanged(),
560577
() => this.selectColumns(),
561-
() =>
562-
this.internalCommands.executeCommand(
563-
AvailableCommands.STAGE_LIST,
564-
this.dvcRoot
565-
),
566-
() => this.addStage(),
567578
(branchesSelected: string[]) => this.selectBranches(branchesSelected),
568579
() => this.data.update()
569580
)

extension/src/experiments/webview/contract.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ export type TableData = {
104104
hasConfig: boolean
105105
hasMoreCommits: Record<string, boolean>
106106
hasRunningWorkspaceExperiment: boolean
107-
hasValidDvcYaml: boolean
108107
isShowingMoreCommits: Record<string, boolean>
109108
rows: Commit[]
110109
selectedForPlotsCount: number

extension/src/experiments/webview/messages.ts

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,20 @@ import { SortDefinition } from '../model/sortBy'
2020
import { getPositiveIntegerInput } from '../../vscode/inputBox'
2121
import { Title } from '../../vscode/title'
2222
import { ConfigKey, setConfigValue } from '../../vscode/config'
23-
import { hasDvcYamlFile } from '../../fileSystem'
2423
import { NUM_OF_COMMITS_TO_INCREASE } from '../../cli/dvc/constants'
24+
import { Pipeline } from '../../pipeline'
2525

2626
export class WebviewMessages {
2727
private readonly dvcRoot: string
2828

2929
private readonly experiments: ExperimentsModel
3030
private readonly columns: ColumnsModel
31+
private readonly pipeline: Pipeline
3132

3233
private readonly getWebview: () => BaseWebview<TableData> | undefined
3334
private readonly notifyChanged: () => void
3435
private readonly selectColumns: () => Promise<void>
3536

36-
private readonly hasStages: () => Promise<string | undefined>
37-
38-
private hasConfig = false
39-
private hasValidDvcYaml = true
40-
41-
private readonly addStage: () => Promise<boolean>
4237
private readonly selectBranches: (
4338
branchesSelected: string[]
4439
) => Promise<string[] | undefined>
@@ -49,11 +44,10 @@ export class WebviewMessages {
4944
dvcRoot: string,
5045
experiments: ExperimentsModel,
5146
columns: ColumnsModel,
47+
pipeline: Pipeline,
5248
getWebview: () => BaseWebview<TableData> | undefined,
5349
notifyChanged: () => void,
5450
selectColumns: () => Promise<void>,
55-
hasStages: () => Promise<string>,
56-
addStage: () => Promise<boolean>,
5751
selectBranches: (
5852
branchesSelected: string[]
5953
) => Promise<string[] | undefined>,
@@ -62,22 +56,12 @@ export class WebviewMessages {
6256
this.dvcRoot = dvcRoot
6357
this.experiments = experiments
6458
this.columns = columns
59+
this.pipeline = pipeline
6560
this.getWebview = getWebview
6661
this.notifyChanged = notifyChanged
6762
this.selectColumns = selectColumns
68-
this.hasStages = hasStages
69-
this.addStage = addStage
7063
this.selectBranches = selectBranches
7164
this.update = update
72-
73-
void this.changeHasConfig()
74-
}
75-
76-
public async changeHasConfig(update?: boolean) {
77-
const stages = await this.hasStages()
78-
this.hasValidDvcYaml = !hasDvcYamlFile(this.dvcRoot) || stages !== undefined
79-
this.hasConfig = !!stages
80-
update && this.sendWebviewMessage()
8165
}
8266

8367
public sendWebviewMessage() {
@@ -267,20 +251,19 @@ export class WebviewMessages {
267251
this.experiments.getAvailableBranchesToShow().length > 0,
268252
hasCheckpoints: this.experiments.hasCheckpoints(),
269253
hasColumns: this.columns.hasNonDefaultColumns(),
270-
hasConfig: this.hasConfig,
254+
hasConfig: this.pipeline.hasPipeline(),
271255
hasMoreCommits: this.experiments.getHasMoreCommits(),
272256
hasRunningWorkspaceExperiment:
273257
this.experiments.hasRunningWorkspaceExperiment(),
274-
hasValidDvcYaml: this.hasValidDvcYaml,
275258
isShowingMoreCommits: this.experiments.getIsShowingMoreCommits(),
276259
rows: this.experiments.getRowData(),
277260
selectedForPlotsCount: this.experiments.getSelectedRevisions().length,
278261
sorts: this.experiments.getSorts()
279262
}
280263
}
281264

282-
private async addConfiguration() {
283-
await this.addStage()
265+
private addConfiguration() {
266+
return this.pipeline.checkOrAddPipeline()
284267
}
285268

286269
private async setMaxTableHeadDepth() {

0 commit comments

Comments
 (0)