Skip to content

Commit

Permalink
Show DVC Cli Details in DVC Setup (#3688)
Browse files Browse the repository at this point in the history
  • Loading branch information
julieg18 authored Apr 27, 2023
1 parent 2bc96d3 commit 12221b1
Show file tree
Hide file tree
Showing 22 changed files with 746 additions and 278 deletions.
38 changes: 35 additions & 3 deletions extension/src/setup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import {
} from 'vscode'
import { Disposable, Disposer } from '@hediet/std/disposable'
import isEmpty from 'lodash.isempty'
import { SetupSection, SetupData as TSetupData } from './webview/contract'
import {
DvcCliDetails,
SetupSection,
SetupData as TSetupData
} from './webview/contract'
import { collectSectionCollapsed } from './collect'
import { WebviewMessages } from './webview/messages'
import { validateTokenInput } from './inputBox'
Expand All @@ -20,7 +24,6 @@ import { BaseWebview } from '../webview'
import { ViewKey } from '../webview/constants'
import { BaseRepository } from '../webview/repository'
import { Resource } from '../resourceLocator'
import { isPythonExtensionInstalled } from '../extensions/python'
import {
findAbsoluteDvcRootPath,
findDvcRootPaths,
Expand Down Expand Up @@ -52,6 +55,7 @@ import { GLOBAL_WEBVIEW_DVCROOT } from '../webview/factory'
import { ConfigKey, getConfigValue } from '../vscode/config'
import { getValidInput } from '../vscode/inputBox'
import { Title } from '../vscode/title'
import { getOptions } from '../cli/dvc/options'

export type SetupWebviewWebview = BaseWebview<TSetupData>

Expand Down Expand Up @@ -334,10 +338,34 @@ export class Setup
return this.sendDataToWebview()
}

public async getDvcCliDetails(): Promise<DvcCliDetails> {
const dvcPath = this.config.getCliPath()
const pythonBinPath = this.config.getPythonBinPath()
const cwd = getFirstWorkspaceFolder()

const { args, executable } = getOptions(pythonBinPath, dvcPath, cwd || '')
const commandArgs = args.length === 0 ? '' : ` ${args.join(' ')}`
const command = executable + commandArgs

return {
command,
version: cwd ? await this.getCliVersion(cwd) : undefined
}
}

private isDVCBeingUsedGlobally() {
const dvcPath = this.config.getCliPath()
const pythonBinPath = this.config.getPythonBinPath()

return dvcPath || !pythonBinPath
}

private async sendDataToWebview() {
const projectInitialized = this.hasRoots()
const hasData = this.getHasData()

const isPythonExtensionUsed = await this.isPythonExtensionUsed()

const needsGitInitialized =
!projectInitialized && !!(await this.needsGitInit())

Expand All @@ -348,11 +376,15 @@ export class Setup

const pythonBinPath = await findPythonBinForInstall()

const dvcCliDetails = await this.getDvcCliDetails()

this.webviewMessages.sendWebviewMessage({
canGitInitialize,
cliCompatible: this.cliCompatible,
dvcCliDetails,
hasData,
isPythonExtensionInstalled: isPythonExtensionInstalled(),
isPythonExtensionUsed:
!this.isDVCBeingUsedGlobally() && isPythonExtensionUsed,
isStudioConnected: this.studioIsConnected,
needsGitCommit,
needsGitInitialized,
Expand Down
8 changes: 7 additions & 1 deletion extension/src/setup/webview/contract.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
export type DvcCliDetails = {
command: string
version: string | undefined
}

export type SetupData = {
canGitInitialize: boolean
cliCompatible: boolean | undefined
dvcCliDetails: DvcCliDetails
hasData: boolean | undefined
isPythonExtensionInstalled: boolean
isPythonExtensionUsed: boolean
isStudioConnected: boolean
needsGitCommit: boolean
needsGitInitialized: boolean | undefined
Expand Down
6 changes: 4 additions & 2 deletions extension/src/setup/webview/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ export class WebviewMessages {
public sendWebviewMessage({
canGitInitialize,
cliCompatible,
dvcCliDetails,
hasData,
isPythonExtensionInstalled,
isPythonExtensionUsed,
isStudioConnected,
needsGitCommit,
needsGitInitialized,
Expand All @@ -48,8 +49,9 @@ export class WebviewMessages {
void this.getWebview()?.show({
canGitInitialize,
cliCompatible,
dvcCliDetails,
hasData,
isPythonExtensionInstalled,
isPythonExtensionUsed,
isStudioConnected,
needsGitCommit,
needsGitInitialized,
Expand Down
22 changes: 18 additions & 4 deletions extension/src/test/suite/setup/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ suite('Setup Test Suite', () => {
setup.setCliCompatible(undefined)
setup.setAvailable(false)
await setup.setRoots()
stub(setup, 'getCliVersion').resolves(undefined)

messageSpy.restore()
const mockSendMessage = stub(BaseWebview.prototype, 'show')
Expand All @@ -238,8 +239,9 @@ suite('Setup Test Suite', () => {
expect(mockSendMessage).to.be.calledWithExactly({
canGitInitialize: true,
cliCompatible: undefined,
dvcCliDetails: { command: 'dvc', version: undefined },
hasData: false,
isPythonExtensionInstalled: false,
isPythonExtensionUsed: false,
isStudioConnected: false,
needsGitCommit: true,
needsGitInitialized: true,
Expand Down Expand Up @@ -278,8 +280,9 @@ suite('Setup Test Suite', () => {
expect(mockSendMessage).to.be.calledWithExactly({
canGitInitialize: true,
cliCompatible: true,
dvcCliDetails: { command: 'dvc', version: MIN_CLI_VERSION },
hasData: false,
isPythonExtensionInstalled: false,
isPythonExtensionUsed: false,
isStudioConnected: false,
needsGitCommit: true,
needsGitInitialized: true,
Expand Down Expand Up @@ -324,8 +327,12 @@ suite('Setup Test Suite', () => {
expect(mockSendMessage).to.be.calledWithExactly({
canGitInitialize: false,
cliCompatible: true,
dvcCliDetails: {
command: 'dvc',
version: MIN_CLI_VERSION
},
hasData: false,
isPythonExtensionInstalled: false,
isPythonExtensionUsed: false,
isStudioConnected: false,
needsGitCommit: false,
needsGitInitialized: false,
Expand Down Expand Up @@ -370,8 +377,12 @@ suite('Setup Test Suite', () => {
expect(mockSendMessage).to.be.calledWithExactly({
canGitInitialize: false,
cliCompatible: true,
dvcCliDetails: {
command: 'dvc',
version: MIN_CLI_VERSION
},
hasData: false,
isPythonExtensionInstalled: false,
isPythonExtensionUsed: false,
isStudioConnected: false,
needsGitCommit: true,
needsGitInitialized: false,
Expand Down Expand Up @@ -568,6 +579,7 @@ suite('Setup Test Suite', () => {
mockRunSetup.restore()
stub(config, 'isPythonExtensionUsed').returns(false)
stub(config, 'getPythonBinPath').resolves(join('python'))
stub(setup, 'getDvcCliDetails').resolves(undefined)

mockVersion.resetBehavior()
mockVersion
Expand Down Expand Up @@ -627,6 +639,7 @@ suite('Setup Test Suite', () => {
mockExecuteCommand.restore()
mockRunSetup.restore()
stub(config, 'isPythonExtensionUsed').returns(true)
stub(setup, 'getDvcCliDetails').resolves(undefined)

mockVersion.resetBehavior()
mockVersion.rejects(new Error('no CLI here'))
Expand Down Expand Up @@ -762,6 +775,7 @@ suite('Setup Test Suite', () => {
const mockUpdate = stub()

stub(workspace, 'getConfiguration').returns({
get: stub(),
update: mockUpdate
} as unknown as WorkspaceConfiguration)

Expand Down
6 changes: 1 addition & 5 deletions webview/src/experiments/components/table/styles.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -836,13 +836,9 @@ $badge-size: 0.85rem;
// below table styles

.buttonAsLink {
@extend %link;
@extend %buttonAsLink;

background: none;
border: none;
padding: 0;
font-size: 0.65rem;
cursor: pointer;
}

.addConfigButton {
Expand Down
Loading

0 comments on commit 12221b1

Please sign in to comment.