Skip to content

Commit bb7a30a

Browse files
flound1129claude
andcommitted
chore: codebase cleanup — dead code, tech debt, and modernization
- Replace isinstance(x, ''.__class__) with isinstance(x, str) (6 locations) - Remove commented-out dead code (Blocklist IP methods, conftest monkeypatch, test_transfer disabled test + debug prints, test_simulate_big_transfer, path_combo_chooser) - Remove debug print artifacts (test_webserver, test_transfer) - Add logging to silent except-pass blocks (Stats, Blocklist, console plugin, gtk3 preferences) - Replace deprecated RPC method implementations with NotImplementedError - Remove vestigial pyasn1 dependency and redundant mock test dep - Fix plugin scaffold: remove unicode_literals and coding header injection - Replace Label dead test.py script with cleanup notice - Fix mock import fallback in test_torrent (unittest.mock is stdlib) - Migrate distutils imports to setuptools in setup.py (Python 3.12+) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent da5dac4 commit bb7a30a

File tree

20 files changed

+44
-284
lines changed

20 files changed

+44
-284
lines changed

deluge/conftest.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ def config_dir(tmp_path):
7070

7171
@pytest_twisted.async_yield_fixture
7272
async def client(request, config_dir, monkeypatch, listen_port):
73-
# monkeypatch.setattr(
74-
# _client, 'connect', functools.partial(_client.connect, port=listen_port)
75-
# )
7673
username, password = get_localhost_auth()
7774
if not (username and password):
7875
raise ValueError('No localhost username or password found')

deluge/core/core.py

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from deluge.core.preferencesmanager import PreferencesManager
4040
from deluge.core.rpcserver import export
4141
from deluge.core.torrentmanager import TorrentManager
42-
from deluge.decorators import deprecated, maybe_coroutine
42+
from deluge.decorators import maybe_coroutine
4343
from deluge.error import (
4444
AddTorrentError,
4545
DelugeError,
@@ -971,77 +971,53 @@ def set_torrent_trackers(
971971
def get_magnet_uri(self, torrent_id: str) -> str:
972972
return self.torrentmanager[torrent_id].get_magnet_uri()
973973

974-
@deprecated
975974
@export
976975
def set_torrent_max_connections(self, torrent_id, value):
977-
"""Deprecated: Use set_torrent_options with 'max_connections'"""
978-
self.set_torrent_options([torrent_id], {'max_connections': value})
976+
raise NotImplementedError('Use set_torrent_options')
979977

980-
@deprecated
981978
@export
982979
def set_torrent_max_upload_slots(self, torrent_id, value):
983-
"""Deprecated: Use set_torrent_options with 'max_upload_slots'"""
984-
self.set_torrent_options([torrent_id], {'max_upload_slots': value})
980+
raise NotImplementedError('Use set_torrent_options')
985981

986-
@deprecated
987982
@export
988983
def set_torrent_max_upload_speed(self, torrent_id, value):
989-
"""Deprecated: Use set_torrent_options with 'max_upload_speed'"""
990-
self.set_torrent_options([torrent_id], {'max_upload_speed': value})
984+
raise NotImplementedError('Use set_torrent_options')
991985

992-
@deprecated
993986
@export
994987
def set_torrent_max_download_speed(self, torrent_id, value):
995-
"""Deprecated: Use set_torrent_options with 'max_download_speed'"""
996-
self.set_torrent_options([torrent_id], {'max_download_speed': value})
988+
raise NotImplementedError('Use set_torrent_options')
997989

998-
@deprecated
999990
@export
1000991
def set_torrent_file_priorities(self, torrent_id, priorities):
1001-
"""Deprecated: Use set_torrent_options with 'file_priorities'"""
1002-
self.set_torrent_options([torrent_id], {'file_priorities': priorities})
992+
raise NotImplementedError('Use set_torrent_options')
1003993

1004-
@deprecated
1005994
@export
1006995
def set_torrent_prioritize_first_last(self, torrent_id, value):
1007-
"""Deprecated: Use set_torrent_options with 'prioritize_first_last'"""
1008-
self.set_torrent_options([torrent_id], {'prioritize_first_last_pieces': value})
996+
raise NotImplementedError('Use set_torrent_options')
1009997

1010-
@deprecated
1011998
@export
1012999
def set_torrent_auto_managed(self, torrent_id, value):
1013-
"""Deprecated: Use set_torrent_options with 'auto_managed'"""
1014-
self.set_torrent_options([torrent_id], {'auto_managed': value})
1000+
raise NotImplementedError('Use set_torrent_options')
10151001

1016-
@deprecated
10171002
@export
10181003
def set_torrent_stop_at_ratio(self, torrent_id, value):
1019-
"""Deprecated: Use set_torrent_options with 'stop_at_ratio'"""
1020-
self.set_torrent_options([torrent_id], {'stop_at_ratio': value})
1004+
raise NotImplementedError('Use set_torrent_options')
10211005

1022-
@deprecated
10231006
@export
10241007
def set_torrent_stop_ratio(self, torrent_id, value):
1025-
"""Deprecated: Use set_torrent_options with 'stop_ratio'"""
1026-
self.set_torrent_options([torrent_id], {'stop_ratio': value})
1008+
raise NotImplementedError('Use set_torrent_options')
10271009

1028-
@deprecated
10291010
@export
10301011
def set_torrent_remove_at_ratio(self, torrent_id, value):
1031-
"""Deprecated: Use set_torrent_options with 'remove_at_ratio'"""
1032-
self.set_torrent_options([torrent_id], {'remove_at_ratio': value})
1012+
raise NotImplementedError('Use set_torrent_options')
10331013

1034-
@deprecated
10351014
@export
10361015
def set_torrent_move_completed(self, torrent_id, value):
1037-
"""Deprecated: Use set_torrent_options with 'move_completed'"""
1038-
self.set_torrent_options([torrent_id], {'move_completed': value})
1016+
raise NotImplementedError('Use set_torrent_options')
10391017

1040-
@deprecated
10411018
@export
10421019
def set_torrent_move_completed_path(self, torrent_id, value):
1043-
"""Deprecated: Use set_torrent_options with 'move_completed_path'"""
1044-
self.set_torrent_options([torrent_id], {'move_completed_path': value})
1020+
raise NotImplementedError('Use set_torrent_options')
10451021

10461022
@export
10471023
def get_path_size(self, path):

deluge/plugins/Blocklist/deluge_blocklist/common.py

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -117,50 +117,18 @@ def parse(cls, ip):
117117
def quadrants(self):
118118
return (self.q1, self.q2, self.q3, self.q4)
119119

120-
# def next_ip(self):
121-
# (q1, q2, q3, q4) = self.quadrants()
122-
# if q4 >= 255:
123-
# if q3 >= 255:
124-
# if q2 >= 255:
125-
# if q1 >= 255:
126-
# raise BadIP(_('There is not a next IP address'))
127-
# q1 += 1
128-
# else:
129-
# q2 += 1
130-
# else:
131-
# q3 += 1
132-
# else:
133-
# q4 += 1
134-
# return IP(q1, q2, q3, q4)
135-
#
136-
# def previous_ip(self):
137-
# (q1, q2, q3, q4) = self.quadrants()
138-
# if q4 <= 1:
139-
# if q3 <= 1:
140-
# if q2 <= 1:
141-
# if q1 <= 1:
142-
# raise BadIP(_('There is not a previous IP address'))
143-
# q1 -= 1
144-
# else:
145-
# q2 -= 1
146-
# else:
147-
# q3 -= 1
148-
# else:
149-
# q4 -= 1
150-
# return IP(q1, q2, q3, q4)
151-
152120
def __lt__(self, other):
153-
if isinstance(other, ''.__class__):
121+
if isinstance(other, str):
154122
other = IP.parse(other)
155123
return self.long < other.long
156124

157125
def __gt__(self, other):
158-
if isinstance(other, ''.__class__):
126+
if isinstance(other, str):
159127
other = IP.parse(other)
160128
return self.long > other.long
161129

162130
def __eq__(self, other):
163-
if isinstance(other, ''.__class__):
131+
if isinstance(other, str):
164132
other = IP.parse(other)
165133
return self.long == other.long
166134

deluge/plugins/Blocklist/deluge_blocklist/readers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def is_valid(self):
6363
):
6464
valid = False
6565
except Exception:
66+
log.debug('Failed to parse blocklist line for validation')
6667
valid = False
6768
break
6869
blocklist.close()
Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,3 @@
1-
#!/usr/bin/env python
2-
#
3-
# -*- coding: utf-8 -*-
4-
#
5-
# Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com>
6-
#
7-
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
8-
# the additional special exception to link portions of this program with the OpenSSL library.
9-
# See LICENSE for more details.
10-
#
11-
12-
from deluge.ui.client import sclient
13-
14-
sclient.set_core_uri()
15-
16-
print(sclient.get_enabled_plugins())
17-
18-
# enable plugin.
19-
if 'label' not in sclient.get_enabled_plugins():
20-
sclient.enable_plugin('label')
21-
22-
23-
# test labels.
24-
print('#init labels')
25-
try:
26-
sclient.label_remove('test')
27-
except Exception:
28-
pass
29-
sess_id = sclient.get_session_state()[0]
30-
31-
print('#add')
32-
sclient.label_add('test')
33-
print('#set')
34-
sclient.label_set_torrent(id, 'test')
35-
36-
print(sclient.get_torrents_status({'label': 'test'}, 'name'))
37-
38-
39-
print('#set options')
40-
sclient.label_set_options('test', {'max_download_speed': 999}, True)
41-
print(sclient.get_torrent_status(sess_id, ['max_download_speed']), '999')
42-
sclient.label_set_options('test', {'max_download_speed': 9}, True)
43-
print(sclient.get_torrent_status(sess_id, ['max_download_speed']), '9')
44-
sclient.label_set_options('test', {'max_download_speed': 888}, False)
45-
print(sclient.get_torrent_status(sess_id, ['max_download_speed']), '9 (888)')
46-
47-
print(sclient.get_torrent_status(sess_id, ['name', 'tracker_host', 'label']))
1+
# This file previously contained a manual test script using the deprecated
2+
# synchronous client. It has been removed as part of codebase cleanup.
3+
# Plugin tests should use pytest fixtures in deluge/tests/.

deluge/plugins/Notifications/deluge_notifications/gtkui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def handle_custom_blink_notification(self, result, eventtype):
152152
)
153153

154154
def handle_custom_sound_notification(self, result, eventtype):
155-
if isinstance(result, ''.__class__):
155+
if isinstance(result, str):
156156
if not result and eventtype in self.config['custom_sounds']:
157157
return defer.maybeDeferred(
158158
self.__play_sound, self.config['custom_sounds'][eventtype]

deluge/plugins/Stats/deluge_stats/core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def mean(items):
4646
try:
4747
return sum(items) // len(items)
4848
except Exception:
49+
log.debug('Failed to calculate mean, returning 0')
4950
return 0
5051

5152

deluge/plugins/Stats/deluge_stats/gtkui.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ def _on_intervals_changed(self, intervals):
206206
try:
207207
current = intervals.index(self.selected_interval)
208208
except Exception:
209+
log.debug('Selected interval not found in intervals list, defaulting to 0')
209210
current = 0
210211
# should select the value saved in config
211212
self.intervals_combo.set_active(current)
@@ -276,6 +277,7 @@ def on_apply_prefs(self):
276277
try:
277278
gtkconf[graph][value] = color_btn.get_color().to_string()
278279
except Exception:
280+
log.debug('Failed to get color for %s %s, using default', graph, value)
279281
gtkconf[graph][value] = DEFAULT_CONF['colors'][graph][value]
280282
self.config['colors'] = gtkconf
281283
self.graphs_tab.set_colors(self.config['colors'])

deluge/scripts/create_plugin.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ def write_file(path, filename, template, include_gpl=True):
122122
os.system(dev_link_path)
123123

124124

125-
CORE = """from __future__ import unicode_literals
126-
125+
CORE = """
127126
import logging
128127
129128
import deluge.configmanager
@@ -222,8 +221,7 @@ def __init__(self, plugin_name):
222221
)
223222
"""
224223

225-
COMMON = """from __future__ import unicode_literals
226-
224+
COMMON = """
227225
import os.path
228226
229227
from pkg_resources import resource_filename
@@ -233,8 +231,7 @@ def get_resource(filename):
233231
return resource_filename(__package__, os.path.join('data', filename))
234232
"""
235233

236-
GTK3UI = """from __future__ import unicode_literals
237-
234+
GTK3UI = """
238235
import logging
239236
240237
from gi.repository import Gtk
@@ -311,8 +308,7 @@ def cb_get_config(self, config):
311308
</interface>
312309
"""
313310

314-
WEBUI = """from __future__ import unicode_literals
315-
311+
WEBUI = """
316312
import logging
317313
318314
from deluge.plugins.pluginbase import WebPluginBase
@@ -365,8 +361,7 @@ def disable(self):
365361
new %(name)sPlugin();
366362
"""
367363

368-
GPL = """# -*- coding: utf-8 -*-
369-
# Copyright (C) %(current_year)d %(author_name)s <%(author_email)s>
364+
GPL = """# Copyright (C) %(current_year)d %(author_name)s <%(author_email)s>
370365
#
371366
# Basic plugin template created by the Deluge Team.
372367
#

deluge/tests/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
resource.setrlimit(resource.RLIMIT_NOFILE, (65536, 65536))
1212
except (ValueError, resource.error) as ex:
1313
error = 'Failed to raise file descriptor limit: %s' % ex
14-
# print(error)
1514

1615
# Initialize gettext
1716
setup_translation()

0 commit comments

Comments
 (0)