use pre-commit to run linter formatter
This commit is contained in:
parent
86da9b2e43
commit
95f30e6a14
32
Makefile
32
Makefile
@ -23,6 +23,14 @@ expect-uv:
|
|||||||
echo "Please install uv to continue:\n https://github.com/astral-sh/uv?tab=readme-ov-file#installation"; \
|
echo "Please install uv to continue:\n https://github.com/astral-sh/uv?tab=readme-ov-file#installation"; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# assume reasonably pre-commit is a safe dependency given its wide support (e.g. GitHub Actions integration)
|
||||||
|
.PHONY: ensure-pre-commit
|
||||||
|
@if ! /usr/bin/which -s pre-commit; then \
|
||||||
|
echo "pre-commit required for submitting commits before pull requests. Using uv tool to install pre-commit."; \
|
||||||
|
uv tool install pre-commit; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# assume reasonably that if user has installed uv, they trust ruff from the same team
|
# assume reasonably that if user has installed uv, they trust ruff from the same team
|
||||||
.PHONY: ensure-ruff
|
.PHONY: ensure-ruff
|
||||||
ensure-ruff:
|
ensure-ruff:
|
||||||
@ -41,16 +49,18 @@ venv-init: expect-arm64 expect-uv
|
|||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
.PHONY: install
|
.PHONY: install
|
||||||
install: venv-init
|
install: venv-init ensure-pre-commit
|
||||||
# 🏗️ Installing dependencies...
|
# 🏗️ Installing dependencies and pre-commit hooks...
|
||||||
uv pip install -e .
|
uv pip install -e .
|
||||||
# ✅ Dependencies installed.
|
# ✅ Dependencies installed.
|
||||||
|
pre-commit install
|
||||||
|
# ✅ Pre-commit hooks installed.
|
||||||
|
|
||||||
# Run linters
|
# Run linters
|
||||||
.PHONY: lint
|
.PHONY: lint
|
||||||
lint: ensure-ruff
|
lint: ensure-ruff
|
||||||
# 🏗️ Running linters, your files will not be mutated.
|
# 🏗️ Running linters, your files will not be mutated.
|
||||||
# Use 'make autofix' to auto-apply fixes."
|
# Use 'make check' to auto-apply fixes."
|
||||||
ruff check
|
ruff check
|
||||||
# ✅ Linting complete."
|
# ✅ Linting complete."
|
||||||
|
|
||||||
@ -63,15 +73,11 @@ format: ensure-ruff
|
|||||||
git diff --stat
|
git diff --stat
|
||||||
# ✅ Formatting complete. Please review your git diffs, if any.
|
# ✅ Formatting complete. Please review your git diffs, if any.
|
||||||
|
|
||||||
# Run ruff auto lint and format
|
# Run ruff auto lint and format via pre-commit hook
|
||||||
# use || true to force possibly failing format/lint checks to allow rest of make helper to continue
|
.PHONY: check
|
||||||
.PHONY: autofix
|
check: ensure-ruff
|
||||||
autofix: ensure-ruff
|
# 🏗️ Running pre-commit linter and formatters on files...
|
||||||
# 🏗️ Running linter and formatters on files...
|
@(pre-commit run --all-files)
|
||||||
@(ruff format --respect-gitignore --target-version py310 || true)
|
|
||||||
# ✅ auto formatting complete
|
|
||||||
@(ruff check --fix || true)
|
|
||||||
# ✅ auto lint fixes complete, check for issues ruff cannot auto fix
|
|
||||||
|
|
||||||
# Run tests
|
# Run tests
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
@ -96,7 +102,7 @@ help:
|
|||||||
@echo " make install - Install project dev dependencies"
|
@echo " make install - Install project dev dependencies"
|
||||||
@echo " make lint - Run ruff python linter"
|
@echo " make lint - Run ruff python linter"
|
||||||
@echo " make format - Run ruff code formatter"
|
@echo " make format - Run ruff code formatter"
|
||||||
@echo " make autofix - Run linters auto fixes *and* style formatter"
|
@echo " make check - Run linters auto fixes *and* style formatter via pre-commit hook"
|
||||||
@echo " make test - Run tests"
|
@echo " make test - Run tests"
|
||||||
@echo " make clean - Remove the virtual environment"
|
@echo " make clean - Remove the virtual environment"
|
||||||
@echo " make help - Show this help message"
|
@echo " make help - Show this help message"
|
||||||
|
|||||||
@ -53,7 +53,7 @@ pip install -U mflux
|
|||||||
3. Follow format and lint checks prior to submitting Pull Requests. The recommended `make lint` and `make format` installs and uses [`ruff`](https://github.com/astral-sh/ruff). You can setup your editor/IDE to lint/format automatically, or use our provided `make` helpers:
|
3. Follow format and lint checks prior to submitting Pull Requests. The recommended `make lint` and `make format` installs and uses [`ruff`](https://github.com/astral-sh/ruff). You can setup your editor/IDE to lint/format automatically, or use our provided `make` helpers:
|
||||||
- `make format` - formats your code
|
- `make format` - formats your code
|
||||||
- `make lint` - shows your lint errors and warnings, but does not auto fix
|
- `make lint` - shows your lint errors and warnings, but does not auto fix
|
||||||
- `make autofix` - formats your code **and** attempts to auto fix lint errors
|
- `make check` - via `pre-commit` hooks, formats your code **and** attempts to auto fix lint errors
|
||||||
- consult official [`ruff` documentation](https://docs.astral.sh/ruff/) on advanced usages
|
- consult official [`ruff` documentation](https://docs.astral.sh/ruff/) on advanced usages
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user