2016-04-03 36 views
1

正确排序进口我试图做出了贡献,以Django的REST的架构,在认证文件进口我跑isort后都是这样的(我已经添加进口6位):使用TOX

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' 
+0

你能分享你添加到Django的REST框架哪些代码。它可以帮助我重现问题并找到解决方案。 –

+0

@Vinit这几乎是2行,'import six',并用authentication.py中的'six.string_types'替换type('')'。 – dnit13

回答

1

从我的REST框架源代码见(例如heresix从进口。与from django.utils import six更换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 
0

我遇到过类似的错误(Imports are incorrectly sorted)。

isort当直接运行时很高兴,当通过tox运行时发生故障。这是isort抱怨的线条是:

import pytest 

from my_module import MyThing 

isort,当直接运行,知道我的模块my_module是第一方(我自己)的代码,而通过tox它没有。因此,直接运行时,它对pytest导入与我的导入之间的空行感到满意,但通过tox它不希望看到空行,因为pytestmy_module都被解释为第三方导入。

的解决方案是这一行添加到我的setup.cfg

[isort] 
... 
known_first_party = my_module