Skip to content

Commit

Permalink
Rearrange imports in databricks.sdk.runtime to improve local editor…
Browse files Browse the repository at this point in the history
… experience (#219)

## Changes
<!-- Summary of your changes that are easy to understand -->

The type hinting here means that VSCode does not give useful syntax
highlights / code completions.

This is the current experience on `main`:
<img width="428" alt="image"
src="https://github.com/databricks/databricks-sdk-py/assets/17158624/72d2c3eb-cc3a-4f95-9f09-7d43a8f2815e">
<img width="428" alt="image"
src="https://github.com/databricks/databricks-sdk-py/assets/17158624/34b04de0-5996-4a2e-a0d2-b26a8c9d3da9">

With these changes this becomes:
<img width="428" alt="image"
src="https://github.com/databricks/databricks-sdk-py/assets/17158624/99a91d82-f06a-4883-b131-7f96a82edd80">
<img width="818" alt="image"
src="https://github.com/databricks/databricks-sdk-py/assets/17158624/ce684fd0-f550-4afe-bc46-1187b6dd4b49">
 

## Tests
<!-- 
How is this tested? Please see the checklist below and also describe any
other relevant tests
-->

- [x] `make test` run locally
- [x] `make fmt` applied
- [ ] relevant integration tests applied
  • Loading branch information
judahrand authored Jul 17, 2023
1 parent 7350f21 commit 6f93548
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions databricks/sdk/runtime/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

is_local_implementation = True

# All objects that are injected into the Notebook's user namespace should also be made
Expand Down Expand Up @@ -31,15 +33,22 @@
_globals[var] = userNamespaceGlobals[var]
is_local_implementation = False
except ImportError:
from typing import Type, cast

# OSS implementation
is_local_implementation = True

try:
from . import stub
from .stub import *
dbutils_type = Type[stub.dbutils]
except (ImportError, NameError):
from databricks.sdk.dbutils import RemoteDbUtils

# this assumes that all environment variables are set
dbutils = RemoteDbUtils()
dbutils_type = RemoteDbUtils

dbutils = cast(dbutils_type, dbutils)

__all__ = ['dbutils'] if is_local_implementation else dbruntime_objects

0 comments on commit 6f93548

Please sign in to comment.