pre-commit-hooks-django icon indicating copy to clipboard operation
pre-commit-hooks-django copied to clipboard

Use of find for manage.py can return multiple files and break e.g. with a local env dir

Open leinadao opened this issue 3 years ago • 0 comments

I'm using poetry and have it configured to store the environment within the project, in ./venv.

Due to one of the pacakges in the environment, the find command in the check-unapplied-migrations and check-absent-migrations entrypoints is returning two manage.py files:

  • ./venv/..../manage.py
  • ./manage.py.

Then:

  • The wrong manage.py is run
  • ./manage.py is also passsed in and causes an error as an invalid command

It seems plausible that other situations could arrise causing multiple manage.py files to be found too.

I've temporarily resolved this by overriding a hard-coded entrypoint:

-   repo: https://github.com/ecugol/pre-commit-hooks-django
    rev: v0.4.0
    hooks:
    -   id: check-untracked-migrations
    -   id: check-unapplied-migrations
        entry: python manage.py migrate --check
    -   id: check-absent-migrations
        entry: python manage.py makemigrations --check --dry-run

Is there reason to use find for manage.py? If so then perhaps a small script could only run this if ./manage.py (default location) is not available? However that could still run into a multiple files found issue, in the non-default location instance (i.e. when falling back to find). So perhaps hard code a default and allow an argument for manual override if at a different location is required?

leinadao avatar Jan 04 '22 01:01 leinadao