-
Notifications
You must be signed in to change notification settings - Fork 29
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
Simplify DVC CLI Location/Version Logic #3784
Changes from 8 commits
6c950c1
8ff17c4
e9e9e77
1a3ed8c
7b177c4
4b1f4a7
857aa4c
4350616
42d1c11
b1ec992
b7dcf84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,4 @@ | ||
import { | ||
LATEST_TESTED_CLI_VERSION, | ||
MAX_CLI_VERSION, | ||
MIN_CLI_VERSION | ||
} from './contract' | ||
import { LATEST_TESTED_CLI_VERSION } from './contract' | ||
import { CliCompatible, isVersionCompatible } from './version' | ||
import { IExtensionSetup } from '../../interfaces' | ||
import { Toast } from '../../vscode/toast' | ||
|
@@ -12,90 +8,82 @@ import { | |
getConfigValue, | ||
setUserConfigValue | ||
} from '../../vscode/config' | ||
import { getPythonBinPath } from '../../extensions/python' | ||
import { getFirstWorkspaceFolder } from '../../vscode/workspaceFolders' | ||
import { delay } from '../../util/time' | ||
import { SetupSection } from '../../setup/webview/contract' | ||
|
||
export const warnUnableToVerifyVersion = () => | ||
Toast.warnWithOptions( | ||
const warnWithSetupAction = async ( | ||
setup: IExtensionSetup, | ||
warningText: string | ||
): Promise<void> => { | ||
const response = await Toast.warnWithOptions(warningText, Response.SHOW_SETUP) | ||
|
||
if (response === Response.SHOW_SETUP) { | ||
return setup.showSetup(SetupSection.DVC) | ||
} | ||
} | ||
|
||
const warnUnableToVerifyVersion = (setup: IExtensionSetup) => { | ||
void warnWithSetupAction( | ||
setup, | ||
'The extension cannot initialize as we were unable to verify the DVC CLI version.' | ||
) | ||
} | ||
|
||
export const warnVersionIncompatible = ( | ||
version: string, | ||
const warnVersionIncompatible = ( | ||
setup: IExtensionSetup, | ||
update: 'CLI' | 'extension' | ||
): void => { | ||
void Toast.warnWithOptions( | ||
`The extension cannot initialize because you are using version ${version} of the DVC CLI. The expected version is ${MIN_CLI_VERSION} <= DVC < ${MAX_CLI_VERSION}. Please upgrade to the most recent version of the ${update} and reload this window.` | ||
void warnWithSetupAction( | ||
setup, | ||
`The extension cannot initialize because you are using the wrong version of the ${update}.` | ||
julieg18 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
} | ||
|
||
export const warnAheadOfLatestTested = (): void => { | ||
const warnAheadOfLatestTested = (): void => { | ||
void Toast.warnWithOptions( | ||
`The located DVC CLI is at least a minor version ahead of the latest version the extension was tested with (${LATEST_TESTED_CLI_VERSION}). This could lead to unexpected behaviour. Please upgrade to the most recent version of the extension and reload this window.` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Left this toast alone for now since we don't have any info on the latest tested cli version in Setup yet. Once we update our DVC Setup page (task is in #3434 list), we can simplify this one or remove entirely. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's aim to remove it |
||
) | ||
} | ||
|
||
const warnUserCLIInaccessible = async ( | ||
setup: IExtensionSetup, | ||
warningText: string | ||
setup: IExtensionSetup | ||
): Promise<void> => { | ||
if (getConfigValue<boolean>(ConfigKey.DO_NOT_SHOW_CLI_UNAVAILABLE)) { | ||
return | ||
} | ||
|
||
const response = await Toast.warnWithOptions( | ||
warningText, | ||
'An error was thrown when trying to access the CLI.', | ||
Response.SHOW_SETUP, | ||
Response.NEVER | ||
) | ||
|
||
switch (response) { | ||
case Response.SHOW_SETUP: | ||
return setup.showSetup(SetupSection.EXPERIMENTS) | ||
return setup.showSetup(SetupSection.DVC) | ||
case Response.NEVER: | ||
return setUserConfigValue(ConfigKey.DO_NOT_SHOW_CLI_UNAVAILABLE, true) | ||
} | ||
} | ||
|
||
const warnUserCLIInaccessibleAnywhere = async ( | ||
setup: IExtensionSetup, | ||
globalDvcVersion: string | undefined | ||
): Promise<void> => { | ||
const binPath = await getPythonBinPath() | ||
|
||
return warnUserCLIInaccessible( | ||
setup, | ||
`The extension is unable to initialize. The CLI was not located using the interpreter provided by the Python extension. ${ | ||
globalDvcVersion ? globalDvcVersion + ' is' : 'The CLI is also not' | ||
} installed globally. For auto Python environment activation, ensure the correct interpreter is set. Active Python interpreter: ${ | ||
binPath || 'unset' | ||
}.` | ||
) | ||
} | ||
|
||
const warnUser = ( | ||
setup: IExtensionSetup, | ||
cliCompatible: CliCompatible, | ||
version: string | undefined | ||
cliCompatible: CliCompatible | ||
): void => { | ||
if (!setup.shouldWarnUserIfCLIUnavailable()) { | ||
return | ||
} | ||
switch (cliCompatible) { | ||
case CliCompatible.NO_BEHIND_MIN_VERSION: | ||
return warnVersionIncompatible(version as string, 'CLI') | ||
return warnVersionIncompatible(setup, 'CLI') | ||
case CliCompatible.NO_CANNOT_VERIFY: | ||
void warnUnableToVerifyVersion() | ||
void warnUnableToVerifyVersion(setup) | ||
return | ||
case CliCompatible.NO_MAJOR_VERSION_AHEAD: | ||
return warnVersionIncompatible(version as string, 'extension') | ||
return warnVersionIncompatible(setup, 'extension') | ||
case CliCompatible.NO_NOT_FOUND: | ||
void warnUserCLIInaccessible( | ||
setup, | ||
'An error was thrown when trying to access the CLI.' | ||
) | ||
void warnUserCLIInaccessible(setup) | ||
return | ||
case CliCompatible.YES_MINOR_VERSION_AHEAD_OF_TESTED: | ||
return warnAheadOfLatestTested() | ||
|
@@ -128,7 +116,6 @@ const getVersionDetails = async ( | |
): Promise< | ||
CanRunCli & { | ||
cliCompatible: CliCompatible | ||
version: string | undefined | ||
} | ||
> => { | ||
const version = await setup.getCliVersion(cwd, tryGlobalCli) | ||
|
@@ -140,11 +127,12 @@ const getVersionDetails = async ( | |
const processVersionDetails = ( | ||
setup: IExtensionSetup, | ||
cliCompatible: CliCompatible, | ||
version: string | undefined, | ||
isAvailable: boolean, | ||
isCompatible: boolean | undefined | ||
isCompatible: boolean | undefined, | ||
version: string | undefined | ||
): CanRunCli => { | ||
warnUser(setup, cliCompatible, version) | ||
warnUser(setup, cliCompatible) | ||
|
||
return { | ||
isAvailable, | ||
isCompatible, | ||
|
@@ -159,21 +147,17 @@ const tryGlobalFallbackVersion = async ( | |
const tryGlobal = await getVersionDetails(setup, cwd, true) | ||
const { cliCompatible, isAvailable, isCompatible, version } = tryGlobal | ||
|
||
if (setup.shouldWarnUserIfCLIUnavailable() && !isCompatible) { | ||
void warnUserCLIInaccessibleAnywhere(setup, version) | ||
} | ||
if ( | ||
setup.shouldWarnUserIfCLIUnavailable() && | ||
cliCompatible === CliCompatible.YES_MINOR_VERSION_AHEAD_OF_TESTED | ||
) { | ||
warnAheadOfLatestTested() | ||
} | ||
|
||
if (isCompatible) { | ||
setup.unsetPythonBinPath() | ||
} | ||
|
||
return { isAvailable, isCompatible, version } | ||
return processVersionDetails( | ||
setup, | ||
cliCompatible, | ||
isAvailable, | ||
isCompatible, | ||
version | ||
) | ||
} | ||
|
||
const extensionCanAutoRunCli = async ( | ||
|
@@ -190,12 +174,13 @@ const extensionCanAutoRunCli = async ( | |
if (pythonCliCompatible === CliCompatible.NO_NOT_FOUND) { | ||
return tryGlobalFallbackVersion(setup, cwd) | ||
} | ||
|
||
return processVersionDetails( | ||
setup, | ||
pythonCliCompatible, | ||
pythonVersion, | ||
pythonVersionIsAvailable, | ||
pythonVersionIsCompatible | ||
pythonVersionIsCompatible, | ||
pythonVersion | ||
) | ||
} | ||
|
||
|
@@ -213,9 +198,9 @@ export const extensionCanRunCli = async ( | |
return processVersionDetails( | ||
setup, | ||
cliCompatible, | ||
version, | ||
isAvailable, | ||
isCompatible | ||
isCompatible, | ||
version | ||
) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current possible options are:
Version not found:
An error was thrown when trying to access the CLI.
buttons: Setup, Don't Show Again
Version can not be verified:
The extension cannot initialize as we were unable to verify the DVC CLI version.
Button: Setup
Version is found but it's not up to date:
The extension cannot initialize because you are using the wrong version of the CLI
Buttons: Setup
Version is found but it's too far ahead:
The extension cannot initialize because you are using the wrong version of the extension.
Button: Setup
What do we think? Should the toasts be more/less simplified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated Toasts:
Version not found:
An error was thrown when trying to access the CLI.
buttons: Setup, Don't Show Again
Version can not be verified:
The extension cannot initialize as we were unable to verify the DVC CLI version.
Button: Setup
Version behind or ahead
The extension cannot initialize because the DVC CLI version is incompatible.
Button: Setup