Skip to content

Commit a38e841

Browse files
authored
Restructure plots path tree for nested dvc.yaml paths (#4527)
* create rough fix * improve implementation * fix lint issue
1 parent 39b40b9 commit a38e841

File tree

9 files changed

+167
-15
lines changed

9 files changed

+167
-15
lines changed

extension/src/cli/dvc/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export const TEMP_DAG_FILE = join(DOT_DVC, 'tmp', 'dag.md')
77

88
export const TEMP_PLOTS_DIR = join(DOT_DVC, 'tmp', 'plots')
99

10+
export const FIELD_SEPARATOR = '::'
11+
1012
const TEMP_EXP_DIR = join(DOT_DVC, 'tmp', 'exps')
1113
export const DVCLIVE_ONLY_RUNNING_SIGNAL_FILE = join(
1214
TEMP_EXP_DIR,

extension/src/experiments/columns/tree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class ExperimentsColumnsTree extends BasePathSelectionTree<WorkspaceExper
3939

4040
const { label, collapsibleState } = element
4141

42-
const treeItem = new TreeItem(label as string, collapsibleState)
42+
const treeItem = new TreeItem(label, collapsibleState)
4343

4444
return this.addTreeItemDetails(element, treeItem)
4545
}

extension/src/path/selection/tree.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export type PathSelectionItem = {
2525
description: string | undefined
2626
dvcRoot: string
2727
iconPath: Resource | Uri
28-
label: string | undefined
28+
label: string
2929
path: string
3030
tooltip: MarkdownString | undefined
3131
}
@@ -111,7 +111,7 @@ export abstract class BasePathSelectionTree<
111111
hasChildren: boolean
112112
path: string
113113
status: Status
114-
label?: string
114+
label: string
115115
tooltip?: MarkdownString
116116
}) {
117117
const {

extension/src/plots/multiSource/collect.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import {
1111
import { isImagePlot, Plot, TemplatePlot } from '../webview/contract'
1212
import { PlotsOutput } from '../../cli/dvc/contract'
1313
import { sortCollectedArray } from '../../util/array'
14-
15-
const FIELD_SEPARATOR = '::'
14+
import { FIELD_SEPARATOR } from '../../cli/dvc/constants'
1615

1716
type Values = { filename?: Set<string>; field?: Set<string> }
1817

extension/src/plots/paths/collect.test.ts

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,64 +15,74 @@ import plotsDiffFixture from '../../test/fixtures/plotsDiff/output'
1515
import { Shape, StrokeDash } from '../multiSource/constants'
1616
import { EXPERIMENT_WORKSPACE_ID, PlotsOutput } from '../../cli/dvc/contract'
1717
import { REVISIONS } from '../../test/fixtures/plotsDiff'
18+
import { FIELD_SEPARATOR } from '../../cli/dvc/constants'
1819

1920
const plotsDiffFixturePaths: PlotPath[] = [
2021
{
2122
hasChildren: false,
23+
label: 'acc.png',
2224
parentPath: 'plots',
2325
path: join('plots', 'acc.png'),
2426
revisions: new Set(REVISIONS),
2527
type: new Set<PathType>([PathType.COMPARISON])
2628
},
2729
{
2830
hasChildren: true,
31+
label: 'plots',
2932
parentPath: undefined,
3033
path: 'plots',
3134
revisions: new Set(REVISIONS)
3235
},
3336
{
3437
hasChildren: false,
38+
label: 'heatmap.png',
3539
parentPath: 'plots',
3640
path: join('plots', 'heatmap.png'),
3741
revisions: new Set(REVISIONS),
3842
type: new Set<PathType>([PathType.COMPARISON])
3943
},
4044
{
4145
hasChildren: false,
46+
label: 'loss.png',
4247
parentPath: 'plots',
4348
path: join('plots', 'loss.png'),
4449
revisions: new Set(REVISIONS),
4550
type: new Set<PathType>([PathType.COMPARISON])
4651
},
4752
{
4853
hasChildren: false,
54+
label: 'image',
4955
parentPath: 'plots',
5056
path: join('plots', 'image'),
5157
revisions: new Set(REVISIONS),
5258
type: new Set<PathType>([PathType.COMPARISON])
5359
},
5460
{
5561
hasChildren: false,
62+
label: 'loss.tsv',
5663
parentPath: 'logs',
5764
path: join('logs', 'loss.tsv'),
5865
revisions: new Set(REVISIONS),
5966
type: new Set<PathType>([PathType.TEMPLATE_SINGLE])
6067
},
6168
{
6269
hasChildren: true,
70+
label: 'logs',
6371
parentPath: undefined,
6472
path: 'logs',
6573
revisions: new Set(REVISIONS)
6674
},
6775
{
6876
hasChildren: false,
77+
label: 'acc.tsv',
6978
parentPath: 'logs',
7079
path: join('logs', 'acc.tsv'),
7180
revisions: new Set(REVISIONS),
7281
type: new Set<PathType>([PathType.TEMPLATE_SINGLE])
7382
},
7483
{
7584
hasChildren: false,
85+
label: 'predictions.json',
7686
parentPath: undefined,
7787
path: 'predictions.json',
7888
revisions: new Set(REVISIONS),
@@ -164,6 +174,7 @@ describe('collectPaths', () => {
164174
const pathsWithNoTypes: PlotPath[] = plotsDiffFixturePaths.map(
165175
plotPath => ({
166176
hasChildren: plotPath.hasChildren,
177+
label: plotPath.label,
167178
parentPath: plotPath.parentPath,
168179
path: plotPath.path,
169180
revisions: new Set(['workspace'])
@@ -183,6 +194,7 @@ describe('collectPaths', () => {
183194
const mockPath = 'completely:madeup:path'
184195
const mockPlotPath = {
185196
hasChildren: false,
197+
label: mockPath,
186198
parentPath: undefined,
187199
path: mockPath,
188200
revisions: new Set(['bfc7f64']),
@@ -230,56 +242,133 @@ describe('collectPaths', () => {
230242
revisions,
231243
type: PlotsType.VEGA
232244
}
245+
],
246+
[join(`dvc.yaml${FIELD_SEPARATOR}logs`, 'acc.tsv')]: [
247+
{
248+
content: {},
249+
datapoints: { [EXPERIMENT_WORKSPACE_ID]: [{}] },
250+
revisions,
251+
type: PlotsType.VEGA
252+
}
253+
],
254+
[join(
255+
'nested',
256+
'dvclive',
257+
`dvc.yaml${FIELD_SEPARATOR}logs`,
258+
'acc.tsv'
259+
)]: [
260+
{
261+
content: {},
262+
datapoints: { [EXPERIMENT_WORKSPACE_ID]: [{}] },
263+
revisions,
264+
type: PlotsType.VEGA
265+
}
233266
]
234267
}
235268
}
236269

237270
expect(collectPaths([], mockPlotsDiff, revisions)).toStrictEqual([
238271
{
239272
hasChildren: false,
273+
label: 'acc.tsv',
240274
parentPath: join('logs', 'scalars'),
241275
path: join('logs', 'scalars', 'acc.tsv'),
242276
revisions: new Set(revisions),
243277
type: new Set(['template-single'])
244278
},
245279
{
246280
hasChildren: true,
281+
label: 'scalars',
247282
parentPath: 'logs',
248283
path: join('logs', 'scalars'),
249284
revisions: new Set(revisions)
250285
},
251286
{
252287
hasChildren: true,
288+
label: 'logs',
253289
parentPath: undefined,
254290
path: 'logs',
255291
revisions: new Set(revisions)
256292
},
257293
{
258294
hasChildren: false,
295+
label: 'loss.tsv',
259296
parentPath: join('logs', 'scalars'),
260297
path: join('logs', 'scalars', 'loss.tsv'),
261298
revisions: new Set(revisions),
262299
type: new Set(['template-single'])
263300
},
264301
{
265302
hasChildren: false,
303+
label: 'heatmap.png',
266304
parentPath: 'plots',
267305
path: join('plots', 'heatmap.png'),
268306
revisions: new Set(revisions),
269307
type: new Set(['comparison'])
270308
},
271309
{
272310
hasChildren: true,
311+
label: 'plots',
273312
parentPath: undefined,
274313
path: 'plots',
275314
revisions: new Set(revisions)
276315
},
277316
{
278317
hasChildren: false,
318+
label: 'predictions.json',
279319
parentPath: undefined,
280320
path: 'predictions.json',
281321
revisions: new Set(revisions),
282322
type: new Set(['template-multi'])
323+
},
324+
{
325+
hasChildren: false,
326+
label: 'acc.tsv',
327+
parentPath: join(`dvc.yaml${FIELD_SEPARATOR}logs`),
328+
path: join(`dvc.yaml${FIELD_SEPARATOR}logs`, 'acc.tsv'),
329+
revisions: new Set(revisions),
330+
type: new Set(['template-single'])
331+
},
332+
{
333+
hasChildren: true,
334+
label: 'logs',
335+
parentPath: join('dvc.yaml'),
336+
path: join(`dvc.yaml${FIELD_SEPARATOR}logs`),
337+
revisions: new Set(revisions)
338+
},
339+
{
340+
hasChildren: true,
341+
label: 'dvc.yaml',
342+
parentPath: undefined,
343+
path: 'dvc.yaml',
344+
revisions: new Set(revisions)
345+
},
346+
{
347+
hasChildren: false,
348+
label: 'acc.tsv',
349+
parentPath: join('nested', 'dvclive', `dvc.yaml${FIELD_SEPARATOR}logs`),
350+
path: join(
351+
'nested',
352+
'dvclive',
353+
`dvc.yaml${FIELD_SEPARATOR}logs`,
354+
'acc.tsv'
355+
),
356+
revisions: new Set(revisions),
357+
type: new Set(['template-single'])
358+
},
359+
{
360+
hasChildren: true,
361+
label: 'logs',
362+
parentPath: join('nested', 'dvclive', 'dvc.yaml'),
363+
path: join('nested', 'dvclive', `dvc.yaml${FIELD_SEPARATOR}logs`),
364+
revisions: new Set(revisions)
365+
},
366+
{
367+
hasChildren: true,
368+
label: join('nested', 'dvclive', 'dvc.yaml'),
369+
parentPath: undefined,
370+
path: join('nested', 'dvclive', 'dvc.yaml'),
371+
revisions: new Set(revisions)
283372
}
284373
])
285374
})
@@ -308,24 +397,28 @@ describe('collectPaths', () => {
308397
expect(paths).toStrictEqual([
309398
{
310399
hasChildren: false,
400+
label: 'mip.jpg',
311401
parentPath: join('training', 'plots', 'images'),
312402
path: misspeltJpg,
313403
revisions
314404
},
315405
{
316406
hasChildren: true,
407+
label: 'images',
317408
parentPath: join('training', 'plots'),
318409
path: join('training', 'plots', 'images'),
319410
revisions
320411
},
321412
{
322413
hasChildren: true,
414+
label: 'plots',
323415
parentPath: 'training',
324416
path: join('training', 'plots'),
325417
revisions
326418
},
327419
{
328420
hasChildren: true,
421+
label: 'training',
329422
parentPath: undefined,
330423
path: 'training',
331424
revisions

0 commit comments

Comments
 (0)