Skip to content

Add databricks labs command group - #914

Merged
nfx merged 8 commits into
mainfrom
feat/labs
Nov 17, 2023
Merged

Add databricks labs command group#914
nfx merged 8 commits into
mainfrom
feat/labs

Conversation

@nfx

@nfxnfx commented Oct 24, 2023

Copy link
Copy Markdown
Contributor

@nfx
nfx requested a review from pieternOctober 24, 2023 19:41
@nfx

nfx commented Oct 24, 2023

Copy link
Copy Markdown
ContributorAuthor

Downstream command router can be really trivial:

importloggingimportsys, jsonfromdatabricks.sdkimportWorkspaceClientfromdatabricks.labs.ucx.installimportWorkspaceInstallerdefjobs():
ws=WorkspaceClient()
installer=WorkspaceInstaller(ws)
forstep, job_idininstaller.deployed_steps().items():
print(step, job_id)
defme():
ws=WorkspaceClient()
my_user=ws.current_user.me()
print(my_user.user_name)
MAPPING= {
'jobs': jobs,
'me': me,
}
defmain(raw):
payload=json.loads(raw)
command=payload['command']
ifcommandnotinMAPPING:
raiseKeyError(f'cannot find command: {command}')
flags=payload['flags']
log_level=flags.pop('log_level')
iflog_level!='disabled':
databricks_logger=logging.getLogger("databricks")
databricks_logger.setLevel(log_level.upper())
kwargs= {k.replace('-', '_'): vfork,vinflags.items()}
MAPPING[command](**kwargs)
if__name__=="__main__":
main(*sys.argv[1:])

@nfx

nfx commented Oct 27, 2023

Copy link
Copy Markdown
ContributorAuthor

#927make snapshot in a separate PR

@nfx
nfx marked this pull request as ready for review October 27, 2023 10:47
Comment threadcmd/labs/list_test.go
Comment threadcmd/labs/installable/repositories.go Outdated
Comment threadcmd/labs/installable/repositories.go Outdated
Comment threadcmd/labs/localcache/jsonfile.go
Comment threadcmd/labs/localcache/jsonfile_test.go Outdated
Comment threadcmd/labs/project/project.go Outdated
Comment threadcmd/labs/project/project.go Outdated
Comment threadcmd/labs/project/project.go Outdated
Comment threadcmd/labs/localcache/jsonfile.go Outdated
Comment threadcmd/labs/releases/releases.go Outdated
github-merge-queueBot pushed a commit that referenced this pull request Nov 7, 2023
## Changes
This PR enables testing commands with stdin
## Tests
#914
@nfxnfx added the CLI CLI related issues label Nov 7, 2023
@nfx
nfx enabled auto-merge November 7, 2023 23:59
@nfx

nfx commented Nov 8, 2023

Copy link
Copy Markdown
ContributorAuthor

installing this branch

brew install golang
git@github.com:databricks/cli.git
cd cli
git checkout feat/labs
make snapshot

and the binary will be in .databricks/databricks file

