-1

我尝试在提交之前配置 start mypy + django-stubs cheking。我使用预先提交。当我尝试提交时,出现错误django.core.exceptions.ImproperlyConfigured: Set the POSTGRES_DB environment variable。这个变量在 .env 文件中,我使用 django-environ 将变量从 .env 导出到 Django 配置。当然还有 .gitignore 中的 .env。所以,据我了解:预提交从它自己的虚拟环境开始,它不知道我的 .env 文件。

最重要的是,我是否正确理解我的情况?如果我是对的,如何从 .env 文件中获取变量以预先提交环境?

我的.pre-commit-config.yaml(部分)

- repo: https://github.com/pre-commit/mirrors-mypy
    rev: ''
    hooks:
      - id: mypy
        exclude: "[a-zA-Z]*/(migrations)/(.)*"
        args: [--config=setup.cfg,
               --no-strict-optional,
               --ignore-missing-imports]
       additional_dependencies: [django-stubs, django-environ]

我的setup.cfg

[mypy]
python_version = 3.9
allow_redefinition = True
check_untyped_defs = True
ignore_missing_imports = True
incremental = True
strict_optional = True
show_traceback = True
warn_no_return = False
warn_unused_ignores = True
warn_redundant_casts = True
warn_unused_configs = True
plugins = mypy_django_plugin.main
show_column_numbers = True

[mypy.plugins.django-stubs]
django_settings_module = config.settings.local

[mypy_django_plugin]
ignore_missing_model_attributes = True

[mypy-*.migrations.*]
# Django migrations should not produce any errors:
ignore_errors = True
4

0 回答 0