【问题标题】:Exclude .env directory from flake8 tests?从 flake8 测试中排除 .env 目录?
【发布时间】:2020-03-26 11:10:21
【问题描述】:

问题

我收到了数千个源自本地 .env 的 flake8 错误。一些错误消息的示例:

./env/lib/python3.7/site-packages/pip/_vendor/pyparsing.py:3848:80: E501 line too long (85 > 79 characters)
./env/lib/python3.7/site-packages/pip/_vendor/pyparsing.py:3848:84: E202 whitespace before ')'
./env/lib/python3.7/site-packages/pip/_vendor/pyparsing.py:3855:51: E201 whitespace after '('
./env/lib/python3.7/site-packages/pip/_vendor/pyparsing.py:3855:65: E202 whitespace before ')'
./env/lib/python3.7/site-packages/pip/_vendor/pyparsing.py:3858:50: E201 whitespace after '('
./env/lib/python3.7/site-packages/pip/_vendor/pyparsing.py:3858:78: E202 whitespace before ')'
./env/lib/python3.7/site-packages/pip/_vendor/pyparsing.py:3861:31: E231 missing whitespace after ','
./env/lib/python3.7/site-packages/pip/_vendor/pyparsing.py:3865:1: W293 blank line contains whitespace
./env/lib/python3.7/site-packages/pip/_vendor/pyparsing.py:3866:1: E302 expected 2 blank lines, found 1

我的目录如下所示:

我的 flake8 文件如下所示:

[flake8]
exclude =
    migrations,
    __pycache__,
    manage.py,
    settings.py,

问题

如何将我的 env 文件内容添加到 flake8 的排除列表中?

我尝试过的

我已经尝试添加:

  env,
./env,

我试过去掉逗号并添加:

[flake8]
exclude =
    migrations
    __pycache__
    manage.py
    settings.py
    env
    .env
    ./env
    env/
    .env/

运行 flake8 --exclude 迁移,pycache,manage.py,settings.py,env 返回:

./app/core/models.py:7:80: E501 line too long (93 > 79 characters)
./app/core/models.py:13:66: E225 missing whitespace around operator
./app/core/models.py:13:80: E501 line too long (103 > 79 characters)
./app/core/admin.py:10:1: W293 blank line contains whitespace
./app/core/admin.py:11:1: W293 blank line contains whitespace
./app/core/admin.py:13:1: W293 blank line contains whitespace
./app/core/tests/test_commands.py:23:47: W292 no newline at end of file
./app/core/management/commands/wait_for_db.py:21:69: W292 no newline at end of file
./app/project/urls.py:23:2: W292 no newline at end of file
./app/inventory/serializers.py:4:1: E302 expected 2 blank lines, found 1
./app/inventory/serializers.py:8:1: W391 blank line at end of file
./app/inventory/urls.py:5:70: W291 trailing whitespace
./app/inventory/urls.py:7:26: W292 no newline at end of file
./app/inventory/views.py:1:1: F401 'rest_framework.response.Response' imported but unused
./app/inventory/views.py:7:1: E302 expected 2 blank lines, found 1
./app/inventory/views.py:11:1: W293 blank line contains whitespace
./app/inventory/views.py:12:5: E303 too many blank lines (2)
./app/inventory/views.py:36:43: W292 no newline at end of file
./app/inventory/tests/test_api.py:2:1: F401 'django.urls.reverse' imported but unused
./app/inventory/tests/test_api.py:7:1: W293 blank line contains whitespace
./app/inventory/tests/test_api.py:9:8: E111 indentation is not a multiple of four
./app/inventory/tests/test_api.py:10:8: E111 indentation is not a multiple of four
./app/inventory/tests/test_api.py:10:40: W291 trailing whitespace
./app/inventory/tests/test_api.py:11:1: W293 blank line contains whitespace
./app/inventory/tests/test_api.py:12:8: E111 indentation is not a multiple of four
./app/inventory/tests/test_api.py:13:8: E111 indentation is not a multiple of four
./app/inventory/tests/test_api.py:18:41: W291 trailing whitespace
./app/inventory/tests/test_api.py:19:1: W293 blank line contains whitespace
./app/inventory/tests/test_api.py:25:37: W291 trailing whitespace
./app/inventory/tests/test_api.py:26:41: W291 trailing whitespace
./app/inventory/tests/test_api.py:27:1: W293 blank line contains whitespace
./app/inventory/tests/test_api.py:31:1: W391 blank line at end of file
./app/inventory/tests/test_api.py:31:1: W293 blank line contains whitespace

【问题讨论】:

  • 您是否尝试过使用env?结果一样吗?
  • 谢谢卢卡斯,但我有。我将更新问题以包含此
  • 或者更确切地说是.env/ ?
  • 我刚才也试过了。我会将其添加到尝试过的内容中。
  • 您可以尝试在命令行中提供排除模式吗? flake8 --exclude migrations,__pycache__,manage.py,settings.py,env

标签: python django flake8


【解决方案1】:

我注意到您的 .flake8 文件位于 app 文件夹中。我假设您是从 app 文件夹外部启动 flake8,换句话说,从项目根目录开始。

.flake8 移动到项目根目录,一切正常:

mv app/.flake8 .

【讨论】:

    【解决方案2】:

    删除逗号。这些 .ini 文件中的列表只是多行列表:

    [flake8]
    exclude =
        migrations
        __pycache__
        manage.py
        settings.py
        env
        .env
    

    【讨论】:

    • 感谢 AKX,但它似乎没有任何改变,我仍然收到错误
    • 你的目录也叫env,而不是.env :)
    • 哈哈,我正在尝试使用 env .env ./env env/ .env/ !
    【解决方案3】:

    也可以通过cli的--exclude标志排除。

     --exclude patterns    Comma-separated list of files or directories to
                        exclude. (Default: ['.svn', 'CVS', '.bzr', '.hg',
                        '.git', '__pycache__', '.tox', '.eggs', '*.egg'])
    

    注意这里是逗号分隔的列表,与 flake8 配置文件不同

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-10
      • 2018-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-03
      • 1970-01-01
      相关资源
      最近更新 更多