Skip to content

Have to manually enable venv before commiting, or mirror django and all other dependencies into additional_dependencies #4

@leinadao

Description

@leinadao

I use poetry and have the following dependencies:

[tool.poetry.dependencies]
python = "^3.8.9"
Django = "^4.0"
django-bootstrap-v5 = "^1.0.7"

The entrypoint commands in check-unapplied-migrations and check-absent-migrations simply run 'python' which fails importing django and / or (depending on the system python packages installed) django-bootstrap-v5.
These are required via manage.py and e.g. Django's INSTALLED_APPS.

Manually activating the virtual environment (e.g. poetry shell) before commiting is one solution.

Based on some progress, I believe it would be possible to resolve by adding every dependency to the hook's additional_dependencies, but this is horribly repetative and error-prone.

Instead I've temporarily resolved the issue by overriding the hook's entrypoint to use poetry and so invoke the virtual environment and have access to all dependencies required to run the project's migration code.

-   repo: https://github.com/ecugol/pre-commit-hooks-django
    rev: v0.4.0
    hooks:
    -   id: check-untracked-migrations
    -   id: check-unapplied-migrations
        entry: sh -c 'poetry run python `find . -name "manage.py"` migrate --check'
    -   id: check-absent-migrations
        entry: sh -c 'poetry run python `find . -name "manage.py"` makemigrations --check --dry-run'

Perhaps configuration could be added for which 'python' command to run?
And / or cases like this could be added to the documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions