Skip to content
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

Use SKIP variable in pre-commit install-hooks #3096

Open
mdeweerd opened this issue Dec 9, 2023 · 8 comments
Open

Use SKIP variable in pre-commit install-hooks #3096

mdeweerd opened this issue Dec 9, 2023 · 8 comments

Comments

@mdeweerd
Copy link

mdeweerd commented Dec 9, 2023

search you tried in the issue tracker

is:issue install-hooks "skip"

describe your actual problem

The SKIP environment variable allows skipping hook executing.

I use it in ci because one of the hooks does not install properly.
To optimize, I try to build a Docker image with pre-installed hooks using

RUN SKIP=perltidy pre-commit install-hooks

However, the perltidy hook is still being installed (and fails).

My suggestion is to skip installation of a hook when it is in the SKIP environment variable.

pre-commit --version

precommit: 3.6.8

@asottile
Copy link
Member

asottile commented Dec 9, 2023

the version output does not match any version that's ever been released

@asottile
Copy link
Member

asottile commented Dec 9, 2023

I'm not sure if giving SKIP another meaning really makes sense. why are you skipping installation in the first place?

@mdeweerd
Copy link
Author

The issue below why I want to skip the installation and execution of a hook.
When running SKIP=perltidy pre-commit run -a the perltidy hook is effectively not installed before running the other hooks. However that method uses up more resources (download, install, etc).

#8 39.87 [INFO] Installing environment for https://github.com/perltidy/perltidy.
#8 39.87 [INFO] Once installed this environment will be reused.
#8 39.87 [INFO] This may take a few minutes...
#8 44.92 An unexpected error has occurred: FileNotFoundError: [Errno 2] No such file or directory: '/root/.cache/pre-commit/repom1vlxp8h/perl_env-default/.install_state_v1staging'
#8 44.92 Check the log at /root/.cache/pre-commit/pre-commit.log
#8 ERROR: process "/bin/sh -c SKIP=perltidy pre-commit install-hooks" did not complete successfully: exit code: 3

@asottile
Copy link
Member

it would probably be better to figure out why perl hooks aren't working for you -- have you done any debugging into why that directory and file isn't getting created properly?

@mdeweerd
Copy link
Author

it would probably be better to figure out why perl hooks aren't working for you -- have you done any debugging into why that directory and file isn't getting created properly?

I've already spent a fair amount of time on that in the past, I decided to skip it in the CI and keep it in the pre-commit. It's a third party action.

From my point of view SKIP does not change meaning if it also skips the hooks for install-hooks - it's still skipping hooks for the pre-commit execution.

It's up to you, I can still add another workaround: comment the hook automatically in the .pre-commit-config.yaml file before running pre-commit install-hooks.

@asottile
Copy link
Member

it's mostly that SKIP is only intended to be an environment variable because there's no other interface at commit time. there's no such limitation for other commands

though ideally it'd probably benefit more people to figure out the perl issue

@mdeweerd
Copy link
Author

mdeweerd commented Dec 10, 2023

When I can I share my findings back to the project, but here the effort to fix it is currently too important.

For pre-commit I submitted a proposal for feature that could have other benefits.

There are another benefits of skipping with install-hooks: no installation of manual hooks that are not useful in CI (and less resource usage).

Anyway, this is my workaround I now use in case anybody else needs something similar:

RUN perl -lX -0X -i -p -e 's@[^\n]*- repo: https://github.com/perltidy/perltidy.*?\n(?=[^\n]*repo)@@s' .pre-commit-config.yaml \
    && pre-commit install-hooks

@mdeweerd
Copy link
Author

the version output does not match any version that's ever been released

Sorry, it was 3.6.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants