Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiments Commands #2: Add "Run All Queued Experiments" Command #268

Merged
merged 4 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
"command": "dvc.queueExperiment",
"category": "DVC"
},
{
"title": "%command.runQueuedExperiments%",
"command": "dvc.runQueuedExperiments",
"category": "DVC"
},
{
"title": "%command.selectDvcPath%",
"command": "dvc.selectDvcPath",
Expand Down
1 change: 1 addition & 0 deletions extension/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"command.push": "Push",
"command.runExperiment": "Run Experiment",
"command.queueExperiment": "Queue Experiment",
"command.runQueuedExperiments": "Run Queued Experiments",
"command.selectDvcPath": "Select DVC CLI Path",
"command.showExperiments": "Show Experiments",
"config.dvcPath.title": "DVC CLI Path",
Expand Down
21 changes: 19 additions & 2 deletions extension/src/IntegratedTerminal.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { IntegratedTerminal, runExperiment } from './IntegratedTerminal'
import {
IntegratedTerminal,
runExperiment,
runQueuedExperiments
} from './IntegratedTerminal'

describe('runExperiment', () => {
it('should run the correct command in the IntegratedTerminal', async () => {
Expand All @@ -9,6 +13,19 @@ describe('runExperiment', () => {
const undef = await runExperiment()
expect(undef).toBeUndefined()

expect(terminalSpy).toBeCalledWith('dvc exp run ')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[C] This is super weird 😕

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old test is weird, or the fact this change was needed is weird?

For the latter, it's just a consequence of removing the exp run command builder, which built the command with a space at the end due to how it anticipated options.

For the former, agreed.

expect(terminalSpy).toBeCalledWith('dvc exp run')
})
})

describe('runQueuedExperiments', () => {
it('should run the correct command in the IntegratedTerminal', async () => {
const terminalSpy = jest
.spyOn(IntegratedTerminal, 'run')
.mockResolvedValueOnce(undefined)

const returnValue = await runQueuedExperiments()
expect(returnValue).toBeUndefined()

expect(terminalSpy).toBeCalledWith('dvc exp run --run-all')
})
})
13 changes: 10 additions & 3 deletions extension/src/IntegratedTerminal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Terminal, window, workspace } from 'vscode'
import { getRunExperimentCommand } from './cli/commands'
import { Commands } from './cli/commands'
import { getReadyPythonExtension } from './extensions/python'
import { delay } from './util'

Expand All @@ -21,6 +21,10 @@ export class IntegratedTerminal {
return currentTerminal?.sendText(command, true)
}

static runDvcCommand = async (command: string): Promise<void> => {
return IntegratedTerminal.run(`dvc ${command}`)
}

static dispose = (): void => {
const currentTerminal = IntegratedTerminal.instance
if (currentTerminal) {
Expand Down Expand Up @@ -65,6 +69,9 @@ export class IntegratedTerminal {
}

export const runExperiment = (): Promise<void> => {
const runExperimentCommand = getRunExperimentCommand()
return IntegratedTerminal.run(runExperimentCommand)
return IntegratedTerminal.runDvcCommand(Commands.experiment_run)
}

export const runQueuedExperiments = (): Promise<void> => {
return IntegratedTerminal.runDvcCommand(Commands.run_all_experiments)
}
15 changes: 2 additions & 13 deletions extension/src/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@ export enum Commands {
checkout = 'checkout',
checkout_recursive = 'checkout --recursive',
status = 'status --show-json',
queue_experiment = 'exp run --queue'
}

const getCliCommand = (command: string, ...options: string[]): string => {
return `dvc ${command} ${options.join(' ')}`
}

export const getRunExperimentCommand = (): string => {
return getCliCommand(Commands.experiment_run)
}

export const getAddCommand = (toAdd: string): string => {
return `${Commands.add} ${toAdd}`
queue_experiment = 'exp run --queue',
run_all_experiments = 'exp run --run-all'
}
Copy link
Contributor Author

@rogermparent rogermparent Apr 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making these builder commands for every possible string interpolation seems a bit overkill in the face of there being more commands, so instead this PR opts to remove these and go full enum.

We'll likely adopt some sort of shared command-building solution as we start using configurable options more, but I don't think this one is it.

4 changes: 2 additions & 2 deletions extension/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { basename, dirname } from 'path'
import { commands, window } from 'vscode'
import { Disposer } from '@hediet/std/disposable'
import { Config } from '../Config'
import { getAddCommand } from './commands'
import { Commands } from './commands'
import {
execCommand,
initializeDirectory,
Expand All @@ -20,7 +20,7 @@ export const add = async (options: {
const cwd = dirname(fsPath)

const toAdd = basename(fsPath)
const addCommand = getAddCommand(toAdd)
const addCommand = `${Commands.add} ${toAdd}`

const { stdout } = await execCommand({ cwd, cliPath }, addCommand)
return stdout
Expand Down
13 changes: 12 additions & 1 deletion extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import {
registerUpdateReconciler,
getReloadCount
} from '@hediet/node-reload'
import { IntegratedTerminal, runExperiment } from './IntegratedTerminal'
import {
IntegratedTerminal,
runExperiment,
runQueuedExperiments
} from './IntegratedTerminal'
import { Config } from './Config'
import { WebviewManager } from './webviews/WebviewManager'
import { getExperiments } from './cli/reader'
Expand Down Expand Up @@ -144,6 +148,13 @@ export class Extension {
})
)

this.dispose.track(
commands.registerCommand('dvc.runQueuedExperiments', async () => {
runQueuedExperiments()
this.showExperimentsWebview()
})
)

this.gitExtension = this.dispose.track(new GitExtension())

this.gitExtension.ready.then(() => {
Expand Down