Skip to content

Commit

Permalink
remove custom logic for live sharing experiments to studio (moved to …
Browse files Browse the repository at this point in the history
…dvc config)
  • Loading branch information
mattseddon committed May 25, 2023
1 parent 9d0f614 commit cd3bd27
Show file tree
Hide file tree
Showing 18 changed files with 91 additions and 260 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ These are the VS Code [settings] available for the Extension:
| `dvc.dvcPath` | Path or shell command to the DVC binary. Required unless Microsoft's [Python extension] is installed and the `dvc` package found in its environment. |
| `dvc.pythonPath` | Path to the desired Python interpreter to use with DVC. Should only be utilized when using a virtual environment without Microsoft's [Python extension]. |
| `dvc.experimentsTableHeadMaxHeight` | Maximum height of experiment table head rows. |
| `dvc.studio.shareExperimentsLive` | Automatically share all new experiment metrics and plots logged with DVCLive to Studio. This option will only take effect once Studio is connected. |
| `dvc.focusedProjects` | A subset of paths to the workspace's available DVC projects. Using this option will override project auto-discovery. |
| `dvc.doNotShowWalkthroughAfterInstall` | Do not prompt to show the Get Started page after installing. Useful for pre-configured development environments |
| `dvc.doNotRecommendAddStudioToken` | Do not prompt to add a [studio.token] to the global DVC config, which enables automatic sharing of experiments to [Studio]. |
Expand Down
5 changes: 0 additions & 5 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -643,11 +643,6 @@
"description": "Path to the desired Python interpreter to use with DVC. Required when using a virtual environment. Overrides any other extension's settings for this extension's purposes.",
"type": "string",
"default": null
},
"dvc.studio.shareExperimentsLive": {
"description": "Automatically share all new experiment metrics and plots logged with DVCLive to Studio. This option will only take effect once Studio is connected (studio.token is set).",
"type": "boolean",
"default": false
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion extension/src/cli/dvc/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ export enum GcPreserveFlag {
}

export enum ConfigKey {
STUDIO_TOKEN = 'studio.token'
STUDIO_TOKEN = 'studio.token',
STUDIO_OFFLINE = 'studio.offline'
}

type Target = string
Expand Down
2 changes: 1 addition & 1 deletion extension/src/cli/dvc/contract.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Plot } from '../../plots/webview/contract'

export const MIN_CLI_VERSION = '2.55.0'
export const MIN_CLI_VERSION = '2.57.0'
export const LATEST_TESTED_CLI_VERSION = '2.58.1'
export const MAX_CLI_VERSION = '3'

