Skip to content

BUG: make precommit-local doesn't work as expected #496

@carlory

Description

@carlory

Describe the bug
When I sumbit some changes on MacOS, it always fails with the following error:

/Applications/Xcode.app/Contents/Developer/usr/bin/python3: No module named pre_commit

The root cause is that the generated hook file depends on the container python environment.

#!/usr/bin/env bash
# File generated by pre-commit: https://pre-commit.com
# ID: 138fd403232d2ddd5efb44317e38bf03

# start templated
INSTALL_PYTHON=/usr/bin/python3
ARGS=(hook-impl --config=.pre-commit-config.yaml --hook-type=pre-commit)
# end templated

HERE="$(cd "$(dirname "$0")" && pwd)"
ARGS+=(--hook-dir "$HERE" -- "$@")

if [ -x "$INSTALL_PYTHON" ]; then
    exec "$INSTALL_PYTHON" -mpre_commit "${ARGS[@]}"
elif command -v pre-commit > /dev/null; then
    exec pre-commit "${ARGS[@]}"
else
    echo '`pre-commit` not found.  Did you forget to activate your virtualenv?' 1>&2
    exit 1
fi

On the other hand, according to Contribution Guide that all you need is a container runtime, it is not true. After running make precommit-local, I found that I still need to install some dependencies manually, such as pre-commit, yamllint, codespell, shellcheck, golangci-lint, etc.

And the required python must be installed in the specific binary path and related dependenics should be install in that environment.

my default environment:

(base) ➜  semantic-router git:(fix-missing-shellcheck) ✗ conda env list
# conda environments:
#
base                  *  /opt/miniconda3

(base) ➜  semantic-router git:(fix-missing-shellcheck) ✗ which -a python
python: aliased to python3.9
/opt/miniconda3/bin/python

(base) ➜  semantic-router git:(fix-missing-shellcheck) ✗ which pre-commit
/opt/miniconda3/bin/pre-commit

Expected behavior

make precommit-local shouldn't depend on host, or remove this command.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions