[Lint] Fix flake8 3.7 warnings

- Fix new flake8 warnings from latest version.
  Note: The `addSlash` variable was orphaned with no reference in
        Twisted or Deluge code so removed.

- Update pre-commit config
  - New pinned versions.
  - Fix prettier output.
  - Use new flake8 hook config and add naming plugin.
This commit is contained in:
Calum Lind 2019-03-29 10:57:22 +00:00
commit c8b621172e
14 changed files with 41 additions and 45 deletions

View file

@ -10,12 +10,22 @@ repos:
name: Fmt Black name: Fmt Black
language_version: python3.6 language_version: python3.6
- repo: https://github.com/prettier/prettier - repo: https://github.com/prettier/prettier
rev: 1.15.2 rev: 1.16.4
hooks: hooks:
- id: prettier - id: prettier
name: Fmt Prettier name: Fmt Prettier
# Workaround to list modified files only.
args: [--list-different]
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.7
hooks:
- id: flake8
name: Chk Flake8
additional_dependencies:
- flake8-isort==2.7
- pep8-naming==0.8.2
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v1.4.0 rev: v2.1.0
hooks: hooks:
- id: double-quote-string-fixer - id: double-quote-string-fixer
name: Fix Double-quotes name: Fix Double-quotes
@ -27,7 +37,3 @@ repos:
args: [--fix=auto] args: [--fix=auto]
- id: trailing-whitespace - id: trailing-whitespace
name: Fix Trailing whitespace name: Fix Trailing whitespace
- id: flake8
name: Chk Flake8
additional_dependencies:
- flake8-isort==2.5

View file

@ -49,12 +49,12 @@ from codecs import getwriter
from io import open from io import open
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
import six.moves.cPickle as pickle import six.moves.cPickle as pickle # noqa: N813
from deluge.common import JSON_FORMAT, get_default_config_dir from deluge.common import JSON_FORMAT, get_default_config_dir
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
callLater = None # Necessary for the config tests callLater = None # noqa: N816 Necessary for the config tests
def prop(func): def prop(func):

View file

@ -17,7 +17,7 @@ import os
import time import time
from tempfile import gettempdir from tempfile import gettempdir
import six.moves.cPickle as pickle import six.moves.cPickle as pickle # noqa: N813
from twisted.internet import defer, error, reactor, threads from twisted.internet import defer, error, reactor, threads
from twisted.internet.defer import Deferred, DeferredList from twisted.internet.defer import Deferred, DeferredList
from twisted.internet.task import LoopingCall from twisted.internet.task import LoopingCall
@ -128,7 +128,7 @@ class TorrentManager(component.Component):
""" """
callLater = reactor.callLater callLater = reactor.callLater # noqa: N815
def __init__(self): def __init__(self):
component.Component.__init__( component.Component.__init__(

View file

@ -31,7 +31,7 @@ del _
class LabelMenu(MenuItem): class LabelMenu(MenuItem):
def __init__(self): def __init__(self):
MenuItem.__init__(self, _('Label')) MenuItem.__init__(self, _('Label')) # noqa: F821
self.sub_menu = Menu() self.sub_menu = Menu()
self.set_submenu(self.sub_menu) self.set_submenu(self.sub_menu)
@ -52,7 +52,7 @@ class LabelMenu(MenuItem):
self.sub_menu.remove(child) self.sub_menu.remove(child)
for label in [NO_LABEL] + list(labels): for label in [NO_LABEL] + list(labels):
if label == NO_LABEL: if label == NO_LABEL:
item = MenuItem(_(NO_LABEL)) item = MenuItem(_(NO_LABEL)) # noqa: F821
else: else:
item = MenuItem(label.replace('_', '__')) item = MenuItem(label.replace('_', '__'))
item.connect('activate', self.on_select_label, label) item.connect('activate', self.on_select_label, label)

View file

@ -68,9 +68,6 @@ class RedirectResource(Resource):
class TopLevelResource(Resource): class TopLevelResource(Resource):
addSlash = True
def __init__(self): def __init__(self):
Resource.__init__(self) Resource.__init__(self)
self.putChild(b'cookie', CookieResource()) self.putChild(b'cookie', CookieResource())

View file

@ -91,9 +91,6 @@ class PartialDownloadResource(Resource):
class TopLevelResource(Resource): class TopLevelResource(Resource):
addSlash = True
def __init__(self): def __init__(self):
Resource.__init__(self) Resource.__init__(self)
self.putChild(b'cookie', CookieResource()) self.putChild(b'cookie', CookieResource())

View file

@ -19,8 +19,8 @@ from zope.interface import implements
class _Reporter(object): class _Reporter(object):
implements(IPlugin, IReporter) implements(IPlugin, IReporter)
def __init__( # NOQA: N803 def __init__(
self, name, module, description, longOpt, shortOpt, klass self, name, module, description, longOpt, shortOpt, klass # noqa: N803
): ):
self.name = name self.name = name
self.module = module self.module = module

View file

@ -15,7 +15,7 @@ import os
import shutil import shutil
import sys import sys
import six.moves.cPickle as pickle import six.moves.cPickle as pickle # noqa: N813
from gi.repository.Gdk import SELECTION_CLIPBOARD from gi.repository.Gdk import SELECTION_CLIPBOARD
from gi.repository.GdkPixbuf import Colorspace, Pixbuf from gi.repository.GdkPixbuf import Colorspace, Pixbuf
from gi.repository.GLib import GError from gi.repository.GLib import GError

View file

@ -12,7 +12,7 @@ from __future__ import division, unicode_literals
import logging import logging
import os.path import os.path
import six.moves.cPickle as pickle import six.moves.cPickle as pickle # noqa: N813
from gi.repository import Gio, Gtk from gi.repository import Gio, Gtk
from gi.repository.Gdk import DragAction, ModifierType, keyval_name from gi.repository.Gdk import DragAction, ModifierType, keyval_name
from gi.repository.GObject import TYPE_UINT64 from gi.repository.GObject import TYPE_UINT64

View file

@ -90,7 +90,7 @@ class PathChoosersHandler(component.Component):
chooser.config_key_funcs[key][1](value) chooser.config_key_funcs[key][1](value)
# Save to core # Save to core
if key is not 'path_chooser_max_popup_rows': if key != 'path_chooser_max_popup_rows':
client.core.set_config({key: value}) client.core.set_config({key: value})
else: else:
# Since the max rows value can be changed fast with a spinbutton, we # Since the max rows value can be changed fast with a spinbutton, we

View file

@ -1237,7 +1237,7 @@ class PathChooserComboBox(Gtk.Box, StoredValuesPopup, GObject.GObject):
folder_name = '' folder_name = ''
if self.show_folder_name_on_button or not self.path_entry_visible: if self.show_folder_name_on_button or not self.path_entry_visible:
folder_name = path_without_trailing_path_sep(text) folder_name = path_without_trailing_path_sep(text)
if folder_name is not '/' and os.path.basename(folder_name): if folder_name != '/' and os.path.basename(folder_name):
folder_name = os.path.basename(folder_name) folder_name = os.path.basename(folder_name)
self.folder_name_label.set_text(folder_name) self.folder_name_label.set_text(folder_name)
# Only trigger event if text has changed # Only trigger event if text has changed

View file

@ -267,9 +267,7 @@ Deluge.ConnectionManager = Ext.extend(Ext.Window, {
} }
var id = selected.id; var id = selected.id;
deluge.client.web.connect( deluge.client.web.connect(id, {
id,
{
success: function(methods) { success: function(methods) {
deluge.client.reloadMethods(); deluge.client.reloadMethods();
deluge.client.on( deluge.client.on(
@ -281,8 +279,7 @@ Deluge.ConnectionManager = Ext.extend(Ext.Window, {
{ single: true } { single: true }
); );
}, },
} });
);
this.hide(); this.hide();
} }
}, },

View file

@ -438,7 +438,6 @@ class ScriptResource(resource.Resource, component.Component):
class TopLevel(resource.Resource): class TopLevel(resource.Resource):
addSlash = True
__stylesheets = [ __stylesheets = [
'css/ext-all-notheme.css', 'css/ext-all-notheme.css',

View file

@ -154,7 +154,7 @@ for script in script_list:
os.remove(script) os.remove(script)
# Exclude files which are already included in GTK or Windows. Also exclude unneeded pygame dlls. # Exclude files which are already included in GTK or Windows. Also exclude unneeded pygame dlls.
excludeDlls = ( exclude_dlls = (
'MSIMG32.dll', 'MSIMG32.dll',
'MSVCR90.dll', 'MSVCR90.dll',
'MSVCP90.dll', 'MSVCP90.dll',
@ -170,7 +170,7 @@ excludeDlls = (
'SDL_image.dll', 'SDL_image.dll',
'SDL_ttf.dll', 'SDL_ttf.dll',
) )
for exclude_dll in excludeDlls: for exclude_dll in exclude_dlls:
try: try:
os.remove(os.path.join(build_dir, exclude_dll)) os.remove(os.path.join(build_dir, exclude_dll))
except OSError: except OSError:
@ -224,14 +224,14 @@ for script in script_list:
script_exe = os.path.splitext(os.path.basename(script))[0] + '.exe' script_exe = os.path.splitext(os.path.basename(script))[0] + '.exe'
# Don't add to dev build versions. # Don't add to dev build versions.
if not re.search('[a-zA-Z_-]', build_version): if not re.search('[a-zA-Z_-]', build_version):
versionInfo = VersionInfo( version_info = VersionInfo(
build_version, build_version,
description='Deluge Bittorrent Client', description='Deluge Bittorrent Client',
company='Deluge Team', company='Deluge Team',
product='Deluge', product='Deluge',
_copyright='Deluge Team', _copyright='Deluge Team',
) )
stamp(os.path.join(build_dir, script_exe), versionInfo) stamp(os.path.join(build_dir, script_exe), version_info)
# Copy version info to file for nsis script. # Copy version info to file for nsis script.
with open('VERSION.tmp', 'w') as ver_file: with open('VERSION.tmp', 'w') as ver_file: