Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nextchanges/air/7744.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* `air run` now warns about missing PyTorch when a pinned snapshot's `include_paths` selects a Python file. ([#7744](https://github.com/databricks/cli/pull/7744))
6 changes: 6 additions & 0 deletions cmd/air/torchcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ func findTorchImportAtCommit(ctx context.Context, g gitRepo, plan snapshotPlan)
for _, b := range bases {
args = append(args, ":(top,glob)"+path.Join(b, "**", "*.py"))
}
for _, p := range plan.includePaths {
if strings.HasSuffix(p, ".py") {
file := path.Join(plan.subtreePrefix, filepath.ToSlash(p))
args = append(args, ":(top,literal)"+file)
}
}
out, err := g.run(ctx, args...)
if err != nil {
// git grep exits 1 when nothing matches.
Expand Down
19 changes: 19 additions & 0 deletions cmd/air/torchcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,23 @@ func TestMissingTorchWarningScansPinnedCommit(t *testing.T) {

assert.Contains(t, missingTorchWarning(t.Context(), cfg, filepath.Join(dir, "run.yaml")), "Warning: model/train.py contains a torch import")
})

t.Run("single file include", func(t *testing.T) {
repo := newTestRepo(t)
writeRepoFile(t, repo, "train.py", "import torch\n")
sha := commitAll(t, repo, "torch")
cfg := writeTorchRunConfig(t, repo, " git:\n commit: "+sha+"\n include_paths:\n - train.py\n")

assert.Contains(t, missingTorchWarning(t.Context(), cfg, filepath.Join(repo, "run.yaml")), "Warning: train.py contains a torch import")
})

t.Run("single file include excludes other imports", func(t *testing.T) {
repo := newTestRepo(t)
writeRepoFile(t, repo, "train.py", "print('hi')\n")
writeRepoFile(t, repo, "other.py", "import torch\n")
sha := commitAll(t, repo, "torch outside include")
cfg := writeTorchRunConfig(t, repo, " git:\n commit: "+sha+"\n include_paths:\n - train.py\n")

assert.Empty(t, missingTorchWarning(t.Context(), cfg, filepath.Join(repo, "run.yaml")))
})
}
Loading