Skip to content

Commit 2128013

Browse files
Add currently selected python environment to path for wheel builds (#1159)
## Changes * Deploying jobs with wheels fails because we are not propagating the selected virtual env to bundle commands. * This PR fixes that by adding the path to virtual environment python binary to `PATH` env var for bundle deploy. ## Tests <!-- How is this tested? --> --------- Co-authored-by: Ilia Babanov <ilia.babanov@databricks.com>
1 parent 3780ec4 commit 2128013

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

packages/databricks-vscode/src/bundle/models/BundleRemoteStateModel.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import lodash from "lodash";
99
import {WorkspaceConfigs} from "../../vscode-objs/WorkspaceConfigs";
1010
import {logging} from "@databricks/databricks-sdk";
1111
import {Loggers} from "../../logger";
12+
import {MsPythonExtensionWrapper} from "../../language/MsPythonExtensionWrapper";
1213

1314
/* eslint-disable @typescript-eslint/naming-convention */
1415
export type BundleResourceModifiedStatus = "created" | "deleted" | "updated";
@@ -49,6 +50,7 @@ export class BundleRemoteStateModel extends BaseModelWithStateCache<BundleRemote
4950
constructor(
5051
private readonly cli: CliWrapper,
5152
private readonly workspaceFolder: Uri,
53+
private readonly pythonExtension: MsPythonExtensionWrapper,
5254
private readonly workspaceConfigs: WorkspaceConfigs
5355
) {
5456
super();
@@ -72,6 +74,7 @@ export class BundleRemoteStateModel extends BaseModelWithStateCache<BundleRemote
7274
this.target,
7375
this.authProvider,
7476
this.workspaceFolder,
77+
this.pythonExtension,
7578
this.workspaceConfigs.databrickscfgLocation,
7679
this.logger
7780
);

packages/databricks-vscode/src/cli/CliWrapper.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import {EnvVarGenerators, FileUtils, UrlUtils} from "../utils";
1616
import {AuthProvider} from "../configuration/auth/AuthProvider";
1717
import {removeUndefinedKeys} from "../utils/envVarGenerators";
1818
import {quote} from "shell-quote";
19+
import {MsPythonExtensionWrapper} from "../language/MsPythonExtensionWrapper";
20+
import path from "path";
1921

2022
const withLogContext = logging.withLogContext;
2123
const execFile = promisify(execFileCb);
@@ -388,6 +390,7 @@ export class CliWrapper {
388390
target: string,
389391
authProvider: AuthProvider,
390392
workspaceFolder: Uri,
393+
pythonExtension: MsPythonExtensionWrapper,
391394
configfilePath?: string,
392395
logger?: logging.NamedLogger
393396
) {
@@ -406,15 +409,26 @@ export class CliWrapper {
406409
bundleOpName: "deploy",
407410
});
408411

412+
// Add python executable to PATH
413+
const executable = await pythonExtension.getPythonExecutable();
414+
const cliEnvVars = EnvVarGenerators.getEnvVarsForCli(configfilePath);
415+
let shellPath = cliEnvVars.PATH;
416+
if (executable) {
417+
shellPath = `${path.dirname(executable)}${
418+
path.delimiter
419+
}${shellPath}`;
420+
}
409421
const p = spawn(cmd[0], cmd.slice(1), {
410422
cwd: workspaceFolder.fsPath,
411423
env: {
412-
...EnvVarGenerators.getEnvVarsForCli(configfilePath),
424+
...cliEnvVars,
413425
...EnvVarGenerators.getProxyEnvVars(),
414426
...authProvider.toEnv(),
415427
...this.getLogginEnvVars(),
416-
// eslint-disable-next-line @typescript-eslint/naming-convention
428+
/* eslint-disable @typescript-eslint/naming-convention */
429+
PATH: shellPath,
417430
DATABRICKS_CLUSTER_ID: this.clusterId,
431+
/* eslint-enable @typescript-eslint/naming-convention */
418432
},
419433
shell: true,
420434
});

packages/databricks-vscode/src/extension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ export async function activate(
232232
const bundleRemoteStateModel = new BundleRemoteStateModel(
233233
cli,
234234
workspaceUri,
235+
pythonExtensionWrapper,
235236
workspaceConfigs
236237
);
237238
const configModel = new ConfigModel(

0 commit comments

Comments
 (0)