-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move all dbconnect run options to Databricks Run Icon (#1066)
## Changes * The run icon has new options to run the current python file and debug it. * The run and debug options run with a bootstrap script (`dbconnect_bootstrap.py`) that * Sets up the env vars by recursing up the file tree and searching for .databricks.env * Sets up the Databricks globals ## Tests <!-- How is this tested? -->
- Loading branch information
1 parent
bb63006
commit c28620a
Showing
16 changed files
with
600 additions
and
391 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,5 @@ scripts/** | |
coverage/ | ||
.nyc_output/ | ||
logs/ | ||
extension/ | ||
extension/ | ||
**/*.vsix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/databricks-vscode/resources/dark/databricks-run-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions
18
packages/databricks-vscode/resources/light/databricks-run-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions
61
packages/databricks-vscode/resources/python/dbconnect-bootstrap.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import os | ||
|
||
# Load environment variables from .databricks/.databricks.env | ||
# We only look for the folder in the current working directory | ||
# since for all commands laucnhed from | ||
def load_env_file_from_cwd(path: str): | ||
if not os.path.isdir(path): | ||
return | ||
|
||
env_file_path = os.path.join(path, ".databricks", ".databricks.env") | ||
if not os.path.exists(os.path.dirname(env_file_path)): | ||
return | ||
|
||
with open(env_file_path, "r") as f: | ||
for line in f.readlines(): | ||
key, value = line.strip().split("=", 1) | ||
os.environ[key] = value | ||
return | ||
|
||
load_env_file_from_cwd(os.getcwd()) | ||
|
||
log_level = os.environ.get("DATABRICKS_VSCODE_LOG_LEVEL") | ||
log_level = log_level if log_level is not None else "WARN" | ||
|
||
import logging | ||
logging.basicConfig(level=log_level) | ||
|
||
db_globals = {} | ||
|
||
from databricks.sdk.runtime import dbutils | ||
db_globals['dbutils'] = dbutils | ||
|
||
# "table", "sc", "sqlContext" are missing | ||
try: | ||
from pyspark.sql import functions as udf, SparkSession | ||
from databricks.connect import DatabricksSession | ||
spark: SparkSession = DatabricksSession.builder.getOrCreate() | ||
sql = spark.sql | ||
db_globals['spark'] = spark | ||
db_globals['sql'] = sql | ||
db_globals['udf'] = udf | ||
except Exception as e: | ||
logging.debug(f"Failed to create DatabricksSession: {e}") | ||
|
||
# We do this to prevent importing widgets implementation prematurely | ||
# The widget import should prompt users to use the implementation | ||
# which has ipywidget support. | ||
def getArgument(*args, **kwargs): | ||
return dbutils.widgets.getArgument(*args, **kwargs) | ||
|
||
db_globals['getArgument'] = getArgument | ||
|
||
from runpy import run_path | ||
import sys | ||
|
||
script = sys.argv[1] | ||
sys.argv = sys.argv[1:] | ||
logging.debug(f"Running ${script}") | ||
logging.debug(f"args: ${sys.argv[1:]}") | ||
|
||
run_path(script, init_globals=db_globals, run_name="__main__") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.