不提高I201和I202就无法通过flake8-import-order

时间:2017-11-11 08:50:38

标签: python flake8

我目前正在为一个很酷的小python项目做贡献,名为PhotoCollage,维护者请求贡献者在考虑拉取请求之前通过flake8检查(足够公平)。

我的问题是我无法通过这些检查:在我的电脑上,没有投诉。但在特拉维斯,我总是get the following errors

$ flake8 .
./photocollage/gtkgui.py:29:1: I202 Additional newline in a section of imports.
./photocollage/gtkgui.py:32:1: I202 Additional newline in a section of imports.
./photocollage/render.py:25:1: I202 Additional newline in a section of imports.

The command "flake8 ." exited with 1.

但是,我的代码如下所示:

gtkgui.py

# -*- coding: utf-8 -*-
# Copyright (C) 2013 Adrien Vergé
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import copy
import gettext
from io import BytesIO
import math
import os.path
import random
import sys

import cairo
import gi
gi.require_version('Gtk', '3.0')  # noqa
from gi.repository import Gtk, Gdk, GObject, GdkPixbuf
from six.moves import urllib  # Python 2 backward compatibility

from photocollage import APP_NAME, artwork, collage, render
from photocollage.render import PIL_SUPPORTED_EXTS as EXTS


gettext.textdomain(APP_NAME)
_ = gettext.gettext
_n = gettext.ngettext

(...)

我没有改变进口wrt。以前的提交,所以我怀疑flake8-import-order以某种方式改变了。有什么想法吗?

1 个答案:

答案 0 :(得分:4)

要在您的计算机上出现这些错误

尝试使用最新版本的flake8flake8-import-order

pip3 install --user --upgrade flake8 flake8-import-order

此外,由于这是Python 3项目,您使用Python 3运行flake8吗?根据您的操作系统,运行命令可以是:

flake8 .

python3 -m flake8 .

关于这些新错误

你是对的:flake8-import-order最近似乎发生了变化,现在发现了误报。由于gi.repository设置导入版本的奇怪方式(gi.require_version()必须在导入之间调用)。

我想除了在这些特定行上禁用这些flake8规则之外,您无能为力:

import gi
gi.require_version('Gtk', '3.0')  # noqa: E402
from gi.repository import Gtk, Gdk, GObject, GdkPixbuf  # noqa: I202