Skip to content

Commit

Permalink
[Lint] Format code with ruff
Browse files Browse the repository at this point in the history
`pre-commit run --all-files`
  • Loading branch information
cas-- committed Sep 8, 2024
1 parent 2247668 commit 0d72195
Show file tree
Hide file tree
Showing 34 changed files with 148 additions and 132 deletions.
1 change: 1 addition & 0 deletions deluge/_libtorrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
>>> from deluge._libtorrent import lt
"""

from deluge.common import VersionSplit, get_version
from deluge.error import LibtorrentImportError

Expand Down
1 change: 1 addition & 0 deletions deluge/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#

"""Common functions for various parts of Deluge to use."""

import base64
import binascii
import functools
Expand Down
1 change: 1 addition & 0 deletions deluge/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
version as this will be done internally.
"""

import json
import logging
import os
Expand Down
1 change: 1 addition & 0 deletions deluge/core/alertmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
`:mod:EventManager` for similar functionality.
"""

import contextlib
import logging
import threading
Expand Down
1 change: 1 addition & 0 deletions deluge/core/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#

"""The Deluge daemon"""

import logging
import os
import socket
Expand Down
1 change: 1 addition & 0 deletions deluge/core/pluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


"""PluginManager for Core"""

import logging

from twisted.internet import defer
Expand Down
13 changes: 6 additions & 7 deletions deluge/core/rpcserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#

"""RPCServer Module"""

import logging
import os
import sys
Expand Down Expand Up @@ -46,13 +47,11 @@


@overload
def export(func: TCallable) -> TCallable:
...
def export(func: TCallable) -> TCallable: ...


@overload
def export(auth_level: int) -> Callable[[TCallable], TCallable]:
...
def export(auth_level: int) -> Callable[[TCallable], TCallable]: ...


def export(auth_level=AUTH_LEVEL_DEFAULT):
Expand Down Expand Up @@ -274,9 +273,9 @@ def send_error():
raise IncompatibleClient(deluge.common.get_version())
ret = component.get('AuthManager').authorize(*args, **kwargs)
if ret:
self.factory.authorized_sessions[
self.transport.sessionno
] = self.AuthLevel(ret, args[0])
self.factory.authorized_sessions[self.transport.sessionno] = (
self.AuthLevel(ret, args[0])
)
self.factory.session_protocols[self.transport.sessionno] = self
except Exception as ex:
send_error()
Expand Down
23 changes: 10 additions & 13 deletions deluge/core/torrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,9 +1138,8 @@ def _create_status_funcs(self):
'download_location': lambda: self.options['download_location'],
'seeds_peers_ratio': lambda: -1.0
if self.status.num_incomplete == 0
else ( # Use -1.0 to signify infinity
self.status.num_complete / self.status.num_incomplete
),
# Use -1.0 to signify infinity
else (self.status.num_complete / self.status.num_incomplete),
'seed_rank': lambda: self.status.seed_rank,
'state': lambda: self.state,
'stop_at_ratio': lambda: self.options['stop_at_ratio'],
Expand Down Expand Up @@ -1544,20 +1543,18 @@ def _get_pieces_info(self):
self.status.pieces, self.handle.piece_availability()
):
if piece:
pieces.append(3) # Completed.
# Completed.
pieces.append(3)
elif avail_piece:
pieces.append(
1
) # Available, just not downloaded nor being downloaded.
# Available, just not downloaded nor being downloaded.
pieces.append(1)
else:
pieces.append(
0
) # Missing, no known peer with piece, or not asked for yet.
# Missing, no known peer with piece, or not asked for yet.
pieces.append(0)

for peer_info in self.handle.get_peer_info():
if peer_info.downloading_piece_index >= 0:
pieces[
peer_info.downloading_piece_index
] = 2 # Being downloaded from peer.
# Being downloaded from peer.
pieces[peer_info.downloading_piece_index] = 2

return pieces
1 change: 1 addition & 0 deletions deluge/core/torrentmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#

"""TorrentManager handles Torrent objects"""

import datetime
import logging
import operator
Expand Down
2 changes: 1 addition & 1 deletion deluge/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def addCallbacks(self, *args, **kwargs): # noqa: N802


def maybe_coroutine(
f: Callable[..., Coroutine[Any, Any, _RetT]]
f: Callable[..., Coroutine[Any, Any, _RetT]],
) -> 'Callable[..., defer.Deferred[_RetT]]':
"""Wraps a coroutine function to make it usable as a normal function that returns a Deferred."""

Expand Down
1 change: 1 addition & 0 deletions deluge/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
and subsequently emitted to the clients.
"""

