From a8db5940128b8f7ab8f61e6a3862781f4cc1c931 Mon Sep 17 00:00:00 2001 From: Michael Landis Date: Thu, 28 Sep 2023 16:13:07 -0700 Subject: [PATCH] fix: short-circuit black and mypy calls when no changes made (#11051) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both black and mypy expect a list of files or directories as input. As-is the Makefile computes a list files changed relative to the last commit; these are passed to black and mypy in the `format_diff` and `lint_diff` targets. This is done by way of the Makefile variable `PYTHON_FILES`. This is to save time by skipping running mypy and black over the whole source tree. When no changes have been made, this variable is empty, so the call to black (and mypy) lacks input files. The call exits with error causing the Makefile target to error out with: ```bash $ make format_diff poetry run black Usage: black [OPTIONS] SRC ... One of 'SRC' or 'code' is required. make: *** [format_diff] Error 1 ``` This is unexpected and undesirable, as the naive caller (that's me! 😄 ) will think something else is wrong. This commit smooths over this by short circuiting when `PYTHON_FILES` is empty. --- libs/langchain/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/langchain/Makefile b/libs/langchain/Makefile index 5bfa3391dda..abaa4ced225 100644 --- a/libs/langchain/Makefile +++ b/libs/langchain/Makefile @@ -50,12 +50,12 @@ lint lint_diff: ./scripts/check_pydantic.sh . ./scripts/check_imports.sh poetry run ruff . - poetry run black $(PYTHON_FILES) --check - poetry run mypy $(PYTHON_FILES) + [ "$(PYTHON_FILES)" = "" ] || poetry run black $(PYTHON_FILES) --check + [ "$(PYTHON_FILES)" = "" ] || poetry run mypy $(PYTHON_FILES) format format_diff: - poetry run black $(PYTHON_FILES) - poetry run ruff --select I --fix $(PYTHON_FILES) + [ "$(PYTHON_FILES)" = "" ] || poetry run black $(PYTHON_FILES) + [ "$(PYTHON_FILES)" = "" ] || poetry run ruff --select I --fix $(PYTHON_FILES) spell_check: poetry run codespell --toml pyproject.toml