我试图对django-rest框架做出贡献,在运行isort
之后,身份验证文件中的导入如下(我添加了导入6):
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'
发布于 2016-04-03 13:03:27
根据我在REST框架源代码(例如这里)中看到的,six
是从django.utils
导入的。将import six
替换为from django.utils import six
应该解决isort
警告:
from __future__ import unicode_literals
import base64
from django.utils 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
发布于 2018-01-01 10:42:25
我遇到了一个类似的错误(Imports are incorrectly sorted
)。
isort
在直接运行时很高兴,在通过tox
运行时失败。isort
抱怨的台词是:
import pytest
from my_module import MyThing
当isort
直接运行时,它知道我的模块my_module
是第一个(我自己的)代码,而通过tox
则不是,所以当直接运行时,它对pytest
导入和我的导入之间的空行很满意,但是通过tox
它不想看到空行,因为pytest
和my_module
都被解释为第三方导入。
解决方案是将这一行添加到我的setup.cfg
中
[isort]
...
known_first_party = my_module
https://stackoverflow.com/questions/36385671
复制相似问题