Skip to content

Commit

Permalink
Housekeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
julieg18 committed Jun 14, 2023
1 parent 2d7c1e9 commit 1c84713
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 40 deletions.
2 changes: 1 addition & 1 deletion extension/src/extensions/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface Settings {
}
}

type EnvironmentVariables = { readonly [key: string]: undefined }
type EnvironmentVariables = { readonly [key: string]: string | undefined }
type EnvironmentVariablesChangeEvent = {
readonly env: EnvironmentVariables
}
Expand Down
96 changes: 57 additions & 39 deletions extension/src/setup/autoInstall.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Progress } from 'vscode'
import {
getPythonExecutionDetails,
isActivePythonEnvGlobal
Expand All @@ -21,6 +22,37 @@ export const findPythonBinForInstall = async (): Promise<

const getProcessGlobalArgs = (isGlobal: boolean) => (isGlobal ? ['--user'] : [])

const installPackageAndIncrementProgress = ({
root,
pythonBinPath,
isGlobalEnv,
progress,
incrementAmount,
packageName,
successMessage
}: {
root: string
pythonBinPath: string
isGlobalEnv: boolean
progress: Progress<{ message: string; amount: number }>
incrementAmount: number
packageName: string
successMessage: string
}) =>
Toast.runCommandAndIncrementProgress(
async () => {
await installPackages(
root,
pythonBinPath,
...getProcessGlobalArgs(isGlobalEnv),
packageName
)
return successMessage
},
progress,
incrementAmount
)

const showUpgradeProgress = (
root: string,
pythonBinPath: string,
Expand All @@ -32,22 +64,16 @@ const showUpgradeProgress = (
progress.report({ increment: 25, message: 'Updating packages...' })

try {
await Toast.runCommandAndIncrementProgress(
async () => {
await installPackages(
root,
pythonBinPath,
...getProcessGlobalArgs(isGlobalEnv),
'dvc'
)
return 'Upgraded successfully'
},
await installPackageAndIncrementProgress({
incrementAmount: 75,
isGlobalEnv,
packageName: 'dvc',
progress,
75
)

return Toast.delayProgressClosing()
} catch (error: unknown) {
pythonBinPath,
root,
successMessage: 'Upgraded successfully'
})
} catch (error) {
return Toast.reportProgressError(error, progress)
}
})
Expand All @@ -61,37 +87,29 @@ const showInstallProgress = (
progress.report({ increment: 0 })

try {
await Toast.runCommandAndIncrementProgress(
async () => {
await installPackages(
root,
pythonBinPath,
...getProcessGlobalArgs(isGlobalEnv),
'dvclive'
)
return 'DVCLive Installed'
},
await installPackageAndIncrementProgress({
incrementAmount: 25,
isGlobalEnv,
packageName: 'dvclive',
progress,
25
)
pythonBinPath,
root,
successMessage: 'DVCLive Installed'
})
} catch (error: unknown) {
return Toast.reportProgressError(error, progress)
}

try {
await Toast.runCommandAndIncrementProgress(
async () => {
await installPackages(
root,
pythonBinPath,
...getProcessGlobalArgs(isGlobalEnv),
'dvc'
)
return 'DVC Installed'
},
await installPackageAndIncrementProgress({
incrementAmount: 75,
isGlobalEnv,
packageName: 'dvc',
progress,
75
)
pythonBinPath,
root,
successMessage: 'DVC Installed'
})

return Toast.delayProgressClosing()
} catch (error: unknown) {
Expand Down

0 comments on commit 1c84713

Please sign in to comment.