Skip to content

Commit

Permalink
Improve venv python version messages (#1501)
Browse files Browse the repository at this point in the history
## Changes
Add 3.12 version message for newly released DBR 16 

(unrelated) Prohibit dots in profile names created from the extension.
Our ini lib thinks that the dot indicates a subsection and escapes it,
creating a profile under a technically different name

## Tests
<!-- How is this tested? -->
  • Loading branch information
ilia-db authored Dec 24, 2024
1 parent 60215b6 commit ab65627
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 25 deletions.
6 changes: 6 additions & 0 deletions packages/databricks-vscode/src/configuration/LoginWizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ export class LoginWizard {
type: "error",
};
}
if (value.includes(".")) {
return {
message: "Profile name cannot contain dots",
type: "error",
};
}
if (profiles.find((profile) => profile.name === value)) {
return {
message: `Profile ${value} already exists`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,55 +153,81 @@ export class EnvironmentDependenciesVerifier extends MultiStepAccessVerifier {
return env.version.major === major && env.version.minor === minor;
}

private printEnvironment(env?: ResolvedEnvironment): string {
private getCurrentPythonVersionMessage(env?: ResolvedEnvironment): string {
return env?.version && env.environment
? `Current version is ${env.version.major}.${env.version.minor}.${env.version.micro}.`
: "No active environments found.";
}

private getExpectedPythonVersionMessage(dbrVersionParts: (number | "x")[]) {
if (dbrVersionParts[0] === 13 || dbrVersionParts[0] === 14) {
return "3.10";
}
if (dbrVersionParts[0] === 15) {
return "3.11";
}
if (dbrVersionParts[0] === 16) {
return "3.12";
}
if (dbrVersionParts[0] !== "x" && dbrVersionParts[0] > 16) {
return "3.12 or greater";
}
return "3.10 or greater";
}

private getVersionMismatchWarning(
dbrMajor: "x" | number,
env: ResolvedEnvironment,
currentPythonVersionMessage: string
): string | undefined {
if (
(dbrMajor === 13 || dbrMajor === 14) &&
!this.matchEnvironmentVersion(env, 3, 10)
) {
return `Use python 3.10 to match DBR ${dbrMajor} requirements. ${currentPythonVersionMessage}`;
}
if (dbrMajor === 15 && !this.matchEnvironmentVersion(env, 3, 11)) {
return `Use python 3.11 to match DBR ${dbrMajor} requirements. ${currentPythonVersionMessage}`;
}
if (dbrMajor === 16 && !this.matchEnvironmentVersion(env, 3, 12)) {
return `Use python 3.12 to match DBR ${dbrMajor} requirements. ${currentPythonVersionMessage}`;
}
return undefined;
}

async checkPythonEnvironment(): Promise<FeatureStepState> {
const dbrVersionParts =
this.connectionManager.cluster?.dbrVersion || [];
const expectedPythonVersion =
this.getExpectedPythonVersionMessage(dbrVersionParts);
const env = await this.pythonExtension.pythonEnvironment;
const envVersionTooLow =
env?.version && (env.version.major !== 3 || env.version.minor < 10);
const noEnvironment = !env?.environment;
const currentPythonVersionMessage =
this.getCurrentPythonVersionMessage(env);
if (noEnvironment || envVersionTooLow) {
return this.rejectStep(
"checkPythonEnvironment",
"Activate an environment with Python >= 3.10",
`Databricks Connect requires python >= 3.10. ${this.printEnvironment(
env
)}`,
`Activate an environment with Python ${expectedPythonVersion}`,
`Databricks Connect requires ${expectedPythonVersion}. ${currentPythonVersionMessage}`,
this.selectPythonInterpreter.bind(this)
);
}
const executable = await this.pythonExtension.getPythonExecutable();
if (!executable) {
return this.rejectStep(
"checkPythonEnvironment",
"Activate an environment with Python >= 3.10",
`Activate an environment with Python ${expectedPythonVersion}`,
"No python executable found",
this.selectPythonInterpreter.bind(this)
);
}
const dbrVersionParts =
this.connectionManager.cluster?.dbrVersion || [];
let warning;
if (
(dbrVersionParts[0] === 13 || dbrVersionParts[0] === 14) &&
!this.matchEnvironmentVersion(env, 3, 10)
) {
warning = `Use python 3.10 to match DBR ${
dbrVersionParts[0]
} requirements. ${this.printEnvironment(env)}`;
}
if (
dbrVersionParts[0] === 15 &&
!this.matchEnvironmentVersion(env, 3, 11)
) {
warning = `Use python 3.11 to match DBR ${
dbrVersionParts[0]
} requirements. ${this.printEnvironment(env)}`;
}
const warning = this.getVersionMismatchWarning(
dbrVersionParts[0],
env,
currentPythonVersionMessage
);
return this.acceptStep(
"checkPythonEnvironment",
`Active Environment: ${env.environment.name}`,
Expand Down

0 comments on commit ab65627

Please sign in to comment.