Expand Down
40 changes: 1 addition & 39 deletions extension/src/cli/dvc/executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Flag, GcPreserveFlag, UNEXPECTED_ERROR_CODE } from './constants'
import { DvcExecutor } from './executor'
import { CliResult, CliStarted } from '..'
import { createProcess } from '../../process/execution'
import { flushPromises, getMockedProcess } from '../../test/util/jest'
import { getMockedProcess } from '../../test/util/jest'
import { getProcessEnv } from '../../env'
import { Config } from '../../config'
import { ContextKey, setContextValue } from '../../vscode/context'
Expand All @@ -30,9 +30,6 @@ const mockedEnv = {

const mockedSetContextValue = jest.mocked(setContextValue)

const mockedGetStudioLiveShareToken = jest.fn()
const mockedGetRepoUrl = jest.fn()

beforeEach(() => {
jest.resetAllMocks()
mockedGetProcessEnv.mockReturnValueOnce(mockedEnv)
Expand All @@ -53,8 +50,6 @@ describe('CliExecutor', () => {
getCliPath: () => undefined,
getPythonBinPath: () => undefined
} as unknown as Config,
mockedGetStudioLiveShareToken,
mockedGetRepoUrl,
{
processCompleted: {
event: jest.fn(),
Expand Down Expand Up @@ -620,39 +615,6 @@ describe('CliExecutor', () => {
executable: 'dvc'
})
})

it("should call createProcess with the correct parameters to start the experiment's queue and send live updates to Studio", async () => {
const cwd = __dirname
const jobs = '91231324'
const mockedToken = 'isat_notarealtoken'
const mockedUrl = '[email protected]:iterative/vscode-dvc-demo.git'

mockedGetStudioLiveShareToken.mockReturnValueOnce(mockedToken)
mockedGetRepoUrl.mockResolvedValueOnce(
'[email protected]:iterative/vscode-dvc-demo.git'
)

const stdout = `Started '${jobs}' new experiments task queue workers.`

mockedCreateProcess.mockReturnValueOnce(getMockedProcess(stdout))

void dvcExecutor.queueStart(cwd, jobs)
await flushPromises()

expect(mockedGetRepoUrl).toHaveBeenCalledWith(cwd)

expect(mockedCreateProcess).toHaveBeenCalledWith({
args: ['queue', 'start', '-j', jobs],
cwd,
detached: true,
env: {
...mockedEnv,
STUDIO_REPO_URL: mockedUrl,
STUDIO_TOKEN: mockedToken
},
executable: 'dvc'
})
})
})

describe('queueStop', () => {
Expand Down
29 changes: 3 additions & 26 deletions extension/src/cli/dvc/executor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { EventEmitter } from 'vscode'
import { DvcCli } from '.'
import {
Args,
Expand All @@ -9,10 +8,8 @@ import {
GcPreserveFlag,
QueueSubCommand
} from './constants'
import { addStudioAccessToken } from './options'
import { CliResult, CliStarted, typeCheckCommands } from '..'
import { typeCheckCommands } from '..'
import { ContextKey, setContextValue } from '../../vscode/context'
import { Config } from '../../config'
import { DEFAULT_REMOTE } from '../git/constants'

export const autoRegisteredCommands = {
Expand Down Expand Up @@ -45,24 +42,8 @@ export class DvcExecutor extends DvcCli {
this
)

private readonly getStudioLiveShareToken: () => string | undefined
private readonly getRepoUrl: (cwd: string) => Promise<string>
private scmCommandRunning = false

constructor(
config: Config,
getStudioLiveShareToken: () => string | undefined,
getRepoUrl: (cwd: string) => Promise<string>,
emitters?: {
processStarted: EventEmitter<CliStarted>
processCompleted: EventEmitter<CliResult>
}
) {
super(config, emitters)
this.getStudioLiveShareToken = getStudioLiveShareToken
this.getRepoUrl = getRepoUrl
}

public add(cwd: string, target: string) {
return this.blockAndExecuteProcess(cwd, Command.ADD, target)
}
Expand Down Expand Up @@ -168,20 +149,16 @@ export class DvcExecutor extends DvcCli {
)
}

public async queueStart(cwd: string, jobs: string) {
public queueStart(cwd: string, jobs: string) {
const options = this.getOptions(
cwd,
Command.QUEUE,
QueueSubCommand.START,
Flag.JOBS,
jobs
)
const studioAccessToken = this.getStudioLiveShareToken()
const repoUrl = studioAccessToken ? await this.getRepoUrl(cwd) : undefined

return this.createBackgroundProcess(
addStudioAccessToken(options, studioAccessToken, repoUrl)
)
return this.createBackgroundProcess(options)
}

public queueStop(cwd: string, ...args: Args) {
Expand Down
26 changes: 0 additions & 26 deletions extension/src/cli/dvc/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,3 @@ export const getOptions = (
executable
}
}

export const addStudioAccessToken = (
options: ExecutionOptions,
studioAccessToken: string | undefined,
repoUrl?: string
): ExecutionOptions => {
if (!studioAccessToken) {
return options
}

if (!repoUrl) {
return {
...options,
env: { ...options.env, STUDIO_TOKEN: studioAccessToken }
}
}

return {
...options,
env: {
...options.env,
STUDIO_REPO_URL: repoUrl,
STUDIO_TOKEN: studioAccessToken
}
}
}
14 changes: 3 additions & 11 deletions extension/src/cli/dvc/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ExperimentFlag,
ExperimentSubCommand
} from './constants'
import { addStudioAccessToken, getOptions } from './options'
import { getOptions } from './options'
import { CliResult, CliStarted, ICli, typeCheckCommands } from '..'
import { getCommandString } from '../command'
import { Config } from '../../config'
Expand Down Expand Up @@ -46,15 +46,10 @@ export class DvcRunner extends Disposable implements ICli {
private readonly pseudoTerminal: PseudoTerminal
private currentProcess: Process | undefined
private readonly config: Config
private readonly getStudioLiveShareToken: () => string | undefined

constructor(
config: Config,
getStudioLiveShareToken: () => string | undefined
) {
constructor(config: Config) {
super()
this.config = config
this.getStudioLiveShareToken = getStudioLiveShareToken

this.processCompleted = this.dispose.track(new EventEmitter<CliResult>())
this.onDidCompleteProcess = this.processCompleted.event
Expand Down Expand Up @@ -175,15 +170,12 @@ export class DvcRunner extends Disposable implements ICli {
}

private getOptions(cwd: string, args: Args) {
const options = getOptions(
return getOptions(
this.config.getPythonBinPath(),
this.config.getCliPath(),
cwd,
...args
)

const studioAccessToken = this.getStudioLiveShareToken()
return addStudioAccessToken(options, studioAccessToken)
}

private startProcess(cwd: string, args: Args) {
Expand Down
12 changes: 2 additions & 10 deletions extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,10 @@ class Extension extends Disposable {
this.gitExecutor = this.dispose.track(new GitExecutor())
this.gitReader = this.dispose.track(new GitReader())

const getStudioLiveShareToken = () => this.setup.getStudioLiveShareToken()

this.dvcExecutor = this.dispose.track(
new DvcExecutor(config, getStudioLiveShareToken, cwd =>
this.gitReader.getRemoteUrl(cwd)
)
)
this.dvcExecutor = this.dispose.track(new DvcExecutor(config))

this.dvcReader = this.dispose.track(new DvcReader(config))
this.dvcRunner = this.dispose.track(
new DvcRunner(config, getStudioLiveShareToken)
)
this.dvcRunner = this.dispose.track(new DvcRunner(config))
this.dvcViewer = this.dispose.track(new DvcViewer(config))

const clis = [
Expand Down
Loading

0 comments on commit cd3bd27

Please sign in to comment.