Skip to content

Commit 1f5a17f

Browse files
committed
Remove old venusian dependency
It is unmaintained and blocking Python 3.10
1 parent 0d7e0c3 commit 1f5a17f

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

cloudbot/bot.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
import collections
33
import gc
4+
import importlib
45
import logging
56
import re
67
import time
@@ -10,13 +11,12 @@
1011
from pathlib import Path
1112
from typing import Any, Dict, Optional, Type
1213

13-
from sqlalchemy import Table, create_engine, inspect
14+
from sqlalchemy import Table, create_engine
15+
from sqlalchemy import inspect as sa_inspect
1416
from sqlalchemy.engine import Engine
1517
from sqlalchemy.orm import Session, scoped_session, sessionmaker
16-
from venusian import Scanner
1718
from watchdog.observers import Observer
1819

19-
from cloudbot import clients
2020
from cloudbot.client import Client
2121
from cloudbot.config import Config
2222
from cloudbot.event import CommandEvent, Event, EventType, RegexEvent
@@ -315,8 +315,21 @@ def load_clients(self):
315315
"""
316316
Load all clients from the "clients" directory
317317
"""
318-
scanner = Scanner(bot=self)
319-
scanner.scan(clients, categories=["cloudbot.client"])
318+
for file in (Path(__file__).parent / "clients").rglob("*.py"):
319+
if file.name.startswith("_"):
320+
continue
321+
322+
mod = importlib.import_module("cloudbot.clients." + file.stem)
323+
for _, obj in vars(mod).items():
324+
if not isinstance(obj, type):
325+
continue
326+
327+
try:
328+
_type = obj._cloudbot_client # type: ignore
329+
except AttributeError:
330+
continue
331+
332+
self.register_client(_type, obj)
320333

321334
async def process(self, event):
322335
run_before_tasks = []
@@ -466,7 +479,7 @@ def migrate_db(self) -> None:
466479
old_session: Session = scoped_session(sessionmaker(bind=engine))()
467480
new_session: Session = database.Session()
468481
table: Table
469-
inspector = inspect(engine)
482+
inspector = sa_inspect(engine)
470483
for table in database.metadata.tables.values():
471484
logger.info("Migrating table %s", table.name)
472485
if not inspector.has_table(table.name):

cloudbot/client.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import random
55
from typing import Any, Dict
66

7-
import venusian
8-
97
from cloudbot.permissions import PermissionManager
108
from cloudbot.util import async_util
119

@@ -14,10 +12,7 @@
1412

1513
def client(_type):
1614
def _decorate(cls):
17-
def callback_cb(context, name, obj):
18-
context.bot.register_client(_type, cls)
19-
20-
venusian.attach(cls, callback_cb, category="cloudbot.client")
15+
cls._cloudbot_client = _type
2116
return cls
2217

2318
return _decorate

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,5 @@ py-irclib == 0.3.0
1717
requests == 2.27.1
1818
tweepy == 3.10.0
1919
urllib3 == 1.26.7
20-
venusian == 3.0.0
2120
watchdog == 2.1.6
2221
yarl == 1.7.2

0 commit comments

Comments
 (0)