1

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

我的问题是我无法通过这些检查:在我的电脑上,没有投诉。但是在 Travis 上,我总是收到以下错误

$ 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

(...)

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

4

1 回答 1

4

在您的计算机上获取这些错误

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

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

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

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
于 2017-11-11T09:43:58.253 回答