-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash on first commit when adding a pre-commit hook #99
Comments
Hi @acdha could you please provide a minimal reproducer indicating the circumstances that this error is happening for you? I tried to execute the following, but I cannot see anything wrong happening (so I cannot observe the error you are referring to): > docker run --rm -it python:3.9-bullseye /bin/bash
git config --global init.defaultBranch main
git config --global user.name User
git config --global user.email [email protected]
pip install -U pre-commit
mkdir /tmp/test
cd /tmp/test
cat <<EOF > .pre-commit-config.yaml
repos:
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.12.2
hooks:
- id: validate-pyproject
EOF
cat <<EOF > pyproject.toml
[project]
name = "helloworld"
version = "42"
EOF
git init .
git add .
git commit -m "Initial commit"
pre-commit install
sed -i 's/42/4.2/g' pyproject.toml
git commit -a -m "Change version"
# [INFO] Initializing environment for https://github.com/abravalheri/validate-pyproject.
# [INFO] Initializing environment for https://github.com/abravalheri/validate-pyproject:.[all].
# [INFO] Installing environment for https://github.com/abravalheri/validate-pyproject.
# [INFO] Once installed this environment will be reused.
# [INFO] This may take a few minutes...
# Validate pyproject.toml..................................................Passed
# [main 4614763] Change version
# 1 file changed, 1 insertion(+), 1 deletion(-) |
Please feel free to edit the script above and adapt it to create a minimal reproducer for the error you are seeing. |
It no longer reproduces but I noticed something interesting when running pre-commit with a clean cache:
That happens whether or not I put the |
So I'm experiencing this right now. repos:
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.18
hooks:
- id: validate-pyproject
# Optional extra validations from SchemaStore:
files: '.*pyproject\.toml'
additional_dependencies: ["validate-pyproject-schema-store[all]"]
Note, that version 0.19 is released right now. The fix for me is to either:
So I'm guessing something breaks when the first time the pre-commit initialises is when it's for a version that's not latest, and the additional dependencies are no longer available or something like that? |
@jvacek I suspect that what is happening in your case is that probably If you either restrict |
It shouldn’t depend on anything new. I’ve not touched it besides the auto SchemaStore updates in a while. Is the error message the same as above? |
@henryiii, does In 0.19 I introduced a new format, I was assuming that the crash was because the schema needs this new format. But probably I am wrong then. @jvacek, could you please provide the full error trace? |
@abravalheri how exactly would you like me to do that? I'm just using this via pre-commit, I'm not running the tool directly |
On a crash, Otherwise, could you please send here the error message you saw and help me with the reproducer below? Right now it is not crashing. Could you try to modify it to produce the same behaviour you are experiencing? # > docker run --rm -it python:3.12.5-bookworm /bin/bash
mkdir /tmp/proj
cd /tmp/proj
cat <<EOF > pyproject.toml
[project]
name = "proj"
version = "42"
EOF
cat <<EOF > .pre-commit-config.yaml
repos:
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.18
hooks:
- id: validate-pyproject
# Optional extra validations from SchemaStore:
files: '.*pyproject\.toml'
additional_dependencies: ["validate-pyproject-schema-store[all]"]
EOF
git init .
git add pyproject.toml
git add .pre-commit-config.yaml
python -m venv .venv
.venv/bin/python -m pip install pre-commit
.venv/bin/pre-commit install
.venv/bin/pre-commit run --verbose
# [INFO] Initializing environment for https://github.com/abravalheri/validate-pyproject.
# [INFO] Initializing environment for https://github.com/abravalheri/validate-pyproject:validate-pyproject-schema-store[all].
# [INFO] Installing environment for https://github.com/abravalheri/validate-pyproject.
# [INFO] Once installed this environment will be reused.
# [INFO] This may take a few minutes...
# Validate pyproject.toml..................................................Passed
# - hook id: validate-pyproject
# - duration: 1.0s
#
# Valid file: pyproject.toml |
Doesn't seem like it. This is the best I got. $ pre-commit run -v
[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to /Users/jvacek/.cache/pre-commit/patch1724251202-13884.
markdownlint-fix.....................................(no files to check)Skipped
- hook id: markdownlint-fix
Lint YAML................................................................Passed
- hook id: yamllint
- duration: 0.12s
shfmt................................................(no files to check)Skipped
- hook id: shfmt
shellcheck...........................................(no files to check)Skipped
- hook id: shellcheck
trim trailing whitespace.................................................Passed
- hook id: trailing-whitespace
- duration: 0.05s
fix end of files.........................................................Passed
- hook id: end-of-file-fixer
- duration: 0.04s
check toml...............................................................Passed
- hook id: check-toml
- duration: 0.04s
Validate pyproject.toml..................................................Failed
- hook id: validate-pyproject
- duration: 0.1s
- exit code: 1
[ERROR] FileNotFoundError: [Errno 2] No such file or directory: '/Users/jvacek/.cache/pre-commit/repo_vlx0urg/py_env-python3.12/lib/python3.12/site-packages/validate_pyproject/pyproject_toml.schema.json'
[INFO] Restored changes from /Users/jvacek/.cache/pre-commit/patch1724251202-13884. |
Have you checked to see if that file exists? Is that the correct directory structure? |
Yeah, I am failing to see why the file would not be present in the disk:
@jvacek did you had the chance to check the path as suggested by Henry? If you can have a look on the script I shared in #99 (comment) and help to evolve it into a reproducer, that would be very helpful (since so far I did not manage to reproduce the problem). |
And now this happens when i've got 0.19 in the config too. Every here and there, I will run I'll see if I can do something to repro this, but not sure when I'll have the time. |
I noticed an odd failure which might be related to #36. I was adding this to an existing project and added the following to my
.pre-commit-config.yaml
file:I updated
pyproject.toml
to test it and rangit commit -a
, waited for it to install the hook, and got this crash:What's interesting is that
pre-commit run --all-files
did not fail on the same repository. If I run it with-v
, I see output like this indicating that it successfully validated the file:If I change the pre-commit hook like this, it starts working, suggesting this is related to packaging:
The text was updated successfully, but these errors were encountered: