[Lint] Update linter version and fix issues

Notable changes:

* Prettier >=2.3 with more consistent js assignments
* Black now formats docstrings
* Added isort to list of autoformaters
* Update flake8 config for v4

Ref: https://prettier.io/blog/2021/05/09/2.3.0.html
This commit is contained in:
Calum Lind 2022-02-13 12:31:41 +00:00
parent 2bd095e5bf
commit 2ec6e10c8e
No known key found for this signature in database
GPG Key ID: 90597A687B836BA3
35 changed files with 129 additions and 156 deletions

View File

@ -6,30 +6,32 @@ exclude: >
deluge/tests/data/.*svg|
)$
repos:
- repo: https://github.com/ambv/black
rev: 20.8b1
- repo: https://github.com/psf/black
rev: 22.1.0
hooks:
- id: black
name: Fmt Black
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.2.1
rev: v2.5.1
hooks:
- id: prettier
name: Fmt Prettier
# Workaround to list modified files only.
args: [--list-different]
- repo: https://gitlab.com/pycqa/flake8
# v3.7.9 due to E402 issue: https://gitlab.com/pycqa/flake8/-/issues/638
rev: 3.7.9
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
name: Fmt isort
- repo: https://github.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
name: Chk Flake8
additional_dependencies:
- flake8-isort==4.0.0
- pep8-naming==0.11.1
args: [--isort-show-traceback]
- pep8-naming==0.12.1
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v4.1.0
hooks:
- id: double-quote-string-fixer
name: Fix Double-quotes
@ -42,7 +44,7 @@ repos:
- id: trailing-whitespace
name: Fix Trailing whitespace
- repo: https://github.com/asottile/pyupgrade
rev: v2.29.1
rev: v2.31.0
hooks:
- id: pyupgrade
args: [--py36-plus]

View File

@ -106,8 +106,8 @@ class DelugeTextHelpFormatter(argparse.RawDescriptionHelpFormatter):
line instead. This way list formatting is not mangled by textwrap.wrap.
"""
wrapped_lines = []
for l in text.splitlines():
wrapped_lines.extend(textwrap.wrap(l, width, subsequent_indent=' '))
for line in text.splitlines():
wrapped_lines.extend(textwrap.wrap(line, width, subsequent_indent=' '))
return wrapped_lines
def _format_action_invocation(self, action):
@ -199,7 +199,7 @@ class ArgParserBase(argparse.ArgumentParser):
self.group.add_argument(
'-L',
'--loglevel',
choices=[l for k in deluge.log.levels for l in (k, k.upper())],
choices=[level for k in deluge.log.levels for level in (k, k.upper())],
help=_('Set the log level (none, error, warning, info, debug)'),
metavar='<level>',
)

View File

@ -436,22 +436,22 @@ def fsize(fsize_b, precision=1, shortform=False):
"""
if fsize_b >= 1024 ** 4:
if fsize_b >= 1024**4:
return '%.*f %s' % (
precision,
fsize_b / 1024 ** 4,
fsize_b / 1024**4,
tib_txt_short if shortform else tib_txt,
)
elif fsize_b >= 1024 ** 3:
elif fsize_b >= 1024**3:
return '%.*f %s' % (
precision,
fsize_b / 1024 ** 3,
fsize_b / 1024**3,
gib_txt_short if shortform else gib_txt,
)
elif fsize_b >= 1024 ** 2:
elif fsize_b >= 1024**2:
return '%.*f %s' % (
precision,
fsize_b / 1024 ** 2,
fsize_b / 1024**2,
mib_txt_short if shortform else mib_txt,
)
elif fsize_b >= 1024:
@ -503,28 +503,28 @@ def fspeed(bps, precision=1, shortform=False):
"""
if bps < 1024 ** 2:
if bps < 1024**2:
return '%.*f %s' % (
precision,
bps / 1024,
_('K/s') if shortform else _('KiB/s'),
)
elif bps < 1024 ** 3:
elif bps < 1024**3:
return '%.*f %s' % (
precision,
bps / 1024 ** 2,
bps / 1024**2,
_('M/s') if shortform else _('MiB/s'),
)
elif bps < 1024 ** 4:
elif bps < 1024**4:
return '%.*f %s' % (
precision,
bps / 1024 ** 3,
bps / 1024**3,
_('G/s') if shortform else _('GiB/s'),
)
else:
return '%.*f %s' % (
precision,
bps / 1024 ** 4,
bps / 1024**4,
_('T/s') if shortform else _('TiB/s'),
)
@ -639,17 +639,17 @@ def tokenize(text):
size_units = [
{'prefix': 'b', 'divider': 1, 'singular': 'byte', 'plural': 'bytes'},
{'prefix': 'KiB', 'divider': 1024 ** 1},
{'prefix': 'MiB', 'divider': 1024 ** 2},
{'prefix': 'GiB', 'divider': 1024 ** 3},
{'prefix': 'TiB', 'divider': 1024 ** 4},
{'prefix': 'PiB', 'divider': 1024 ** 5},
{'prefix': 'KB', 'divider': 1000 ** 1},
{'prefix': 'MB', 'divider': 1000 ** 2},
{'prefix': 'GB', 'divider': 1000 ** 3},
{'prefix': 'TB', 'divider': 1000 ** 4},
{'prefix': 'PB', 'divider': 1000 ** 5},
{'prefix': 'm', 'divider': 1000 ** 2},
{'prefix': 'KiB', 'divider': 1024**1},
{'prefix': 'MiB', 'divider': 1024**2},
{'prefix': 'GiB', 'divider': 1024**3},
{'prefix': 'TiB', 'divider': 1024**4},
{'prefix': 'PiB', 'divider': 1024**5},
{'prefix': 'KB', 'divider': 1000**1},
{'prefix': 'MB', 'divider': 1000**2},
{'prefix': 'GB', 'divider': 1000**3},
{'prefix': 'TB', 'divider': 1000**4},
{'prefix': 'PB', 'divider': 1000**5},
{'prefix': 'm', 'divider': 1000**2},
]

View File

@ -231,7 +231,7 @@ class Config:
self._save_timer = self.callLater(5, self.save)
def __getitem__(self, key):
"""See get_item """
"""See get_item"""
return self.get_item(key)
def get_item(self, key):

View File

@ -198,7 +198,7 @@ class PreferencesManager(component.Component):
self.__set_listen_on()
def __set_listen_on(self):
""" Set the ports and interface address to listen for incoming connections on."""
"""Set the ports and interface address to listen for incoming connections on."""
if self.config['random_port']:
if not self.config['listen_random_port']:
self.config['listen_random_port'] = random.randrange(49152, 65525)

View File

@ -576,7 +576,7 @@ class Torrent:
trackers (list of dicts): A list of trackers.
"""
if trackers is None:
self.trackers = [tracker for tracker in self.handle.trackers()]
self.trackers = list(self.handle.trackers())
self.tracker_host = None
return

View File

@ -42,22 +42,21 @@ Deluge.ux.preferences.AutoAddPage = Ext.extend(Ext.Panel, {
dataIndex: 'enabled',
tpl: new Ext.XTemplate('{enabled:this.getCheckbox}', {
getCheckbox: function (checked, selected) {
Deluge.ux.AutoAdd.onClickFunctions[
selected.id
] = function () {
if (selected.enabled) {
deluge.client.autoadd.disable_watchdir(
selected.id
);
checked = false;
} else {
deluge.client.autoadd.enable_watchdir(
selected.id
);
checked = true;
}
autoAdd.updateWatchDirs();
};
Deluge.ux.AutoAdd.onClickFunctions[selected.id] =
function () {
if (selected.enabled) {
deluge.client.autoadd.disable_watchdir(
selected.id
);
checked = false;
} else {
deluge.client.autoadd.enable_watchdir(
selected.id
);
checked = true;
}
autoAdd.updateWatchDirs();
};
return (
'<input id="enabled-' +
selected.id +

View File

@ -90,9 +90,8 @@ Deluge.ux.AutoAdd.AutoAddWindowBase = Ext.extend(Ext.Window, {
options['enabled'] = Ext.getCmp('enabled').getValue();
options['path'] = Ext.getCmp('path').getValue();
options['download_location'] = Ext.getCmp(
'download_location'
).getValue();
options['download_location'] =
Ext.getCmp('download_location').getValue();
options['move_completed_path'] = Ext.getCmp(
'move_completed_path'
).getValue();

View File

@ -16,7 +16,7 @@ import os
import gi # isort:skip (Required before Gtk import).
gi.require_version('Gtk', '3.0') # NOQA: E402
gi.require_version('Gtk', '3.0')
# isort:imports-thirdparty
from gi.repository import Gtk

View File

@ -11,7 +11,7 @@ from datetime import datetime
import gi # isort:skip (Required before Gtk import).
gi.require_version('Gtk', '3.0') # NOQA: E402
gi.require_version('Gtk', '3.0')
# isort:imports-thirdparty
from gi.repository import Gtk

View File

@ -10,7 +10,7 @@ import logging
import gi # isort:skip (Required before Gtk import).
gi.require_version('Gtk', '3.0') # NOQA: E402
gi.require_version('Gtk', '3.0')
# isort:imports-thirdparty
from gi.repository import Gtk

View File

@ -14,7 +14,7 @@ import logging
import gi # isort:skip (Required before Gtk import).
gi.require_version('Gtk', '3.0') # NOQA: E402
gi.require_version('Gtk', '3.0')
# isort:imports-thirdparty
from gi.repository import Gtk

View File

@ -148,8 +148,7 @@ Deluge.ux.LabelOptionsWindow = Ext.extend(Ext.Window, {
xtype: 'fieldset',
border: false,
labelWidth: 1,
style:
'margin-bottom: 0px; padding-bottom: 0px;',
style: 'margin-bottom: 0px; padding-bottom: 0px;',
items: [
{
xtype: 'checkbox',
@ -218,8 +217,7 @@ Deluge.ux.LabelOptionsWindow = Ext.extend(Ext.Window, {
xtype: 'fieldset',
border: false,
labelWidth: 1,
style:
'margin-bottom: 0px; padding-bottom: 0px;',
style: 'margin-bottom: 0px; padding-bottom: 0px;',
items: [
{
xtype: 'checkbox',
@ -260,8 +258,7 @@ Deluge.ux.LabelOptionsWindow = Ext.extend(Ext.Window, {
width: 60,
decimalPrecision: 2,
incrementValue: 0.1,
style:
'position: relative; left: 100px',
style: 'position: relative; left: 100px',
disabled: true,
},
{
@ -285,8 +282,7 @@ Deluge.ux.LabelOptionsWindow = Ext.extend(Ext.Window, {
xtype: 'fieldset',
border: false,
labelWidth: 1,
style:
'margin-bottom: 0px; padding-bottom: 0px;',
style: 'margin-bottom: 0px; padding-bottom: 0px;',
items: [
{
xtype: 'checkbox',
@ -339,8 +335,7 @@ Deluge.ux.LabelOptionsWindow = Ext.extend(Ext.Window, {
xtype: 'fieldset',
border: false,
labelWidth: 1,
style:
'margin-bottom: 0px; padding-bottom: 0px;',
style: 'margin-bottom: 0px; padding-bottom: 0px;',
items: [
{
xtype: 'checkbox',
@ -408,9 +403,8 @@ Deluge.ux.LabelOptionsWindow = Ext.extend(Ext.Window, {
onOkClick: function () {
var values = this.form.getForm().getFieldValues();
if (values['auto_add_trackers']) {
values['auto_add_trackers'] = values['auto_add_trackers'].split(
'\n'
);
values['auto_add_trackers'] =
values['auto_add_trackers'].split('\n');
}
deluge.client.label.set_options(this.label, values);
this.hide();

View File

@ -11,7 +11,7 @@ import logging
import gi # isort:skip (Required before Gtk import).
gi.require_version('Gtk', '3.0') # NOQA: E402
gi.require_version('Gtk', '3.0')
# isort:imports-thirdparty
from gi.repository import Gtk

View File

@ -19,7 +19,7 @@ import time
import gi
gi.require_foreign('cairo') # NOQA: E402
gi.require_foreign('cairo')
import cairo # isort:skip (gi checks required before import).

View File

@ -153,7 +153,7 @@ class ProcessOutputHandler(protocol.ProcessProtocol):
return result
def _kill_watchdogs(self):
""""Cancel all watchdogs"""
"""Cancel all watchdogs"""
for w in self.watchdogs:
if not w.called and not w.cancelled:
w.cancel()

View File

@ -184,10 +184,10 @@ class TestCommon:
('1 MiB', 2 ** (10 * 2)),
('1 GiB', 2 ** (10 * 3)),
('1 GiB', 2 ** (10 * 3)),
('1M', 10 ** 6),
('1MB', 10 ** 6),
('1 GB', 10 ** 9),
('1 TB', 10 ** 12),
('1M', 10**6),
('1MB', 10**6),
('1 GB', 10**9),
('1 TB', 10**12),
]
for human_size, byte_size in sizes:

View File

@ -44,8 +44,8 @@ class TestFilesTab(BaseTestCase):
root = treestore.get_iter_first()
level = 1
def p_level(s, l):
print('{}{}'.format(' ' * l, s))
def p_level(s, lvl):
print('{}{}'.format(' ' * lvl, s))
def _print_treestore_children(i, lvl):
while i:

View File

@ -175,7 +175,7 @@ class Command(BaseCommand):
sort_key = 'name'
sort_reverse = False
for key, value in sorted(
list(status.items()),
status.items(),
key=lambda x: x[1].get(sort_key),
reverse=sort_reverse,
):

View File

@ -84,7 +84,7 @@ class CursesStdIO:
"""
def fileno(self):
""" We want to select on FD 0 """
"""We want to select on FD 0"""
return 0
def doRead(self): # NOQA: N802

View File

@ -235,11 +235,11 @@ def wrap_string(string, width, min_lines=0, strip_colors=True):
else:
cstr = s
def append_indent(l, string, offset):
def append_indent(line, string, offset):
"""Prepends indent to string if specified"""
if indent and offset != 0:
string = indent + string
l.append(string)
line.append(string)
while cstr:
# max with for a line. If indent is specified, we account for this

View File

@ -12,7 +12,7 @@ import os.path
import gi # isort:skip (Required before Gtk import).
gi.require_version('Gtk', '3.0') # NOQA: E402
gi.require_version('Gtk', '3.0')
# isort:imports-thirdparty
from gi.repository import Gio, Gtk

View File

@ -15,8 +15,8 @@ import time
import gi # isort:skip (Required before Gtk import).
gi.require_version('Gtk', '3.0') # NOQA: E402
gi.require_version('Gdk', '3.0') # NOQA: E402
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
# isort:imports-thirdparty
from gi.repository.GLib import set_prgname

View File

@ -76,7 +76,7 @@ class ListView:
}
def __init__(self, title=None, cell_renderer=None, **args):
""" Constructor, see Gtk.TreeViewColumn """
"""Constructor, see Gtk.TreeViewColumn"""
Gtk.TreeViewColumn.__init__(self, title, cell_renderer, **args)
label = Gtk.Label(label=title)
self.set_widget(label)

View File

@ -1405,7 +1405,7 @@ class PathChooserComboBox(Gtk.Box, StoredValuesPopup, GObject.GObject):
self.set_text(self.get_text())
def _on_entry_combobox_hbox_realize(self, widget):
""" Must do this when the widget is realized """
"""Must do this when the widget is realized"""
self.set_filechooser_button_visible(self.filechooser_visible)
self.set_path_entry_visible(self.path_entry_visible)

View File

@ -10,9 +10,9 @@ from math import pi
import gi # isort:skip (Version check required before import).
gi.require_version('PangoCairo', '1.0') # NOQA: E402
gi.require_foreign('cairo') # NOQA: E402
gi.require_version('cairo', '1.0') # NOQA: E402
gi.require_version('PangoCairo', '1.0')
gi.require_foreign('cairo')
gi.require_version('cairo', '1.0')
# isort:imports-thirdparty
import cairo # Backward compat cairo <= 1.15

View File

@ -19,6 +19,7 @@ from gi.repository.Gdk import Color
import deluge.common
import deluge.component as component
from deluge.configmanager import ConfigManager, get_config_dir
from deluge.decorators import maybe_coroutine
from deluge.error import AuthManagerError, NotAuthorizedError
from deluge.i18n import get_languages
from deluge.ui.client import client
@ -1337,8 +1338,6 @@ class Preferences(component.Component):
self.builder.get_object('accounts_edit').set_sensitive(False)
self.builder.get_object('accounts_delete').set_sensitive(False)
from deluge.decorators import maybe_coroutine
@maybe_coroutine
async def on_accounts_add_clicked(self, widget):
dialog = AccountDialog(

View File

@ -104,8 +104,7 @@ Deluge.about.AboutWindow = Ext.extend(Ext.Window, {
{
xtype: 'label',
style: 'padding-top: 5px; font-size: 12px;',
html:
'<a href="https://deluge-torrent.org" target="_blank">deluge-torrent.org</a>',
html: '<a href="https://deluge-torrent.org" target="_blank">deluge-torrent.org</a>',
},
]);
this.addButton(_('Close'), this.onCloseClick, this);

View File

@ -10,7 +10,8 @@
Ext.ns('Deluge');
// Custom VType validator for tracker urls
var trackerUrlTest = /(((^https?)|(^udp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
var trackerUrlTest =
/(((^https?)|(^udp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
Ext.apply(Ext.form.VTypes, {
trackerUrl: function (val, field) {
return trackerUrlTest.test(val);

View File

@ -134,9 +134,8 @@ Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
nodes,
function (node) {
if (node.attributes.fileindex < 0) return;
var priorities = this.form.optionsManager.get(
'file_priorities'
);
var priorities =
this.form.optionsManager.get('file_priorities');
priorities[node.attributes.fileindex] = newValue;
this.form.optionsManager.update('file_priorities', priorities);
},

View File

@ -117,8 +117,7 @@ Deluge.preferences.Bandwidth = Ext.extend(Ext.form.FormPanel, {
border: false,
title: '',
defaultType: 'checkbox',
style:
'padding-top: 0px; padding-bottom: 5px; margin-top: 0px; margin-bottom: 0px;',
style: 'padding-top: 0px; padding-bottom: 5px; margin-top: 0px; margin-bottom: 0px;',
autoHeight: true,
});
om.bind(

View File

@ -80,9 +80,8 @@ Ext.ux.form.SpinnerGroup = Ext.extend(Ext.form.CheckboxGroup, {
// Generate the column configs with the correct width setting
for (var i = 0; i < numCols; i++) {
var cc = Ext.apply({ items: [] }, colCfg);
cc[
this.columns[i] <= 1 ? 'columnWidth' : 'width'
] = this.columns[i];
cc[this.columns[i] <= 1 ? 'columnWidth' : 'width'] =
this.columns[i];
if (this.defaults) {
cc.defaults = Ext.apply(
cc.defaults || {},

View File

@ -1,12 +1,15 @@
# -*- mode: python ; coding: utf-8 -*-
# -*- mode: python -*-
import os
import sys
import deluge.common
from PyInstaller.utils.hooks import collect_data_files, collect_submodules, copy_metadata
from PyInstaller.utils.hooks import (
collect_data_files,
collect_submodules,
copy_metadata,
)
datas = []
binaries = []
hiddenimports = ['pygame','ifaddr']
hiddenimports = ['pygame', 'ifaddr']
# Collect Meta Data
datas += copy_metadata('deluge', recursive=True)
@ -16,7 +19,8 @@ datas += copy_metadata('service-identity', recursive=True)
hiddenimports += collect_submodules('deluge')
# Add stdlib as Hidden Imports.
# This is filtered list that excludes some common examples or stuff not useful in plugins (such as tty, mailbox, turtledemo etc.).
# This is filtered list that excludes some common examples or stuff not useful in
# plugins (such as tty, mailbox, turtledemo etc.).
# It is safe to assume that 90% of that list would already be included anyway.
stdlib = [
'string',
@ -108,46 +112,22 @@ icon = [src for src, dest in package_data if src.endswith('deluge.ico')][0]
# List of executables to produce
executables = {
'deluge-script.pyw': {
'name': 'deluge',
'console': False,
'gtk': True,
},
'deluge-gtk-script.pyw': {
'name': 'deluge-gtk',
'console': False,
'gtk': True,
},
'deluge-debug-script.py': {
'name': 'deluge-debug',
'console': True,
'gtk': True,
},
'deluge-script.pyw': {'name': 'deluge', 'console': False, 'gtk': True},
'deluge-gtk-script.pyw': {'name': 'deluge-gtk', 'console': False, 'gtk': True},
'deluge-debug-script.py': {'name': 'deluge-debug', 'console': True, 'gtk': True},
'deluge-console-script.py': {
'name': 'deluge-console',
'console': True,
'gtk': False,
},
'deluged-script.pyw': {
'name': 'deluged',
'console': False,
'gtk': False,
},
'deluged-debug-script.py': {
'name': 'deluged-debug',
'console': True,
'gtk': False,
},
'deluged-script.pyw': {'name': 'deluged', 'console': False, 'gtk': False},
'deluged-debug-script.py': {'name': 'deluged-debug', 'console': True, 'gtk': False},
'deluge-web-debug-script.py': {
'name': 'deluge-web-debug',
'console': True,
'gtk': False,
},
'deluge-web-script.pyw': {
'name': 'deluge-web',
'console': False,
'gtk': False,
},
'deluge-web-script.pyw': {'name': 'deluge-web', 'console': False, 'gtk': False},
}
analysis = {}

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2012-2015 Calum Lind <calumlind@gmail.com>
# Copyright (C) 2010 Damien Churchill <damoxc@gmail.com>

View File

@ -27,15 +27,19 @@ frameworks = CoreFoundation, Foundation, AppKit
[flake8]
max-line-length = 120
builtins = _,_n,__request__
exclude = .git,.tox,.eggs,dist,build
ignore =
# A003 Class attribute is a python builtin.
extend-exclude = dist,build
extend-ignore =
# flake8-builtins: A003 class attribute is shadowing a python builtin
A003,
# C813, C815, C816: PY3 missing trailing commas.
C813,C815,C816,
# W503 line break before binary operator.
W503,
E203
# E203 whitespace before ':'
E203,
# N818 pep8-naming: error suffix in exception names
N818
per-file-ignores =
# import not top of file (gi checks required before import)
deluge/ui/gtk3/*.py : E402
deluge/**/gtkui.py: E402
deluge/**/gtkui/*.py: E402
deluge/plugins/Stats/deluge_stats/graph.py: E402
[pycodestyle]
max-line-length = 88