小编Iva*_*nko的帖子

如何让 .env 预提交 + mypy + django-stubs

我尝试在提交之前配置 start mypy + django-stubs 检查。我使用预提交。当我尝试提交时,出现错误django.core.exceptions.ImproperlyConfigured:设置 POSTGRES_DB 环境变量。该变量位于 .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]
Run Code Online (Sandbox Code Playgroud)

我的设置.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 …
Run Code Online (Sandbox Code Playgroud)

python django mypy pre-commit.com django-stubs

5
推荐指数
0
解决办法
1179
查看次数

标签 统计

django ×1

django-stubs ×1

mypy ×1

pre-commit.com ×1

python ×1