PythonMutator: update instrumentation (#2124)

## Changes
Update instrumentation for PythonMutator to handle `experimental/python`
config.

## Tests
Unit tests
This commit is contained in:
Gleb Kanterov 2025-01-13 10:16:29 +01:00 committed by GitHub
parent d525ff67be
commit f8f804fe17
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 2 deletions

View File

@ -232,7 +232,11 @@ func setUserAgentExtraEnvVar(environ map[string]string, b *bundle.Bundle) error
// Terraform provider to the CLI. // Terraform provider to the CLI.
products := []string{"cli/" + build.GetInfo().Version} products := []string{"cli/" + build.GetInfo().Version}
if experimental := b.Config.Experimental; experimental != nil { 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") products = append(products, "databricks-pydabs/0.0.0")
} }
} }

View File

@ -248,7 +248,7 @@ func TestSetProxyEnvVars(t *testing.T) {
assert.ElementsMatch(t, []string{"HTTP_PROXY", "HTTPS_PROXY", "NO_PROXY"}, maps.Keys(env)) 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{ b := &bundle.Bundle{
BundleRootPath: t.TempDir(), BundleRootPath: t.TempDir(),
Config: config.Root{ Config: config.Root{
@ -268,6 +268,26 @@ func TestSetUserAgentExtraEnvVar(t *testing.T) {
}, env) }, 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) { func TestInheritEnvVars(t *testing.T) {
t.Setenv("HOME", "/home/testuser") t.Setenv("HOME", "/home/testuser")
t.Setenv("PATH", "/foo:/bar") t.Setenv("PATH", "/foo:/bar")