known_events = {}


Expand Down
1 change: 1 addition & 0 deletions deluge/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#

"""Logging functions"""

import inspect
import logging
import logging.handlers
Expand Down
1 change: 1 addition & 0 deletions deluge/pluginmanagerbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


"""PluginManagerBase"""

import email
import logging
import os.path
Expand Down
2 changes: 1 addition & 1 deletion deluge/plugins/AutoAdd/deluge_autoadd/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def on_torrent_added(torrent_id, filename, filepath):
if 'Label' in component.get('CorePluginManager').get_enabled_plugins():
if watchdir.get('label_toggle', True) and watchdir.get('label'):
label = component.get('CorePlugin.Label')
if not watchdir['label'] in label.get_labels():
if watchdir['label'] not in label.get_labels():
label.add(watchdir['label'])
try:
label.set_torrent(torrent_id, watchdir['label'])
Expand Down
3 changes: 2 additions & 1 deletion deluge/plugins/Label/deluge_label/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
torrent-label core plugin.
adds a status field for tracker.
"""

import logging
import re

Expand Down Expand Up @@ -182,7 +183,7 @@ def add(self, label_id):
RE_VALID.match(label_id), _('Invalid label, valid characters:[a-z0-9_-]')
)
check_input(label_id, _('Empty Label'))
check_input(not (label_id in self.labels), _('Label already exists'))
check_input(label_id not in self.labels, _('Label already exists'))

self.labels[label_id] = dict(OPTIONS_DEFAULTS)
self.config.save()
Expand Down
24 changes: 12 additions & 12 deletions deluge/plugins/Scheduler/deluge_scheduler/gtkui.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ def on_state_deferred(state):
def disable(self):
component.get('Preferences').remove_page(_('Scheduler'))
# Reset statusbar dict.
self.statusbar.config_value_changed_dict[
'max_download_speed'
] = self.statusbar._on_max_download_speed
self.statusbar.config_value_changed_dict[
'max_upload_speed'
] = self.statusbar._on_max_upload_speed
self.statusbar.config_value_changed_dict['max_download_speed'] = (
self.statusbar._on_max_download_speed
)
self.statusbar.config_value_changed_dict['max_upload_speed'] = (
self.statusbar._on_max_upload_speed
)
# Remove statusbar item.
self.statusbar.remove_item(self.status_item)
del self.status_item
Expand Down Expand Up @@ -246,12 +246,12 @@ def on_scheduler_event(self, state):
# Skip error due to Plugin being enabled before statusbar items created on startup.
pass
else:
self.statusbar.config_value_changed_dict[
'max_download_speed'
] = self.statusbar._on_max_download_speed
self.statusbar.config_value_changed_dict[
'max_upload_speed'
] = self.statusbar._on_max_upload_speed
self.statusbar.config_value_changed_dict['max_download_speed'] = (
self.statusbar._on_max_download_speed
)
self.statusbar.config_value_changed_dict['max_upload_speed'] = (
self.statusbar._on_max_upload_speed
)

def update_config_values(config):
try:
Expand Down
4 changes: 3 additions & 1 deletion deluge/plugins/Stats/deluge_stats/gtkui.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ def set_colors(self, colors):
self.colors = colors
# Fake switch page to update the graph colors (HACKY)
self._on_notebook_switch_page(
self.notebook, None, self.notebook.get_current_page() # This is unused
self.notebook,
None,
self.notebook.get_current_page(), # This is unused
)

def _on_intervals_changed(self, intervals):
Expand Down
1 change: 1 addition & 0 deletions deluge/plugins/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""
This base class is used in plugin's __init__ for the plugin entry points.
"""

import logging

log = logging.getLogger(__name__)
Expand Down
6 changes: 2 additions & 4 deletions deluge/tests/test_alertmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ def set_up(self, component):
component.start(['AlertManager'])

def test_register_handler(self):
def handler(alert):
...
def handler(alert): ...

