mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-16 09:22:22 +00:00
Merge c3f3c0a189 into 4a4c9cf7e3
This commit is contained in:
commit
c9f5504f51
2 changed files with 48 additions and 10 deletions
18
Makefile
18
Makefile
|
|
@ -147,14 +147,15 @@ lint-install:
|
|||
$(UV_RUN) python scripts/prisma_generate_if_needed.py
|
||||
|
||||
# Diff-scoped format check, mirroring test-linting.yml's "Check ruff format" step:
|
||||
# only the litellm Python files changed vs the base are checked, so a pre-existing
|
||||
# only the litellm Python files changed vs the base and still on disk are checked, so a pre-existing
|
||||
# format issue elsewhere doesn't block an unrelated commit. Git pathspecs match
|
||||
# recursively, so 'litellm/*.py' covers top-level files and nested modules alike,
|
||||
# the same set CI's ':(glob)litellm/**/*.py' selects.
|
||||
lint-format-check-changed: $(LINT_DEP_INSTALL) $(LINT_DEP_BASE)
|
||||
@base_ref=$$($(RESOLVE_BASE)) && \
|
||||
changed=$$(git diff --name-only --diff-filter=ACMR "$$base_ref...HEAD" -- 'litellm/*.py') && \
|
||||
files=$$(printf '%s\n' "$$changed" | grep -v '^litellm/enterprise/' || true) || exit $$?; \
|
||||
files=$$(printf '%s\n' "$$changed" | grep -v '^litellm/enterprise/' | \
|
||||
while IFS= read -r f; do if [ -f "$$f" ]; then printf '%s\n' "$$f"; fi; done) || exit $$?; \
|
||||
if [ -z "$$files" ]; then \
|
||||
echo "No changed litellm Python files to format-check."; \
|
||||
else \
|
||||
|
|
@ -173,14 +174,11 @@ lint-ruff: $(LINT_DEP_INSTALL)
|
|||
# https://github.com/astral-sh/ruff/discussions/4049
|
||||
lint-format-changed: install-dev
|
||||
@base_ref=$$($(RESOLVE_BASE)) && \
|
||||
diff=$$(git diff "$$base_ref" --unified=0 --no-color -- '*.py') && \
|
||||
diff=$$(git diff "$$base_ref" --unified=0 --no-color --diff-filter=d -- '*.py') && \
|
||||
printf '%s\n' "$$diff" | \
|
||||
perl -ne '\
|
||||
if (/^diff --git a\/(.*) b\//) { $$file = $$1; } \
|
||||
if (/^@@ .* \+(\d+)(?:,(\d+))? @@/) { \
|
||||
$$start = $$1; $$count = $$2 || 1; $$end = $$start + $$count - 1; \
|
||||
print "$$file:$$start:1-$$end:999\n"; \
|
||||
}' | \
|
||||
perl -ne 'if (/^\+\+\+ b\/(.*)/) { $$file = $$1; }' \
|
||||
-e 'if (/^@@ .* \+(\d+)(?:,(\d+))? @@/) { $$start = $$1; $$count = $$2 || 1; $$end = $$start + $$count - 1;' \
|
||||
-e 'print "$$file:$$start:1-$$end:999\n"; }' | \
|
||||
while read range; do \
|
||||
file="$${range%%:*}"; \
|
||||
lines="$${range#*:}"; \
|
||||
|
|
@ -199,7 +197,7 @@ lint-ruff-dev: install-dev
|
|||
|
||||
lint-ruff-FULL-dev: install-dev
|
||||
@base_ref=$$($(RESOLVE_BASE)) && \
|
||||
files=$$(git diff --name-only "$$base_ref" -- '*.py') || exit $$?; \
|
||||
files=$$(git diff --name-only --diff-filter=d "$$base_ref" -- '*.py') || exit $$?; \
|
||||
if [ -n "$$files" ]; then echo "$$files" | xargs $(UV_RUN) ruff check; \
|
||||
else echo "No changed .py files to check."; fi
|
||||
|
||||
|
|
|
|||
|
|
@ -119,6 +119,46 @@ def test_explicit_base_works_without_remote_access(
|
|||
assert "No changed litellm Python files" in checked.stdout
|
||||
|
||||
|
||||
@pytest.mark.parametrize("target", ["lint-format-check-changed", "lint-format-changed", "lint-ruff-FULL-dev"])
|
||||
def test_changed_file_targets_skip_paths_gone_from_the_working_tree(
|
||||
remote_and_clone: tuple[Path, Path],
|
||||
target: str,
|
||||
) -> None:
|
||||
_, repo = remote_and_clone
|
||||
(repo / "litellm" / "renamed_away.py").write_text("a = 1\nb = 2\nc = 3\nd = 4\n")
|
||||
_commit(repo, "add a module the branch renames")
|
||||
base: Final = _git(repo, "rev-parse", "HEAD")
|
||||
(repo / "litellm" / "kept.py").write_text("value = 2\n")
|
||||
(repo / "litellm" / "dropped.py").write_text("value = 3\n")
|
||||
_git(repo, "mv", "litellm/renamed_away.py", "litellm/renamed_to.py")
|
||||
(repo / "litellm" / "renamed_to.py").write_text("a = 1\nb = 2\nc = 3\nd = 5\n")
|
||||
_commit(repo, "add two modules and rename one")
|
||||
_git(repo, "rm", "-q", "litellm/dropped.py", "litellm/example.py")
|
||||
checked: Final = _make(repo, target, "-o", "install-dev", f"BASE_REF={base}", "UV_RUN=echo")
|
||||
assert checked.returncode == 0, checked.stderr
|
||||
assert "litellm/kept.py" in checked.stdout
|
||||
assert "litellm/renamed_to.py" in checked.stdout
|
||||
assert "--range 0:" not in checked.stdout
|
||||
gone: Final = ("litellm/dropped.py", "litellm/example.py", "litellm/renamed_away.py")
|
||||
assert [path for path in gone if path in checked.stdout] == []
|
||||
|
||||
|
||||
def test_format_check_skips_a_branch_file_the_merged_base_renamed(remote_and_clone: tuple[Path, Path]) -> None:
|
||||
_, repo = remote_and_clone
|
||||
_git(repo, "checkout", "-qb", "upstream")
|
||||
_git(repo, "mv", "litellm/example.py", "litellm/moved.py")
|
||||
_commit(repo, "upstream renames the module")
|
||||
_git(repo, "checkout", "-q", "release_branch")
|
||||
(repo / "litellm" / "example.py").write_text("value = 5\n")
|
||||
_commit(repo, "branch edits the module")
|
||||
_git(repo, "-c", "user.name=Test", "-c", "user.email=test@example.com", "merge", "-q", "--no-commit", "upstream")
|
||||
assert (repo / "litellm" / "moved.py").read_text() == "value = 5\n"
|
||||
checked: Final = _make(repo, "lint-format-check-changed", "BASE_REF=upstream", "UV_RUN=echo")
|
||||
assert checked.returncode == 0, checked.stderr
|
||||
assert "litellm/example.py" not in checked.stdout
|
||||
assert "No changed litellm Python files to format-check." in checked.stdout
|
||||
|
||||
|
||||
def _freshness(repo: Path, *args: str) -> subprocess.CompletedProcess[str]:
|
||||
return subprocess.run(
|
||||
[
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue