From d26f3f4863bfe7b4532a31a67f33863226529045 Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Tue, 6 Aug 2024 11:54:58 +0200 Subject: [PATCH] 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 --- bundle/artifacts/whl/prepare.go | 5 +++++ .../python_wheel_no_build/.gitignore | 3 +++ .../python_wheel_no_build/bundle.yml | 16 ++++++++++++++++ .../lib/my_test_code-0.0.1-py3-none-any.whl | Bin 0 -> 1832 bytes .../dist/my_test_code-0.0.1-py3-none-any.whl | Bin 0 -> 1832 bytes bundle/tests/python_wheel_test.go | 13 +++++++++++++ 6 files changed, 37 insertions(+) create mode 100644 bundle/tests/python_wheel/python_wheel_no_build/.gitignore create mode 100644 bundle/tests/python_wheel/python_wheel_no_build/bundle.yml create mode 100644 bundle/tests/python_wheel/python_wheel_no_build/dist/lib/my_test_code-0.0.1-py3-none-any.whl create mode 100644 bundle/tests/python_wheel/python_wheel_no_build/dist/my_test_code-0.0.1-py3-none-any.whl diff --git a/bundle/artifacts/whl/prepare.go b/bundle/artifacts/whl/prepare.go index 7284b11e..0fbb2080 100644 --- a/bundle/artifacts/whl/prepare.go +++ b/bundle/artifacts/whl/prepare.go @@ -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") diff --git a/bundle/tests/python_wheel/python_wheel_no_build/.gitignore b/bundle/tests/python_wheel/python_wheel_no_build/.gitignore new file mode 100644 index 00000000..f03e23bc --- /dev/null +++ b/bundle/tests/python_wheel/python_wheel_no_build/.gitignore @@ -0,0 +1,3 @@ +build/ +*.egg-info +.databricks diff --git a/bundle/tests/python_wheel/python_wheel_no_build/bundle.yml b/bundle/tests/python_wheel/python_wheel_no_build/bundle.yml new file mode 100644 index 00000000..91b8b155 --- /dev/null +++ b/bundle/tests/python_wheel/python_wheel_no_build/bundle.yml @@ -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 diff --git a/bundle/tests/python_wheel/python_wheel_no_build/dist/lib/my_test_code-0.0.1-py3-none-any.whl b/bundle/tests/python_wheel/python_wheel_no_build/dist/lib/my_test_code-0.0.1-py3-none-any.whl new file mode 100644 index 0000000000000000000000000000000000000000..4bb80477caf51393354453b18c0c88711098825e GIT binary patch literal 1832 zcmWIWW@Zs#U|`^2xLh&ryk0?NcfY>3uGYCT z=ezsEH-rWlT`<029P+5E-(N@fdGY9=0ryhVJ$tvvUNQc+{d3{D zn|B2?ro>EK#LF7E*yLqccPAsi^Am}D%e30AoeArVlYJ((&Chx9t8w97&hq5+iY(pM z?WKI0`Ng-xP8DwL5?S^qs;1iP{ao7%o!XY-3yZ&e5Ut|$zxe;x^oV^&AD++Fd7iem zR(X?DP}|ALQzYCuG|lZak1|#q*u;_lsY}J+e|O){(NT&M^DqET*~S;Ni)SUsN4C z9Dn1{?j=1*vsGR>2Ap1Urdi@ME2@w3r*1Nd0r~`ll?eGL+{4w?hx@#T@7asIkTkJ5 z$l!|cgChU4-nw2oC-pZ4d3c@F(d*P_Um1A8;DWK?CF2WExK5qdzxY+>8n1?~*V&Uk zn}RenwS1p)dHQS*(pX_~?d<9E-dBCktbX!{2`Tk}Lc4^`-&YapE?q)yOU)}Os*Eql z&&(?+)+?zf>Gsnum6bPz^n=Yu)|leb1cf?%&Q77=vb)*4}*!*?@Mi z0I?P!yGrs4;&W2VQgc8SY3q4CLw9*{w)FQ{Mg|65CI$v&LZ$_|I{OE?w4OU%)MUWm zaB=T_A&mrw*ph>*mAaB@F8Q(@M!#{WU5W^A%QRiSMW z{ozJ=^Fq0UM|XJ53fr~pZf|;Euh=Z{Z-Tx4a;F>EwmRNScHD8mvs7)8lJ+L8`I_QF zshMAec0^w`-2TiwZ^_?(T*a4Um+uz%9hJHAo6n-@<%iYQ%+*hCy{@^uvZID|#pH|s ze;h2ndvtru#jke9t4>^Ne8ji;gOB{FCkgtet-sDum^X=S@}n%?$yyAP)vvd7E<0Z8 zI`hG%7f1XLTdv`o%)7mde~0q)?pa+LTXvaz|5|P@sQzMo+2)nERD@WZf7CmNnCf|W zcinFk%sFDWcj{{;(KVwNY7ngq3`-iL;hNz^9I|F?B?v;ZHZZ*qRi2<5iJpZK zM*byaBsfE(n}?q55a!JUCTF}(M9+liMx*C4gwd?b1dK+>bLi%x=Qo(STN;B2nG4B% V0p6^j+|R%cgo;34egu^R3;+-1eXjrj literal 0 HcmV?d00001 diff --git a/bundle/tests/python_wheel/python_wheel_no_build/dist/my_test_code-0.0.1-py3-none-any.whl b/bundle/tests/python_wheel/python_wheel_no_build/dist/my_test_code-0.0.1-py3-none-any.whl new file mode 100644 index 0000000000000000000000000000000000000000..4bb80477caf51393354453b18c0c88711098825e GIT binary patch literal 1832 zcmWIWW@Zs#U|`^2xLh&ryk0?NcfY>3uGYCT z=ezsEH-rWlT`<029P+5E-(N@fdGY9=0ryhVJ$tvvUNQc+{d3{D zn|B2?ro>EK#LF7E*yLqccPAsi^Am}D%e30AoeArVlYJ((&Chx9t8w97&hq5+iY(pM z?WKI0`Ng-xP8DwL5?S^qs;1iP{ao7%o!XY-3yZ&e5Ut|$zxe;x^oV^&AD++Fd7iem zR(X?DP}|ALQzYCuG|lZak1|#q*u;_lsY}J+e|O){(NT&M^DqET*~S;Ni)SUsN4C z9Dn1{?j=1*vsGR>2Ap1Urdi@ME2@w3r*1Nd0r~`ll?eGL+{4w?hx@#T@7asIkTkJ5 z$l!|cgChU4-nw2oC-pZ4d3c@F(d*P_Um1A8;DWK?CF2WExK5qdzxY+>8n1?~*V&Uk zn}RenwS1p)dHQS*(pX_~?d<9E-dBCktbX!{2`Tk}Lc4^`-&YapE?q)yOU)}Os*Eql z&&(?+)+?zf>Gsnum6bPz^n=Yu)|leb1cf?%&Q77=vb)*4}*!*?@Mi z0I?P!yGrs4;&W2VQgc8SY3q4CLw9*{w)FQ{Mg|65CI$v&LZ$_|I{OE?w4OU%)MUWm zaB=T_A&mrw*ph>*mAaB@F8Q(@M!#{WU5W^A%QRiSMW z{ozJ=^Fq0UM|XJ53fr~pZf|;Euh=Z{Z-Tx4a;F>EwmRNScHD8mvs7)8lJ+L8`I_QF zshMAec0^w`-2TiwZ^_?(T*a4Um+uz%9hJHAo6n-@<%iYQ%+*hCy{@^uvZID|#pH|s ze;h2ndvtru#jke9t4>^Ne8ji;gOB{FCkgtet-sDum^X=S@}n%?$yyAP)vvd7E<0Z8 zI`hG%7f1XLTdv`o%)7mde~0q)?pa+LTXvaz|5|P@sQzMo+2)nERD@WZf7CmNnCf|W zcinFk%sFDWcj{{;(KVwNY7ngq3`-iL;hNz^9I|F?B?v;ZHZZ*qRi2<5iJpZK zM*byaBsfE(n}?q55a!JUCTF}(M9+liMx*C4gwd?b1dK+>bLi%x=Qo(STN;B2nG4B% V0p6^j+|R%cgo;34egu^R3;+-1eXjrj literal 0 HcmV?d00001 diff --git a/bundle/tests/python_wheel_test.go b/bundle/tests/python_wheel_test.go index 53c6764e..05e4fdfa 100644 --- a/bundle/tests/python_wheel_test.go +++ b/bundle/tests/python_wheel_test.go @@ -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()) +}