Skip to content

Commit 1b39901

Browse files
authored
Update Setup "dvc is unavailable" section text content (#4098)
* update button names * simplify text content * add warning with global environments
1 parent 4f5be9f commit 1b39901

File tree

10 files changed

+84
-25
lines changed

10 files changed

+84
-25
lines changed

extension/src/setup/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ import { Title } from '../vscode/title'
6060
import { getDVCAppDir } from '../util/appdirs'
6161
import { getOptions } from '../cli/dvc/options'
6262
import { isAboveLatestTestedVersion } from '../cli/dvc/version'
63-
import { createPythonEnv, selectPythonInterpreter } from '../extensions/python'
63+
import {
64+
createPythonEnv,
65+
isActivePythonEnvGlobal,
66+
selectPythonInterpreter
67+
} from '../extensions/python'
6468

6569
export class Setup
6670
extends BaseRepository<TSetupData>
@@ -396,12 +400,16 @@ export class Setup
396400

397401
const pythonBinPath = await findPythonBinForInstall()
398402

403+
const isPythonEnvironmentGlobal =
404+
isPythonExtensionUsed && (await isActivePythonEnvGlobal())
405+
399406
this.webviewMessages.sendWebviewMessage({
400407
canGitInitialize,
401408
cliCompatible: this.getCliCompatible(),
402409
dvcCliDetails,
403410
hasData,
404411
isAboveLatestTestedVersion: isAboveLatestTestedVersion(this.cliVersion),
412+
isPythonEnvironmentGlobal,
405413
isPythonExtensionUsed,
406414
isStudioConnected: this.studioIsConnected,
407415
needsGitCommit,

extension/src/setup/webview/contract.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export type SetupData = {
1212
cliCompatible: boolean | undefined
1313
dvcCliDetails: DvcCliDetails | undefined
1414
hasData: boolean | undefined
15+
isPythonEnvironmentGlobal: boolean | undefined
1516
isPythonExtensionUsed: boolean
1617
isStudioConnected: boolean
1718
needsGitCommit: boolean

extension/src/test/suite/setup/index.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ suite('Setup Test Suite', () => {
356356
dvcCliDetails: { command: 'dvc', version: undefined },
357357
hasData: false,
358358
isAboveLatestTestedVersion: undefined,
359+
isPythonEnvironmentGlobal: false,
359360
isPythonExtensionUsed: false,
360361
isStudioConnected: false,
361362
needsGitCommit: true,
@@ -400,6 +401,7 @@ suite('Setup Test Suite', () => {
400401
dvcCliDetails: { command: 'dvc', version: MIN_CLI_VERSION },
401402
hasData: false,
402403
isAboveLatestTestedVersion: false,
404+
isPythonEnvironmentGlobal: false,
403405
isPythonExtensionUsed: false,
404406
isStudioConnected: false,
405407
needsGitCommit: true,
@@ -452,6 +454,7 @@ suite('Setup Test Suite', () => {
452454
},
453455
hasData: false,
454456
isAboveLatestTestedVersion: false,
457+
isPythonEnvironmentGlobal: false,
455458
isPythonExtensionUsed: false,
456459
isStudioConnected: false,
457460
needsGitCommit: false,
@@ -504,6 +507,7 @@ suite('Setup Test Suite', () => {
504507
},
505508
hasData: false,
506509
isAboveLatestTestedVersion: false,
510+
isPythonEnvironmentGlobal: false,
507511
isPythonExtensionUsed: false,
508512
isStudioConnected: false,
509513
needsGitCommit: true,

webview/src/setup/components/App.test.tsx

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const DEFAULT_DATA = {
3131
},
3232
hasData: false,
3333
isAboveLatestTestedVersion: false,
34+
isPythonEnvironmentGlobal: false,
3435
isPythonExtensionUsed: false,
3536
isStudioConnected: false,
3637
needsGitCommit: false,
@@ -161,7 +162,7 @@ describe('App', () => {
161162
})
162163

163164
const sentenceReg = new RegExp(
164-
`DVC & DVCLive can be auto-installed with ${defaultInterpreter}.`
165+
`Auto-install \\(pip\\) DVC & DVCLive with ${defaultInterpreter}`
165166
)
166167

167168
expect(screen.getByText(sentenceReg)).toBeInTheDocument()
@@ -178,7 +179,7 @@ describe('App', () => {
178179
pythonBinPath: 'python'
179180
})
180181

181-
const button = screen.getByText('Configure')
182+
const button = screen.getByText('Locate DVC')
182183
fireEvent.click(button)
183184

184185
expect(mockPostMessage).toHaveBeenCalledWith({
@@ -197,7 +198,7 @@ describe('App', () => {
197198
pythonBinPath: 'python'
198199
})
199200

200-
const button = screen.getByText('Update Env')
201+
const button = screen.getByText('Set Env')
201202
fireEvent.click(button)
202203

203204
expect(mockPostMessage).toHaveBeenCalledWith({
@@ -223,6 +224,25 @@ describe('App', () => {
223224
})
224225
})
225226

227+
it('should let the user auto-install DVC but warn the user that their selected env is global when the Python extension is installed', () => {
228+
const defaultInterpreter = 'python'
229+
renderApp({
230+
cliCompatible: undefined,
231+
dvcCliDetails: {
232+
command: 'python -m dvc',
233+
version: undefined
234+
},
235+
isPythonEnvironmentGlobal: true,
236+
isPythonExtensionUsed: true,
237+
pythonBinPath: defaultInterpreter
238+
})
239+
240+
const button = screen.getByText('Set Env')
241+
242+
expect(button).toBeInTheDocument()
243+
expect(screen.getByText('Not a virtual environment)')).toBeInTheDocument()
244+
})
245+
226246
it('should not show a screen saying that DVC is not installed if the cli is available', () => {
227247
renderApp()
228248

@@ -354,14 +374,14 @@ describe('App', () => {
354374
expect(within(envDetails).getByText(command)).toBeInTheDocument()
355375
})
356376

357-
it('should show the user the command used to run DVC with a "Configure" button if dvc is installed without the python extension', () => {
377+
it('should show the user the command used to run DVC with a "Locate DVC" button if dvc is installed without the python extension', () => {
358378
renderApp()
359379

360380
const envDetails = screen.getByTestId('dvc-env-details')
361381

362382
expect(within(envDetails).getByText('Command:')).toBeInTheDocument()
363383

364-
const configureButton = within(envDetails).getByText('Configure')
384+
const configureButton = within(envDetails).getByText('Locate DVC')
365385
const selectButton = within(envDetails).queryByText(
366386
'Select Python Interpreter'
367387
)
@@ -376,7 +396,7 @@ describe('App', () => {
376396
})
377397
})
378398

379-
it('should show the user the command used to run DVC with "Configure" and "Update Env" buttons if dvc is installed with the python extension', () => {
399+
it('should show the user the command used to run DVC with "Locate DVC" and "Set Env" buttons if dvc is installed with the python extension', () => {
380400
renderApp({
381401
isPythonExtensionUsed: true
382402
})
@@ -385,8 +405,8 @@ describe('App', () => {
385405

386406
expect(within(envDetails).getByText('Command:')).toBeInTheDocument()
387407

388-
const configureButton = within(envDetails).getByText('Configure')
389-
const selectButton = within(envDetails).getByText('Update Env')
408+
const configureButton = within(envDetails).getByText('Locate DVC')
409+
const selectButton = within(envDetails).getByText('Set Env')
390410

391411
expect(configureButton).toBeInTheDocument()
392412
expect(selectButton).toBeInTheDocument()

webview/src/setup/components/App.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
updateCliCompatible,
2121
updateDvcCliDetails,
2222
updateIsAboveLatestTestedVersion,
23+
updateIsPythonEnvironmentGlobal,
2324
updateIsPythonExtensionUsed,
2425
updateNeedsGitInitialized,
2526
updateProjectInitialized,
@@ -82,6 +83,11 @@ export const feedStore = (
8283
case 'hasData':
8384
dispatch(updateExperimentsHasData(data.data.hasData))
8485
continue
86+
case 'isPythonEnvironmentGlobal':
87+
dispatch(
88+
updateIsPythonEnvironmentGlobal(data.data.isPythonEnvironmentGlobal)
89+
)
90+
continue
8591
case 'isPythonExtensionUsed':
8692
dispatch(updateIsPythonExtensionUsed(data.data.isPythonExtensionUsed))
8793
continue

webview/src/setup/components/dvc/CliUnavailable.tsx

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,47 @@ import {
99
setupWorkspace,
1010
updatePythonEnvironment
1111
} from '../../util/messages'
12+
import { Warning } from '../../../shared/components/icons'
1213

1314
export const CliUnavailable: React.FC<PropsWithChildren> = ({ children }) => {
14-
const { pythonBinPath, isPythonExtensionUsed } = useSelector(
15-
(state: SetupState) => state.dvc
16-
)
15+
const { pythonBinPath, isPythonExtensionUsed, isPythonEnvironmentGlobal } =
16+
useSelector((state: SetupState) => state.dvc)
1717
const canInstall = !!pythonBinPath
1818
const installationSentence = (
1919
<>
2020
The extension supports all{' '}
21-
<a href="https://dvc.org/doc/install">installation types</a>. It can also
22-
help to install needed packages via{' '}
23-
<a href="https://packaging.python.org/en/latest/key_projects/#pip">pip</a>
24-
.
21+
<a href="https://dvc.org/doc/install">installation types</a>.
2522
</>
2623
)
2724

2825
const conditionalContents = canInstall ? (
2926
<>
3027
<p>
31-
{installationSentence} DVC & DVCLive can be auto-installed with{' '}
32-
{pythonBinPath}.
28+
{installationSentence} Auto-install (pip) DVC & DVCLive with{' '}
29+
{pythonBinPath}{' '}
30+
{isPythonEnvironmentGlobal && (
31+
<>
32+
(<Warning className={styles.inlineWarningSvg} />{' '}
33+
<span>Not a virtual environment)</span>
34+
</>
35+
)}
36+
.
3337
</p>
3438
<div className={styles.sideBySideButtons}>
3539
<Button onClick={installDvc} text="Install (pip)" />
3640
{isPythonExtensionUsed && (
37-
<Button onClick={updatePythonEnvironment} text="Update Env" />
41+
<Button onClick={updatePythonEnvironment} text="Set Env" />
3842
)}
39-
<Button onClick={setupWorkspace} text="Configure" />
43+
<Button onClick={setupWorkspace} text="Locate DVC" />
4044
</div>
4145
</>
4246
) : (
4347
<>
4448
<p>
45-
{installationSentence} Unfortunately, DVC & DVCLive cannot be
46-
auto-installed as Python was not located.
49+
{installationSentence} DVC & DVCLive cannot be auto-installed as Python
50+
was not located.
4751
</p>
48-
<Button onClick={setupWorkspace} text="Configure" />
52+
<Button onClick={setupWorkspace} text="Locate DVC" />
4953
</>
5054
)
5155

webview/src/setup/components/dvc/DvcEnvCommandRow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const DvcEnvCommandRow: React.FC<DvcEnvCommandRowProps> = ({
2121
<span className={styles.command}>{commandText}</span>
2222
<span className={styles.actions}>
2323
<button className={styles.buttonAsLink} onClick={setupWorkspace}>
24-
Configure
24+
Locate DVC
2525
</button>
2626
{isPythonExtensionUsed && (
2727
<>
@@ -30,7 +30,7 @@ export const DvcEnvCommandRow: React.FC<DvcEnvCommandRowProps> = ({
3030
className={styles.buttonAsLink}
3131
onClick={updatePythonEnvironment}
3232
>
33-
Update Env
33+
Set Env
3434
</button>
3535
</>
3636
)}

webview/src/setup/components/dvc/styles.module.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232
}
3333
}
3434

35+
.inlineWarningSvg {
36+
vertical-align: middle;
37+
fill: $warn-color;
38+
width: 16px;
39+
height: 16px;
40+
}
41+
3542
.buttonAsLink {
3643
@extend %buttonAsLink;
3744

webview/src/setup/state/dvcSlice.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const dvcInitialState: DvcState = {
1515
cliCompatible: undefined,
1616
dvcCliDetails: undefined,
1717
isAboveLatestTestedVersion: undefined,
18+
isPythonEnvironmentGlobal: undefined,
1819
isPythonExtensionUsed: false,
1920
needsGitInitialized: false,
2021
projectInitialized: false,
@@ -47,6 +48,12 @@ export const dvcSlice = createSlice({
4748
) => {
4849
state.isAboveLatestTestedVersion = action.payload
4950
},
51+
updateIsPythonEnvironmentGlobal: (
52+
state,
53+
action: PayloadAction<boolean | undefined>
54+
) => {
55+
state.isPythonEnvironmentGlobal = action.payload
56+
},
5057
updateIsPythonExtensionUsed: (state, action: PayloadAction<boolean>) => {
5158
state.isPythonExtensionUsed = action.payload
5259
},
@@ -70,6 +77,7 @@ export const {
7077
updateCliCompatible,
7178
updateDvcCliDetails,
7279
updateIsAboveLatestTestedVersion,
80+
updateIsPythonEnvironmentGlobal,
7381
updateIsPythonExtensionUsed,
7482
updateNeedsGitInitialized,
7583
updateProjectInitialized,

webview/src/stories/Setup.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const DEFAULT_DATA: SetupData = {
1717
},
1818
hasData: false,
1919
isAboveLatestTestedVersion: false,
20+
isPythonEnvironmentGlobal: false,
2021
isPythonExtensionUsed: true,
2122
isStudioConnected: true,
2223
needsGitCommit: false,

0 commit comments

Comments
 (0)