github-merge-queueBot pushed a commit that referenced this pull request Nov 8, 2023
## Changes
`os.Getenv(..)` is not friendly with `libs/env`. This PR makes the
relevant changes to places where we need to read user home directory.
## Tests
Mainly done in #914
github-merge-queueBot pushed a commit that referenced this pull request Nov 9, 2023
)
## Changes
This PR makes unit testing with subprocesses fast.
```
ctx := context.Background()
ctx, stub := process.WithStub(ctx)
stub.WithDefaultOutput("meeee")
ctx = env.Set(ctx, "FOO", "bar")
out, err := process.Background(ctx, []string{"/usr/local/bin/meeecho", "1", "--foo", "bar"})
require.NoError(t, err)
require.Equal(t, "meeee", out)
require.Equal(t, 1, stub.Len())
require.Equal(t, []string{"meeecho 1 --foo bar"}, stub.Commands())
allEnv := stub.CombinedEnvironment()
require.Equal(t, "bar", allEnv["FOO"])
require.Equal(t, "bar", stub.LookupEnv("FOO"))
```
This should make further iterations of
#914 easier
## Tests
`make test`
github-merge-queueBot pushed a commit that referenced this pull request Nov 9, 2023
… flow by displaying cluster type and runtime version (#956)
This PR adds selectors for Databricks-connect compatible clusters and
SQL warehouses
Tested in #914
Serge Smertin added 2 commits November 9, 2023 18:20
..
Add folder
list installed works
stdin forwarding
fixed some tests
tests pass
fetching versions
added installer, still WIP
fixed tests for UNIX
added debug logging
..
installer tests
..
run on windows
xx
fixed
added uninstall
..
work on windows
..
..
work with more CUJs
pick up configuration when auth.json is not found
..
Added spinners
added cluster prompts
..
...
..
support for dbconnect lib install
..
..
..
fixed dev libDIr logic
starting tests for dev installs
+10% coverage
,,
..
..
..
@alexott

Copy link
Copy Markdown
Collaborator

Got error on the clean install

Error: save cache: open /Users/alexey.ott/.databricks/labs/databrickslabs-repositories.json: no such file or directory

@alexott

Copy link
Copy Markdown
Collaborator

Another bug

$ databricks labs sandbox ip-access-list-analyzer --profile=az-alexott
Error: cannot find Python 3.8. Please re-run: databricks labs install ip-access-list-analyzer

@alexott

Copy link
Copy Markdown
Collaborator
>databricks labs install . --debug
time=2023-11-10T11:12:49.984+01:00 level=INFO source="root.go 55}" msg=start pid=51984 version=0.0.0-dev+5819644739e8 args="databricks, labs, install, ., --debug"
Installing sandbox in development mode from /Users/.../work/samples/dbl-sandbox

Comment threadcmd/labs/clear_cache.go
Comment threadcmd/labs/github/github.go Outdated
Comment threadcmd/labs/github/releases.go
Comment threadcmd/labs/github/releases_test.go Outdated
Comment threadcmd/labs/labs.go Outdated
Comment threadcmd/labs/project/entrypoint.go
Comment threadcmd/labs/project/entrypoint.go
Comment threadcmd/labs/project/proxy.go
Comment threadcmd/labs/uninstall.go Outdated
@nfx
nfx requested a review from pieternNovember 17, 2023 09:56
@nfx

nfx commented Nov 17, 2023

Copy link
Copy Markdown
ContributorAuthor

#914 (comment) - fixed

these two are related to dev mode, that we'll fix by talking with dev - #914 (comment)#914 (comment)

@pietern

Copy link
Copy Markdown
Contributor

This change LGTM and acknowledge there will be follop-ups on the UX.

Would appreciate a second pair of eyes before a stamp.

// cleanup auth profile and config file location,
// so that we don't confuse SDKs
cfg.Profile = ""
cfg.ConfigFile = ""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These won't be cleared in the environment because they are zero. That means they are not returned from e.environmentFromConfig below and are not cleared for the subprocess, which could confuse downstream programs.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pietern the only case possible when we have --profile (DATABRICKS_CONFIG_PROFILE) is the local dev machine. Github actions (and likes) won't have the DATABRICKS_CONFIG_PROFILE / DATABRICKS_CONFIG_FILE envs set, but rather direct ones, like client ids or hosts. there are tests that verify this to work from github actions-like environments

@mgyuchtmgyucht left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pietern and I reviewed this together this afternoon and feel generally good about it. Let's get labs on the road!

@nfx
nfx added this pull request to the merge queueNov 17, 2023
@pietern
pietern removed this pull request from the merge queue due to a manual request Nov 17, 2023
@pietern

Copy link
Copy Markdown
Contributor

Removed from the merge queue if you want to take a look at the issue above.

@nfx

nfx commented Nov 17, 2023

Copy link
Copy Markdown
ContributorAuthor

@pietern that permutation of configuration flags is very unlikely to happen and has unit tests already. going ahead with the merge :)

