Skip to content

Commit ab65627

Browse files
authored
Improve venv python version messages (#1501)
## 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? -->
1 parent 60215b6 commit ab65627

File tree

2 files changed

+57
-25
lines changed

2 files changed

+57
-25
lines changed

packages/databricks-vscode/src/configuration/LoginWizard.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ export class LoginWizard {
283283
type: "error",
284284
};
285285
}
286+
if (value.includes(".")) {
287+
return {
288+
message: "Profile name cannot contain dots",
289+
type: "error",
290+
};
291+
}
286292
if (profiles.find((profile) => profile.name === value)) {
287293
return {
288294
message: `Profile ${value} already exists`,

packages/databricks-vscode/src/language/EnvironmentDependenciesVerifier.ts

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -153,55 +153,81 @@ export class EnvironmentDependenciesVerifier extends MultiStepAccessVerifier {
153153
return env.version.major === major && env.version.minor === minor;
154154
}
155155

156-
private printEnvironment(env?: ResolvedEnvironment): string {
156+
private getCurrentPythonVersionMessage(env?: ResolvedEnvironment): string {
157157
return env?.version && env.environment
158158
? `Current version is ${env.version.major}.${env.version.minor}.${env.version.micro}.`
159159
: "No active environments found.";
160160
}
161161

162+
private getExpectedPythonVersionMessage(dbrVersionParts: (number | "x")[]) {
163+
if (dbrVersionParts[0] === 13 || dbrVersionParts[0] === 14) {
164+
return "3.10";
165+
}
166+
if (dbrVersionParts[0] === 15) {
167+
return "3.11";
168+
}
169+
if (dbrVersionParts[0] === 16) {
170+
return "3.12";
171+
}
172+
if (dbrVersionParts[0] !== "x" && dbrVersionParts[0] > 16) {
173+
return "3.12 or greater";
174+
}
175+
return "3.10 or greater";
176+
}
177+
178+
private getVersionMismatchWarning(
179+
dbrMajor: "x" | number,
180+
env: ResolvedEnvironment,
181+
currentPythonVersionMessage: string
182+
): string | undefined {
183+
if (
184+
(dbrMajor === 13 || dbrMajor === 14) &&
185+
!this.matchEnvironmentVersion(env, 3, 10)
186+
) {
187+
return `Use python 3.10 to match DBR ${dbrMajor} requirements. ${currentPythonVersionMessage}`;
188+
}
189+
if (dbrMajor === 15 && !this.matchEnvironmentVersion(env, 3, 11)) {
190+
return `Use python 3.11 to match DBR ${dbrMajor} requirements. ${currentPythonVersionMessage}`;
191+
}
192+
if (dbrMajor === 16 && !this.matchEnvironmentVersion(env, 3, 12)) {
193+
return `Use python 3.12 to match DBR ${dbrMajor} requirements. ${currentPythonVersionMessage}`;
194+
}
195+
return undefined;
196+
}
197+
162198
async checkPythonEnvironment(): Promise<FeatureStepState> {
199+
const dbrVersionParts =
200+
this.connectionManager.cluster?.dbrVersion || [];
201+
const expectedPythonVersion =
202+
this.getExpectedPythonVersionMessage(dbrVersionParts);
163203
const env = await this.pythonExtension.pythonEnvironment;
164204
const envVersionTooLow =
165205
env?.version && (env.version.major !== 3 || env.version.minor < 10);
166206
const noEnvironment = !env?.environment;
207+
const currentPythonVersionMessage =
208+
this.getCurrentPythonVersionMessage(env);
167209
if (noEnvironment || envVersionTooLow) {
168210
return this.rejectStep(
169211
"checkPythonEnvironment",
170-
"Activate an environment with Python >= 3.10",
171-
`Databricks Connect requires python >= 3.10. ${this.printEnvironment(
172-
env
173-
)}`,
212+
`Activate an environment with Python ${expectedPythonVersion}`,
213+
`Databricks Connect requires ${expectedPythonVersion}. ${currentPythonVersionMessage}`,
174214
this.selectPythonInterpreter.bind(this)
175215
);
176216
}
177217
const executable = await this.pythonExtension.getPythonExecutable();
178218
if (!executable) {
179219
return this.rejectStep(
180220
"checkPythonEnvironment",
181-
"Activate an environment with Python >= 3.10",
221+
`Activate an environment with Python ${expectedPythonVersion}`,
182222
"No python executable found",
183223
this.selectPythonInterpreter.bind(this)
184224
);
185225
}
186-
const dbrVersionParts =
187-
this.connectionManager.cluster?.dbrVersion || [];
188-
let warning;
189-
if (
190-
(dbrVersionParts[0] === 13 || dbrVersionParts[0] === 14) &&
191-
!this.matchEnvironmentVersion(env, 3, 10)
192-
) {
193-
warning = `Use python 3.10 to match DBR ${
194-
dbrVersionParts[0]
195-
} requirements. ${this.printEnvironment(env)}`;
196-
}
197-
if (
198-
dbrVersionParts[0] === 15 &&
199-
!this.matchEnvironmentVersion(env, 3, 11)
200-
) {
201-
warning = `Use python 3.11 to match DBR ${
202-
dbrVersionParts[0]
203-
} requirements. ${this.printEnvironment(env)}`;
204-
}
226+
const warning = this.getVersionMismatchWarning(
227+
dbrVersionParts[0],
228+
env,
229+
currentPythonVersionMessage
230+
);
205231
return this.acceptStep(
206232
"checkPythonEnvironment",
207233
`Active Environment: ${env.environment.name}`,

0 commit comments

Comments
 (0)