Fixed incorrectly cleaning up python wheel dist folder (#1656)

## Changes
In https://github.com/databricks/cli/pull/1618 we introduced prepare
step in which Python wheel folder was cleaned. Now it was cleaned
everytime instead of only when there is a build command how it is used
to work.

This PR fixes it by only cleaning up dist folder when there is a build
command for wheels.

Fixes #1638 

## Tests
Added regression test
This commit is contained in:
Andrew Nester 2024-08-06 11:54:58 +02:00 committed by GitHub
parent 809c67b675
commit d26f3f4863
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 37 additions and 0 deletions

View File

@ -32,6 +32,11 @@ func (m *prepare) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics
return diag.Errorf("artifact doesn't exist: %s", m.name)
}
// If there is no build command for the artifact, we don't need to cleanup the dist folder before
if artifact.BuildCommand == "" {
return nil
}
dir := artifact.Path
distPath := filepath.Join(dir, "dist")

View File

@ -0,0 +1,3 @@
build/
*.egg-info
.databricks

View File

@ -0,0 +1,16 @@
bundle:
name: python-wheel
resources:
jobs:
test_job:
name: "[${bundle.environment}] My Wheel Job"
tasks:
- task_key: TestTask
existing_cluster_id: "0717-132531-5opeqon1"
python_wheel_task:
package_name: "my_test_code"
entry_point: "run"
libraries:
- whl: ./dist/*.whl
- whl: ./dist/lib/my_test_code-0.0.1-py3-none-any.whl

View File

@ -130,3 +130,16 @@ func TestPythonWheelBuildMultiple(t *testing.T) {
diags = bundle.Apply(ctx, b, match)
require.NoError(t, diags.Error())
}
func TestPythonWheelNoBuild(t *testing.T) {
ctx := context.Background()
b, err := bundle.Load(ctx, "./python_wheel/python_wheel_no_build")
require.NoError(t, err)
diags := bundle.Apply(ctx, b, bundle.Seq(phases.Load(), phases.Build()))
require.NoError(t, diags.Error())
match := libraries.ValidateLocalLibrariesExist()
diags = bundle.Apply(ctx, b, match)
require.NoError(t, diags.Error())
}