From 4cb93457f2ba4caaab68f11e6a54ebd4083ce8b8 Mon Sep 17 00:00:00 2001 From: Kartik Gupta <88345179+kartikgupta-db@users.noreply.github.com> Date: Tue, 30 Jan 2024 15:14:55 +0100 Subject: [PATCH] Search for both databricks.exe and databricks binaries in windows (#517) ## Changes ## Tests - [x] `make test` run locally - [x] `make fmt` applied - [ ] relevant integration tests applied --- databricks/sdk/credentials_provider.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/databricks/sdk/credentials_provider.py b/databricks/sdk/credentials_provider.py index 2c30ea143..9714e8bc6 100644 --- a/databricks/sdk/credentials_provider.py +++ b/databricks/sdk/credentials_provider.py @@ -6,6 +6,7 @@ import logging import os import pathlib +import platform import subprocess import sys from datetime import datetime @@ -473,11 +474,21 @@ def __init__(self, cfg: 'Config'): args += ['--account-id', cfg.account_id] cli_path = cfg.databricks_cli_path + + # If the path is not specified look for "databricks" / "databricks.exe" in PATH. if not cli_path: - cli_path = 'databricks' + try: + # Try to find "databricks" in PATH + cli_path = self.__class__._find_executable("databricks") + except FileNotFoundError as e: + # If "databricks" is not found, try to find "databricks.exe" in PATH (Windows) + if platform.system() == "Windows": + cli_path = self.__class__._find_executable("databricks.exe") + else: + raise e # If the path is unqualified, look it up in PATH. - if cli_path.count("/") == 0: + elif cli_path.count("/") == 0: cli_path = self.__class__._find_executable(cli_path) super().__init__(cmd=[cli_path, *args],