Skip to content

Commit

Permalink
PythonMutator: update instrumentation (#2124)
Browse files Browse the repository at this point in the history
## Changes
Update instrumentation for PythonMutator to handle `experimental/python`
config.

## Tests
Unit tests
  • Loading branch information
kanterov authored Jan 13, 2025
1 parent d525ff6 commit f8f804f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
6 changes: 5 additions & 1 deletion bundle/deploy/terraform/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,11 @@ func setUserAgentExtraEnvVar(environ map[string]string, b *bundle.Bundle) error
// Terraform provider to the CLI.
products := []string{"cli/" + build.GetInfo().Version}
if experimental := b.Config.Experimental; experimental != nil {
if experimental.PyDABs.Enabled {
hasPython := experimental.Python.Resources != nil || experimental.Python.Mutators != nil

if hasPython {
products = append(products, "databricks-pydabs/0.7.0")
} else if experimental.PyDABs.Enabled {
products = append(products, "databricks-pydabs/0.0.0")
}
}
Expand Down
22 changes: 21 additions & 1 deletion bundle/deploy/terraform/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func TestSetProxyEnvVars(t *testing.T) {
assert.ElementsMatch(t, []string{"HTTP_PROXY", "HTTPS_PROXY", "NO_PROXY"}, maps.Keys(env))
}

func TestSetUserAgentExtraEnvVar(t *testing.T) {
func TestSetUserAgentExtraEnvVar_PyDABs(t *testing.T) {
b := &bundle.Bundle{
BundleRootPath: t.TempDir(),
Config: config.Root{
Expand All @@ -268,6 +268,26 @@ func TestSetUserAgentExtraEnvVar(t *testing.T) {
}, env)
}

func TestSetUserAgentExtraEnvVar_Python(t *testing.T) {
b := &bundle.Bundle{
BundleRootPath: t.TempDir(),
Config: config.Root{
Experimental: &config.Experimental{
Python: config.Python{
Resources: []string{"my_project.resources:load_resources"},
},
},
},
}

env := make(map[string]string, 0)
err := setUserAgentExtraEnvVar(env, b)
require.NoError(t, err)
assert.Equal(t, map[string]string{
"DATABRICKS_USER_AGENT_EXTRA": "cli/0.0.0-dev databricks-pydabs/0.7.0",
}, env)
}

func TestInheritEnvVars(t *testing.T) {
t.Setenv("HOME", "/home/testuser")
t.Setenv("PATH", "/foo:/bar")
Expand Down

0 comments on commit f8f804f

Please sign in to comment.