Skip to content

Commit 47a5100

Browse files
native exclude for binary files in the temp diff
1 parent 9b69e7d commit 47a5100

3 files changed

Lines changed: 5 additions & 11 deletions

File tree

codeflash/code_utils/git_utils.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import os
4-
import re
54
import shutil
65
import subprocess
76
import sys
@@ -220,14 +219,9 @@ def create_detached_worktree(module_root: Path) -> Optional[Path]:
220219

221220
# Get uncommitted diff from the original repo
222221
repository.git.add("-N", ".") # add the index for untracked files to be included in the diff
223-
uni_diff_text = repository.git.diff(None, "HEAD", ignore_blank_lines=True, ignore_space_at_eol=True)
224-
225-
# HACK: remove binary files from the diff, find a better way # noqa: FIX004
226-
uni_diff_text = re.sub(
227-
r"^diff --git a\/.*?\.(?:pyc|class|jar|exe|dll|so|dylib|o|obj|bin|pdf|jpg|jpeg|png|gif|zip|tar|gz) b\/.*?\.\w+.*?\n(?:.*?\n)*?(?=diff --git|\Z)",
228-
"",
229-
uni_diff_text,
230-
flags=re.MULTILINE,
222+
exclude_binary_files = [":!*.pyc", ":!*.pyo", ":!*.pyd", ":!*.so", ":!*.dll", ":!*.whl", ":!*.egg", ":!*.egg-info", ":!*.pyz", ":!*.pkl", ":!*.pickle", ":!*.joblib", ":!*.npy", ":!*.npz", ":!*.h5", ":!*.hdf5", ":!*.pth", ":!*.pt", ":!*.pb", ":!*.onnx", ":!*.db", ":!*.sqlite", ":!*.sqlite3", ":!*.feather", ":!*.parquet", ":!*.jpg", ":!*.jpeg", ":!*.png", ":!*.gif", ":!*.bmp", ":!*.tiff", ":!*.webp", ":!*.wav", ":!*.mp3", ":!*.ogg", ":!*.flac", ":!*.mp4", ":!*.avi", ":!*.mov", ":!*.mkv", ":!*.pdf", ":!*.doc", ":!*.docx", ":!*.xls", ":!*.xlsx", ":!*.ppt", ":!*.pptx", ":!*.zip", ":!*.rar", ":!*.tar", ":!*.tar.gz", ":!*.tgz", ":!*.bz2", ":!*.xz"] # fmt: off
223+
uni_diff_text = repository.git.diff(
224+
None, "HEAD", "--", *exclude_binary_files, ignore_blank_lines=True, ignore_space_at_eol=True
231225
)
232226

233227
if not uni_diff_text.strip():

codeflash/lsp/beta.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ def initialize_function_optimization(
9494
_initialize_optimizer_if_api_key_is_valid(server)
9595

9696
server.optimizer.worktree_mode()
97-
# make sure the tests dir is created in the worktree, this can happen if the original tests dir is empty
98-
Path(server.optimizer.args.tests_root).mkdir(parents=True, exist_ok=True)
9997

10098
original_args, _ = server.optimizer.original_args_and_test_cfg
10199

codeflash/optimization/optimizer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,8 @@ def worktree_mode(self) -> None:
440440
return
441441
self.current_worktree = worktree_dir
442442
self.mutate_args_for_worktree_mode(worktree_dir)
443+
# make sure the tests dir is created in the worktree, this can happen if the original tests dir is empty
444+
Path(self.args.tests_root).mkdir(parents=True, exist_ok=True)
443445

444446
def mutate_args_for_worktree_mode(self, worktree_dir: Path) -> None:
445447
saved_args = copy.deepcopy(self.args)

0 commit comments

Comments
 (0)