我正在尝试为 django-rest-framework 做出贡献,运行 isort
后身份验证文件中的导入如下(我添加了导入六):
from __future__ import unicode_literals
import base64
import six
from django.contrib.auth import authenticate, get_user_model
from django.middleware.csrf import CsrfViewMiddleware
from django.utils.translation import ugettext_lazy as _
from rest_framework import HTTP_HEADER_ENCODING, exceptions
当我运行./runtests --lintonly
时,它通过了所有测试,但是当我运行tox
时,它给了我这个错误:
py27-lint runtests: commands[0] | ./runtests.py --lintonly
Running flake8 code linting
flake8 passed
Running isort code checking
ERROR: /home/nitesh/open_source/django-rest-framework/rest_framework/authentication.py Imports are incorrectly sorted.
isort failed: Some modules have incorrectly ordered imports. Fix by running `isort --recursive .`
ERROR: InvocationError: '/home/nitesh/open_source/django-rest-framework/runtests.py --lintonly'
最佳答案
我遇到了类似的错误(导入排序不正确
)。
isort
直接运行时很高兴,但通过 tox
运行时失败。 isort
提示的行是:
import pytest
from my_module import MyThing
isort
在直接运行时知道我的模块 my_module
是第一方(我自己的)代码,而通过 tox
则不然。 t。因此,当直接运行时,它对 pytest
导入和我的导入之间的空行感到满意,但通过 tox
它不想看到空行,因为 pytest
和 my_module
被解释为第三方导入。
解决方案是将这一行添加到我的setup.cfg
中:
[isort]
...
known_first_party = my_module
关于python - 使用 tox 错误排序导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36385671/