self.am.register_handler('dummy1', handler)
self.am.register_handler('dummy2_alert', handler)
Expand Down Expand Up @@ -97,8 +96,7 @@ async def test_pause_not_pop_alert(
assert len(self.am.session.alerts) == 2

def test_deregister_handler(self):
def handler(alert):
...
def handler(alert): ...

self.am.register_handler('dummy1', handler)
self.am.register_handler('dummy2_alert', handler)
Expand Down
6 changes: 5 additions & 1 deletion deluge/tests/test_ui_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,11 @@ def test_bittorrent_v2_hybrid_path(self):
ti = TorrentInfo(filename, filetree=1, force_bt_version=1)
assert ti.files_tree == files_tree
del files_tree['torrent_test']['.pad']
files_tree['torrent_test']['還在一個人無聊嗎~還不趕緊上來聊天美.txt'] = (1, 32, True)
files_tree['torrent_test']['還在一個人無聊嗎~還不趕緊上來聊天美.txt'] = (
1,
32,
True,
)
ti = TorrentInfo(filename, filetree=1, force_bt_version=2)
assert ti.files_tree == files_tree

Expand Down
1 change: 1 addition & 0 deletions deluge/ui/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"""
The ui common module contains methods and classes that are deemed useful for all the interfaces.
"""

import logging
import os
from hashlib import sha1 as sha
Expand Down
18 changes: 9 additions & 9 deletions deluge/ui/console/modes/preferences/preference_panes.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,23 @@ def add_config_values(self, conf_dict):
elif ipt.name == 'proxy_port':
conf_dict.setdefault('proxy', {})['port'] = ipt.get_value()
elif ipt.name == 'proxy_hostnames':
conf_dict.setdefault('proxy', {})[
'proxy_hostnames'
] = ipt.get_value()
conf_dict.setdefault('proxy', {})['proxy_hostnames'] = (
ipt.get_value()
)
elif ipt.name == 'proxy_peer_connections':
conf_dict.setdefault('proxy', {})[
'proxy_peer_connections'
] = ipt.get_value()
conf_dict.setdefault('proxy', {})['proxy_peer_connections'] = (
ipt.get_value()
)
elif ipt.name == 'proxy_tracker_connections':
conf_dict.setdefault('proxy', {})[
'proxy_tracker_connections'
] = ipt.get_value()
elif ipt.name == 'force_proxy':
conf_dict.setdefault('proxy', {})['force_proxy'] = ipt.get_value()
elif ipt.name == 'anonymous_mode':
conf_dict.setdefault('proxy', {})[
'anonymous_mode'
] = ipt.get_value()
conf_dict.setdefault('proxy', {})['anonymous_mode'] = (
ipt.get_value()
)
else:
conf_dict[ipt.name] = ipt.get_value()

Expand Down
6 changes: 3 additions & 3 deletions deluge/ui/console/modes/torrentlist/queue_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def __init__(self, torrentslist, torrent_ids):
self.torrent_ids = torrent_ids

def set_statusbar_args(self, statusbar_args):
statusbar_args[
'bottombar'
] = '{!black,white!}Queue mode: change queue position of selected torrents.'
statusbar_args['bottombar'] = (
'{!black,white!}Queue mode: change queue position of selected torrents.'
)
statusbar_args['bottombar_help'] = ' Press [h] for help'

def update_cursor(self):
Expand Down
10 changes: 5 additions & 5 deletions deluge/ui/console/modes/torrentlist/torrentlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@ def refresh(self, lines=None):
# Update the status bars
statusbar_args = {'scr': self.stdscr, 'bottombar_help': True}
if self.torrentview.curr_filter is not None:
statusbar_args[
'topbar'
] = '{} {{!filterstatus!}}Current filter: {}'.format(
self.statusbars.topbar,
self.torrentview.curr_filter,
statusbar_args['topbar'] = (
'{} {{!filterstatus!}}Current filter: {}'.format(
self.statusbars.topbar,
self.torrentview.curr_filter,
)
)

if self.minor_mode:
Expand Down
4 changes: 2 additions & 2 deletions deluge/ui/console/widgets/inputpane.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(
border_off_east=0,
border_off_south=0,
active_wrap=False,
**kwargs
**kwargs,
):
InputKeyHandler.__init__(self)
self.inputs = []
Expand Down Expand Up @@ -155,7 +155,7 @@ def add_text_input(self, name, message, value='', col='+1', **kwargs):
self.visible_content_pane_width,
value,
col=col,
**kwargs
**kwargs,
)
)

Expand Down
Loading

0 comments on commit 0d72195

Please sign in to comment.