From c71cac9e37d546deb4cbd9c635ca42cc261f046e Mon Sep 17 00:00:00 2001 From: Caroline Chen <324939130+caroline-db@users.noreply.github.com> Date: Tue, 17 Nov 2026 22:38:20 +0000 Subject: [PATCH 1/2] air: detect Torch imports in pinned file includes --- cmd/air/torchcheck.go | 6 ++++++ cmd/air/torchcheck_test.go | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/cmd/air/torchcheck.go b/cmd/air/torchcheck.go index 81bd78c4a94..5d69b84b03b 100644 --- a/cmd/air/torchcheck.go +++ b/cmd/air/torchcheck.go @@ -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. diff --git a/cmd/air/torchcheck_test.go b/cmd/air/torchcheck_test.go index 76e1ef803d9..5d5613f3362 100644 --- a/cmd/air/torchcheck_test.go +++ b/cmd/air/torchcheck_test.go @@ -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"))) + }) } From 4b14534063954f0b9143b370304c49fe85e74b80 Mon Sep 17 00:00:00 2001 From: Caroline Chen <324939130+caroline-db@users.noreply.github.com> Date: Tue, 17 Nov 2026 22:44:32 +0000 Subject: [PATCH 2/2] changelog: add entry for PR 7744 --- .nextchanges/air/7744.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 .nextchanges/air/7744.md diff --git a/.nextchanges/air/7744.md b/.nextchanges/air/7744.md new file mode 100644 index 00000000000..11ec2b7ae0d --- /dev/null +++ b/.nextchanges/air/7744.md @@ -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))