Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pre-commit shows different result when running directly in command line vs running from make

I have a Makefile that contains this:

SOURCE_DIR=./some_codebase/**/*

check-mypy:
    pre-commit run mypy --files $(SOURCE_DIR)

When I trigger make check-mypy, the result shows up as Passed (which is not correct), but when I run pre-commit run mypy --files ./some_codebase/**/* directly in the command line, the result shows up as Failed (which is correct). Another thing to point out is that I use mypy in this question only as an example, all other hooks have this issue as well (I also use ruff/black). This issue also happens in my bitbucket pipeline.

$ make check-mypy
pre-commit run mypy --files ./pyworker_v2/**/*
mypy.....................................................................Passed
$ pre-commit run mypy --files ./pyworker_v2/**/*
mypy.....................................................................Failed
- hook id: mypy
- exit code: 1

My .pre-commit-config.yaml is as below:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

minimum_pre_commit_version: 3.3.3

repos:
  - repo: local
    hooks:
      - id: mypy
        name: mypy
        entry: mypy --config-file ./pyproject.toml --enable-incomplete-feature=Unpack --install-types --non-interactive
        language: system
        types: [python]

I’ve tried running the command through a bash script and weirdly enough, the check shows up as Passed again (not correct), so this is not just an issue with the Makefile.

#!/bin/bash

pre-commit run mypy --files ./pyworker_v2/**/*

I also tried:

  • Using absolute path (same issue).
  • Test with an incorrect path to a nonexistent directory, which pre-commit correctly detects and fails.
  • Do research on git hook caching/pre-commit caching, but nothing shows up yet.

>Solution :

This isn’t a git issue, but a Make & shell one.

You’re (presumably) using zsh as your interactive shell, which supports the ** recursive wildcard as an extension to the original glob expansion.

Neither bash, for your bash script, nor GNU Make (which uses the same glob expansion as bash AFAIK) support this zsh extension.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading