-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow referencing local Python wheels without artifacts section defin…
…ed (#703) ## Changes Now if the user reference local Python wheel files and do not specify "artifacts" section, this file will be automatically uploaded by CLI. Fixes #693 ## Tests Added unit tests Ran bundle deploy for this configuration ``` resources: jobs: some_other_job: name: "[${bundle.environment}] My Wheel Job" tasks: - task_key: TestTask existing_cluster_id: ${var.job_existing_cluster} python_wheel_task: package_name: "my_test_code" entry_point: "run" libraries: - whl: ./dist/*.whl ``` Result ``` andrew.nester@HFW9Y94129 wheel % databricks bundle deploy artifacts.whl.AutoDetect: Detecting Python wheel project... artifacts.whl.AutoDetect: No Python wheel project found at bundle root folder Starting upload of bundle files Uploaded bundle files at /Users/andrew.nester@databricks.com/.bundle/wheel-task/default/files! artifacts.Upload(my_test_code-0.0.1-py3-none-any.whl): Uploading... artifacts.Upload(my_test_code-0.0.1-py3-none-any.whl): Upload succeeded ```
- Loading branch information
1 parent
35350b4
commit b071ad7
Showing
7 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package whl | ||
|
||
import ( | ||
"context" | ||
"path/filepath" | ||
|
||
"github.com/databricks/cli/bundle" | ||
"github.com/databricks/cli/bundle/config" | ||
"github.com/databricks/cli/bundle/libraries" | ||
"github.com/databricks/cli/libs/log" | ||
) | ||
|
||
type fromLibraries struct{} | ||
|
||
func DefineArtifactsFromLibraries() bundle.Mutator { | ||
return &fromLibraries{} | ||
} | ||
|
||
func (m *fromLibraries) Name() string { | ||
return "artifacts.whl.DefineArtifactsFromLibraries" | ||
} | ||
|
||
func (*fromLibraries) Apply(ctx context.Context, b *bundle.Bundle) error { | ||
if len(b.Config.Artifacts) != 0 { | ||
log.Debugf(ctx, "Skipping defining artifacts from libraries because artifacts section is explicitly defined") | ||
return nil | ||
} | ||
|
||
tasks := libraries.FindAllWheelTasks(b) | ||
for _, task := range tasks { | ||
for _, lib := range task.Libraries { | ||
matches, err := filepath.Glob(filepath.Join(b.Config.Path, lib.Whl)) | ||
// File referenced from libraries section does not exists, skipping | ||
if err != nil { | ||
continue | ||
} | ||
|
||
for _, match := range matches { | ||
name := filepath.Base(match) | ||
if b.Config.Artifacts == nil { | ||
b.Config.Artifacts = make(map[string]*config.Artifact) | ||
} | ||
|
||
log.Debugf(ctx, "Adding an artifact block for %s", match) | ||
b.Config.Artifacts[name] = &config.Artifact{ | ||
Files: []config.ArtifactFile{ | ||
{Source: match}, | ||
}, | ||
Type: config.ArtifactPythonWheel, | ||
} | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} |
3 changes: 3 additions & 0 deletions
3
bundle/tests/bundle/python_wheel_no_artifact_no_setup/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
build/ | ||
*.egg-info | ||
.databricks |
22 changes: 22 additions & 0 deletions
22
bundle/tests/bundle/python_wheel_no_artifact_no_setup/bundle.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
bundle: | ||
name: python-wheel-local | ||
|
||
resources: | ||
jobs: | ||
test_job: | ||
name: "[${bundle.environment}] My Wheel Job" | ||
tasks: | ||
- task_key: TestTask | ||
existing_cluster_id: "0717-aaaaa-bbbbbb" | ||
python_wheel_task: | ||
package_name: "my_test_code" | ||
entry_point: "run" | ||
libraries: | ||
- whl: ./package/*.whl | ||
- task_key: TestTask2 | ||
existing_cluster_id: "0717-aaaaa-bbbbbb" | ||
python_wheel_task: | ||
package_name: "my_test_code" | ||
entry_point: "run" | ||
libraries: | ||
- whl: ./non-existing/*.whl |
Binary file added
BIN
+1.86 KB
...ests/bundle/python_wheel_no_artifact_no_setup/package/my_test_code-0.0.1-py3-none-any.whl
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters