Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用tox错误订购进口产品_Python_Django Rest Framework_Pep8_Tox - Fatal编程技术网

Python 使用tox错误订购进口产品

Python 使用tox错误订购进口产品,python,django-rest-framework,pep8,tox,Python,Django Rest Framework,Pep8,Tox,我正试图对django rest框架做出贡献,在我运行isort之后,身份验证文件中的导入如下(我添加了导入六个): 当我运行/runtests--lintonly时,它通过了所有测试,但当我运行tox时,它会给出以下错误: py27-lint runtests: commands[0] | ./runtests.py --lintonly Running flake8 code linting flake8 passed Running isort code checking ERROR: /

我正试图对django rest框架做出贡献,在我运行
isort
之后,身份验证文件中的导入如下(我添加了导入六个):

当我运行
/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'

从我在REST框架源代码(例如)中看到的情况来看,
six
是从
django.utils
导入的。将
import six
替换为来自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

我遇到了类似的错误(
导入的排序不正确

isort
直接运行时很高兴,通过
tox运行时失败。
isort
抱怨的行是:

import pytest

from my_module import MyThing
isort
直接运行时,知道我的模块
my_模块
是第一方(我自己的)代码,而via
tox
则不知道。因此,当直接运行时,它对
pytest
import和my import之间的空行感到满意,但通过
tox
它不想看到空行,因为
pytest
my_module
都被解释为第三方导入

解决方案是将此行添加到我的
setup.cfg

[isort]
...
known_first_party = my_module

您能分享一下您添加到django rest框架的代码吗。它可能会帮助我重现问题并找到解决方案。@Vinit它几乎只有两行,
import six
,并在authentication.py中将
type(“”)
替换为
six.string\u types
[isort]
...
known_first_party = my_module