fix: short-circuit black and mypy calls when no changes made (#11051)

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.
This commit is contained in:
Michael Landis 2023-09-28 16:13:07 -07:00 committed by GitHub
parent fbcd8e02f2
commit a8db594012
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -50,12 +50,12 @@ lint lint_diff:
./scripts/check_pydantic.sh . ./scripts/check_pydantic.sh .
./scripts/check_imports.sh ./scripts/check_imports.sh
poetry run ruff . poetry run ruff .
poetry run black $(PYTHON_FILES) --check [ "$(PYTHON_FILES)" = "" ] || poetry run black $(PYTHON_FILES) --check
poetry run mypy $(PYTHON_FILES) [ "$(PYTHON_FILES)" = "" ] || poetry run mypy $(PYTHON_FILES)
format format_diff: format format_diff:
poetry run black $(PYTHON_FILES) [ "$(PYTHON_FILES)" = "" ] || poetry run black $(PYTHON_FILES)
poetry run ruff --select I --fix $(PYTHON_FILES) [ "$(PYTHON_FILES)" = "" ] || poetry run ruff --select I --fix $(PYTHON_FILES)
spell_check: spell_check:
poetry run codespell --toml pyproject.toml poetry run codespell --toml pyproject.toml