I'm referencing just commands in custom pre-commit hooks. For some reason, just is interpreting staged files as recipes, which leads to
trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...............................................................Passed
check toml...............................................................Passed
ruff (linter)............................................................Failed
- hook id: ruff-lint
- exit code: 1
error: Justfile does not contain recipes
`folder_1/src/alembic/versions/fb4554c0e46f_first_commit.py`,
`folder_1/src/alembic/env.py`, `folder_1/src/crud/user.py`, or `config.py`.
ruff (formatter).........................................................Failed
- hook id: ruff-format
- exit code: 1
error: Justfile does not contain recipes
`folder_1/src/alembic/versions/fb4554c0e46f_first_commit.py`,
`folder_1/src/alembic/env.py`, `folder_1/src/crud/user.py`, or `config.py`.
My project tree is as follows (at least for what pertains to the files listed within the error message):
|-- folder_1
|-- src
|-- alembic
| |-- env.py
| |-- versions
| |-- fb4554c0e46f_first_commit.py
|-- crud
| |-- user.py
...
|-- folder_2
|-- src
...
.pre-commit-config.yaml
config.py
justfile
poetry.lock
pyproject.toml
My .pre-commit-config.yaml is as follows:
default_language_version:
python: python3.10
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-toml
- repo: local
hooks:
- id: ruff-lint
name: ruff (linter)
entry: just ruff-fix
language: system
types: [python]
- id: ruff-format
name: ruff (formatter)
entry: just ruff-format
language: system
types: [python]
My justfile is as follows:
help:
@just --list
install:
@echo " Installing dependencies"
@poetry install --with dev
install-pre-commit:
@echo " Setting up the hooks"
@poetry run pre-commit install
check-project:
@echo " Checking consistency between poetry.lock and pyproject.toml"
@poetry check --lock
@echo " Running the hooks against all files"
@poetry run pre-commit run --all-files
ruff:
@echo " Linting the project with Ruff"
@poetry run ruff check .
ruff-show-violations:
@echo " Linting the project with Ruff and show violations"
@poetry run ruff check --output-format="grouped" .
ruff-fix:
@echo " Linting the project with Ruff and autofix violations (where possible)"
@poetry run ruff check --fix .
ruff-format:
@echo " Formatting the code with Ruff"
@poetry run ruff format .
ruff-format-check:
@echo " Listing files Ruff would reformat"
@poetry run ruff format --check .
lint-and-format: ruff-fix ruff-format
Versions:
$ just --version
just 1.23.0
$ pre-commit --version
pre-commit 3.7.0
Can someone help with this issue? I used to work with a similar setup in different repositories and it did always work.
Eventually, substituting [poetry run ruff check --fix .] to [just ruff-fix] and [poetry run ruff format .] to [just ruff-format] into .pre-commit-config.yaml just :) works, but I'd like to use just commands.
you've selected
types: [python]in your configuration -- as the name says it matches python files in your repository -- and clearly not all of yourtypes: [python]files are just filesyou probably want to adjust your filtering by using either
filesorexcludedisclaimer: I wrote pre-commit