@nfx
nfx added this pull request to the merge queueNov 17, 2023
Merged via the queue into main with commit 1b7558cNov 17, 2023
@nfx
nfx deleted the feat/labs branch November 17, 2023 12:52
pietern added a commit that referenced this pull request Nov 29, 2023
This release includes the new `databricks labs` command to install, manage, and run Databricks Labs projects.
CLI:
* Add `--debug` as shortcut for `--log-level debug` ([#964](#964)).
* Improved usability of `databricks auth login ... --configure-cluster` ([#956](#956)).
* Make `databricks configure` save only explicit fields ([#973](#973)).
* Add `databricks labs` command group ([#914](#914)).
* Tolerate missing .databrickscfg file during `databricks auth login` ([#1003](#1003)).
* Add `--configure-cluster` flag to configure command ([#1005](#1005)).
* Fix bug where the account or workspace client could be `nil` ([#1020](#1020)).
Bundles:
* Do not allow empty descriptions for bundle template inputs ([#967](#967)).
* Added support for top-level permissions ([#928](#928)).
* Allow jobs to be manually unpaused in development mode ([#885](#885)).
* Fix template initialization from current working directory ([#976](#976)).
* Add `--tag` and `--branch` options to bundle init command ([#975](#975)).
* Work around DLT issue with `$PYTHONPATH` not being set correctly ([#999](#999)).
* Enable `spark_jar_task` with local JAR libraries ([#993](#993)).
* Pass `USERPROFILE` environment variable to Terraform ([#1001](#1001)).
* Improve error message when path is not a bundle template ([#985](#985)).
* Correctly overwrite local state if remote state is newer ([#1008](#1008)).
* Add mlops-stacks to the default `databricks bundle init` prompt ([#988](#988)).
* Do not add wheel content hash in uploaded Python wheel path ([#1015](#1015)).
* Do not replace pipeline libraries if there are no matches for pattern ([#1021](#1021)).
Internal:
* Update CLI version in the VS Code extension during release ([#1014](#1014)).
API Changes:
* Changed `databricks functions create` command . New request type is .
* Changed `databricks metastores create` command with new required argument order.
* Removed `databricks metastores enable-optimization` command.
* Removed `databricks account o-auth-enrollment` command group.
* Removed `databricks apps delete` command.
* Removed `databricks apps get` command.
* Added `databricks apps delete-app` command.
* Added `databricks apps get-app` command.
* Added `databricks apps get-app-deployment-status` command.
* Added `databricks apps get-apps` command.
* Added `databricks apps get-events` command.
* Added `databricks account network-connectivity` command group.
OpenAPI commit 22f09783eb8a84d52026f856be3b2068f9498db3 (2023-11-23)
Dependency updates:
* Bump golang.org/x/term from 0.13.0 to 0.14.0 ([#981](#981)).
* Bump github.com/hashicorp/terraform-json from 0.17.1 to 0.18.0 ([#979](#979)).
* Bump golang.org/x/oauth2 from 0.13.0 to 0.14.0 ([#982](#982)).
* Bump github.com/databricks/databricks-sdk-go from 0.24.0 to 0.25.0 ([#980](#980)).
* Bump github.com/databricks/databricks-sdk-go from 0.25.0 to 0.26.0 ([#1019](#1019)).
@pieternpietern mentioned this pull request Nov 29, 2023
github-merge-queueBot pushed a commit that referenced this pull request Nov 29, 2023
This release includes the new `databricks labs` command to install,
manage, and run Databricks Labs projects.
CLI:
* Add `--debug` as shortcut for `--log-level debug`
([#964](#964)).
* Improved usability of `databricks auth login ... --configure-cluster`
([#956](#956)).
* Make `databricks configure` save only explicit fields
([#973](#973)).
* Add `databricks labs` command group
([#914](#914)).
* Tolerate missing .databrickscfg file during `databricks auth login`
([#1003](#1003)).
* Add `--configure-cluster` flag to configure command
([#1005](#1005)).
* Fix bug where the account or workspace client could be `nil`
([#1020](#1020)).
Bundles:
* Do not allow empty descriptions for bundle template inputs
([#967](#967)).
* Added support for top-level permissions
([#928](#928)).
* Allow jobs to be manually unpaused in development mode
([#885](#885)).
* Fix template initialization from current working directory
([#976](#976)).
* Add `--tag` and `--branch` options to bundle init command
([#975](#975)).
* Work around DLT issue with `$PYTHONPATH` not being set correctly
([#999](#999)).
* Enable `spark_jar_task` with local JAR libraries
([#993](#993)).
* Pass `USERPROFILE` environment variable to Terraform
([#1001](#1001)).
* Improve error message when path is not a bundle template
([#985](#985)).
* Correctly overwrite local state if remote state is newer
([#1008](#1008)).
* Add mlops-stacks to the default `databricks bundle init` prompt
([#988](#988)).
* Do not add wheel content hash in uploaded Python wheel path
([#1015](#1015)).
* Do not replace pipeline libraries if there are no matches for pattern
([#1021](#1021)).
Internal:
* Update CLI version in the VS Code extension during release
([#1014](#1014)).
API Changes:
* Changed `databricks functions create` command.
* Changed `databricks metastores create` command with new required
argument order.
* Removed `databricks metastores enable-optimization` command.
* Removed `databricks account o-auth-enrollment` command group.
* Removed `databricks apps delete` command.
* Removed `databricks apps get` command.
* Added `databricks apps delete-app` command.
* Added `databricks apps get-app` command.
* Added `databricks apps get-app-deployment-status` command.
* Added `databricks apps get-apps` command.
* Added `databricks apps get-events` command.
* Added `databricks account network-connectivity` command group.
OpenAPI commit 22f09783eb8a84d52026f856be3b2068f9498db3 (2023-11-23)
Dependency updates:
* Bump golang.org/x/term from 0.13.0 to 0.14.0
([#981](#981)).
* Bump github.com/hashicorp/terraform-json from 0.17.1 to 0.18.0
([#979](#979)).
* Bump golang.org/x/oauth2 from 0.13.0 to 0.14.0
([#982](#982)).
* Bump github.com/databricks/databricks-sdk-go from 0.24.0 to 0.25.0
([#980](#980)).
* Bump github.com/databricks/databricks-sdk-go from 0.25.0 to 0.26.0
([#1019](#1019)).
denik pushed a commit that referenced this pull request May 20, 2026
## Changes
This PR enables testing commands with stdin
## Tests
#914
denik pushed a commit that referenced this pull request May 20, 2026
## Changes
`os.Getenv(..)` is not friendly with `libs/env`. This PR makes the
relevant changes to places where we need to read user home directory.
## Tests
Mainly done in #914
denik pushed a commit that referenced this pull request May 20, 2026
)
## Changes
This PR makes unit testing with subprocesses fast.
```
ctx := context.Background()
ctx, stub := process.WithStub(ctx)
stub.WithDefaultOutput("meeee")
ctx = env.Set(ctx, "FOO", "bar")
out, err := process.Background(ctx, []string{"/usr/local/bin/meeecho", "1", "--foo", "bar"})
require.NoError(t, err)
require.Equal(t, "meeee", out)
require.Equal(t, 1, stub.Len())
require.Equal(t, []string{"meeecho 1 --foo bar"}, stub.Commands())
allEnv := stub.CombinedEnvironment()
require.Equal(t, "bar", allEnv["FOO"])
require.Equal(t, "bar", stub.LookupEnv("FOO"))
```
This should make further iterations of
#914 easier
## Tests
`make test`
denik pushed a commit that referenced this pull request May 20, 2026
… flow by displaying cluster type and runtime version (#956)
This PR adds selectors for Databricks-connect compatible clusters and
SQL warehouses
Tested in #914
denik pushed a commit that referenced this pull request May 20, 2026
This release includes the new `databricks labs` command to install,
manage, and run Databricks Labs projects.
CLI:
* Add `--debug` as shortcut for `--log-level debug`
([#964](#964)).
* Improved usability of `databricks auth login ... --configure-cluster`
([#956](#956)).
* Make `databricks configure` save only explicit fields
([#973](#973)).
* Add `databricks labs` command group
([#914](#914)).
* Tolerate missing .databrickscfg file during `databricks auth login`
([#1003](#1003)).
* Add `--configure-cluster` flag to configure command
([#1005](#1005)).
* Fix bug where the account or workspace client could be `nil`
([#1020](#1020)).
Bundles:
* Do not allow empty descriptions for bundle template inputs
([#967](#967)).
* Added support for top-level permissions
([#928](#928)).
* Allow jobs to be manually unpaused in development mode
([#885](#885)).
* Fix template initialization from current working directory
([#976](#976)).
* Add `--tag` and `--branch` options to bundle init command
([#975](#975)).
* Work around DLT issue with `$PYTHONPATH` not being set correctly
([#999](#999)).
* Enable `spark_jar_task` with local JAR libraries
([#993](#993)).
* Pass `USERPROFILE` environment variable to Terraform
([#1001](#1001)).
* Improve error message when path is not a bundle template
([#985](#985)).
* Correctly overwrite local state if remote state is newer
([#1008](#1008)).
* Add mlops-stacks to the default `databricks bundle init` prompt
([#988](#988)).
* Do not add wheel content hash in uploaded Python wheel path
([#1015](#1015)).
* Do not replace pipeline libraries if there are no matches for pattern
([#1021](#1021)).
Internal:
* Update CLI version in the VS Code extension during release
([#1014](#1014)).
API Changes:
* Changed `databricks functions create` command.
* Changed `databricks metastores create` command with new required
argument order.
* Removed `databricks metastores enable-optimization` command.
* Removed `databricks account o-auth-enrollment` command group.
* Removed `databricks apps delete` command.
* Removed `databricks apps get` command.
* Added `databricks apps delete-app` command.
* Added `databricks apps get-app` command.
* Added `databricks apps get-app-deployment-status` command.
* Added `databricks apps get-apps` command.
* Added `databricks apps get-events` command.
* Added `databricks account network-connectivity` command group.
OpenAPI commit 22f09783eb8a84d52026f856be3b2068f9498db3 (2023-11-23)
Dependency updates:
* Bump golang.org/x/term from 0.13.0 to 0.14.0
([#981](#981)).
* Bump github.com/hashicorp/terraform-json from 0.17.1 to 0.18.0
([#979](#979)).
* Bump golang.org/x/oauth2 from 0.13.0 to 0.14.0
([#982](#982)).
* Bump github.com/databricks/databricks-sdk-go from 0.24.0 to 0.25.0
([#980](#980)).
* Bump github.com/databricks/databricks-sdk-go from 0.25.0 to 0.26.0
([#1019](#1019)).
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLICLI related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@nfx@alexott@pietern@mgyucht