Skip to content

Commit

Permalink
Wait for config to be ready before accessing values (#3799)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon authored May 2, 2023
1 parent c8916ee commit 695719e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
7 changes: 4 additions & 3 deletions extension/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ export class Config extends DeferredDisposable {
}

public async setPythonBinPath() {
this.pythonBinPath = await this.getConfigOrExtensionPythonBinPath()
return this.deferred.resolve()
const pythonBinPath = await this.getConfigOrExtensionPythonBinPath()
this.pythonBinPath = pythonBinPath
this.deferred.resolve()
}

public async setPythonAndNotifyIfChanged() {
const oldPath = this.pythonBinPath
this.pythonBinPath = await this.getConfigOrExtensionPythonBinPath()
await this.setPythonBinPath()
this.notifyIfChanged(oldPath, this.pythonBinPath)
}

Expand Down
20 changes: 8 additions & 12 deletions extension/src/setup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ export class Setup
return this.sendDataToWebview()
}

public getDvcCliDetails(): DvcCliDetails {
private async getDvcCliDetails(): Promise<DvcCliDetails> {
await this.config.isReady()
const dvcPath = this.config.getCliPath()
const pythonBinPath = this.config.getPythonBinPath()
const cwd = getFirstWorkspaceFolder()
Expand All @@ -389,18 +390,14 @@ export class Setup
}
}

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 [isPythonExtensionUsed, dvcCliDetails] = await Promise.all([
this.isPythonExtensionUsed(),
this.getDvcCliDetails()
])

const needsGitInitialized =
!projectInitialized && !!(await this.needsGitInit())
Expand All @@ -415,10 +412,9 @@ export class Setup
this.webviewMessages.sendWebviewMessage({
canGitInitialize,
cliCompatible: this.getCliCompatible(),
dvcCliDetails: this.getDvcCliDetails(),
dvcCliDetails,
hasData,
isPythonExtensionUsed:
!this.isDVCBeingUsedGlobally() && isPythonExtensionUsed,
isPythonExtensionUsed,
isStudioConnected: this.studioIsConnected,
needsGitCommit,
needsGitInitialized,
Expand Down
2 changes: 1 addition & 1 deletion extension/src/test/suite/setup/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ suite('Setup Test Suite', () => {
mockExecuteCommand.restore()
mockRunSetup.restore()
stub(config, 'isPythonExtensionUsed').returns(false)
stub(config, 'getPythonBinPath').resolves(join('python'))
stub(config, 'getPythonBinPath').returns(join('python'))

mockVersion.resetBehavior()
mockVersion
Expand Down

0 comments on commit 695719e

Please sign in to comment.