-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e3ae9c
commit d848208
Showing
6 changed files
with
151 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Event, EventEmitter } from 'vscode' | ||
import { Disposable } from '@hediet/std/disposable' | ||
import { Deferred } from '@hediet/std/synchronization' | ||
import { isSameOrChild, loadYaml, PartialDvcYaml } from '..' | ||
import { findFiles } from '../workspace' | ||
import { join } from '../../test/util/path' | ||
import { createFileSystemWatcher } from '../watcher' | ||
|
||
export class FileSystemData { | ||
public readonly dispose = Disposable.fn() | ||
|
||
public readonly onDidUpdate: Event<{ path: string; yaml: PartialDvcYaml }> | ||
|
||
private readonly dvcRoot: string | ||
|
||
private readonly updated = this.dispose.track( | ||
new EventEmitter<{ path: string; yaml: PartialDvcYaml }>() | ||
) | ||
|
||
private readonly deferred = new Deferred() | ||
private readonly initialized = this.deferred.promise | ||
|
||
constructor(dvcRoot: string) { | ||
this.dvcRoot = dvcRoot | ||
this.onDidUpdate = this.updated.event | ||
|
||
this.watchDvcYaml() | ||
this.initialize() | ||
} | ||
|
||
public isReady() { | ||
return this.initialized | ||
} | ||
|
||
private async initialize() { | ||
const files = await findFiles(join('**', 'dvc.yaml')) | ||
const filesInRepo = files.filter(file => isSameOrChild(this.dvcRoot, file)) | ||
|
||
filesInRepo.map(path => { | ||
const yaml = loadYaml<PartialDvcYaml>(path) | ||
if (yaml) { | ||
this.updated.fire({ path, yaml }) | ||
} | ||
}) | ||
|
||
this.deferred.resolve() | ||
} | ||
|
||
private watchDvcYaml() { | ||
this.dispose.track( | ||
createFileSystemWatcher(join(this.dvcRoot, '**', 'dvc.yaml'), path => { | ||
if (!path) { | ||
return | ||
} | ||
const yaml = loadYaml<PartialDvcYaml>(path) | ||
if (yaml) { | ||
this.updated.fire({ path, yaml }) | ||
} | ||
}) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { afterEach, beforeEach, describe, it, suite } from 'mocha' | ||
import { stub, restore } from 'sinon' | ||
import { expect } from 'chai' | ||
import { Disposable } from '../../../../extension' | ||
import { FileSystemData } from '../../../../fileSystem/data' | ||
import { dvcDemoPath } from '../../../util' | ||
import * as FileSystem from '../../../../fileSystem' | ||
import * as Watcher from '../../../../fileSystem/watcher' | ||
import { getFirstArgOfCall } from '../../util' | ||
import { join } from '../../../util/path' | ||
|
||
suite('Experiments Data Test Suite', () => { | ||
const disposable = Disposable.fn() | ||
const mockWatcher = { | ||
dispose: stub() | ||
} as Disposable | ||
|
||
beforeEach(() => { | ||
restore() | ||
}) | ||
|
||
afterEach(() => { | ||
disposable.dispose() | ||
}) | ||
|
||
describe('FileSystemData', () => { | ||
it('should read the dvc.yaml from the demo path and send an event containing the path and the yaml', async () => { | ||
stub(Watcher, 'createFileSystemWatcher').returns(mockWatcher) | ||
const data = disposable.track(new FileSystemData(dvcDemoPath)) | ||
|
||
disposable.track( | ||
data.onDidUpdate(({ path, yaml }) => { | ||
expect(path).to.equal(dvcDemoPath) | ||
expect(yaml.stages.train.outs).to.deep.equal([ | ||
{ 'model.pt': { checkpoint: true } } | ||
]) | ||
}) | ||
) | ||
|
||
await data.isReady() | ||
}) | ||
|
||
it('should create a watcher with the expected glob', async () => { | ||
const mockCreateFileSystemWatcher = stub( | ||
Watcher, | ||
'createFileSystemWatcher' | ||
).returns(mockWatcher) | ||
stub(FileSystem, 'loadYaml').returns(undefined) | ||
const data = disposable.track(new FileSystemData(dvcDemoPath)) | ||
|
||
expect(mockCreateFileSystemWatcher).to.be.calledOnce | ||
expect(getFirstArgOfCall(mockCreateFileSystemWatcher, 0)).to.equal( | ||
join(dvcDemoPath, '**', 'dvc.yaml') | ||
) | ||
|
||
await data.isReady() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters