Skip to content

Commit 65544e2

Browse files
authored
chore: swap to using ruff for codestyle (#1706)
* chore: swap to using ruff for codestyle This includes black and isort, which was currently used. * docs: add info to CHANGES * fix: remove unused imports * fix: remove f-string usage where not needed * tests: remove sort in tox * fix: sort, ignore and adjust imports * fix: ignore unused variables in flow tests * fix: remove unsued variable * fix: type references * fix: object type checks * style: general formatting
1 parent f9c2dc8 commit 65544e2

30 files changed

+39
-63
lines changed

.github/workflows/python-package.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ jobs:
5050
run: |
5151
tox -e codestyle
5252
53-
- name: Lint - sort
54-
if: ${{ matrix.python-version == '3.12' }}
55-
run: |
56-
tox -e sort
57-
5853
- name: Security
5954
if: ${{ matrix.python-version == '3.12' }}
6055
run: |

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ fixes:
1212
- docs: fix telegram install command (#1697)
1313
- chore: add python versions to test (#1705)
1414
- chore: remove python 3.8 support (#1707)
15+
- chore: use ruff for formatting (#1706)
1516

1617
v6.2.0 (2024-01-01)
1718
-------------------

docs/conf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
# All configuration values have a default; values that are commented out
1313
# serve to show the default.
1414

15-
import subprocess, sys, os
15+
import subprocess
16+
import sys
17+
import os
1618
sys.path.append(os.path.abspath('_themes'))
1719
sys.path.append(os.path.abspath('_themes/err'))
1820
sys.path.append(os.path.abspath('../'))

errbot/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
import logging
44
import re
55
import shlex
6-
import sys
76
from functools import wraps
8-
from typing import Any, Callable, List, Optional, Tuple
7+
from typing import Any, Callable, Optional, Tuple
98

109
from .backends.base import AWAY, DND, OFFLINE, ONLINE, Message # noqa
1110
from .botplugin import ( # noqa
@@ -16,7 +15,7 @@
1615
ShlexArgParser,
1716
ValidationException,
1817
)
19-
from .core_plugins.wsview import WebView, route
18+
from .core_plugins.wsview import route
2019
from .flow import FLOW_END, BotFlow, Flow, FlowRoot
2120

2221
__all__ = [

errbot/backend_plugin_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class PluginNotFoundException(Exception):
1515

1616

1717
def enumerate_backend_plugins(
18-
all_plugins_paths: List[Union[str, Path]]
18+
all_plugins_paths: List[Union[str, Path]],
1919
) -> Iterator[PluginInfo]:
2020
plugin_places = [Path(root) for root in all_plugins_paths]
2121
for path in plugin_places:

errbot/backends/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import time
55
from abc import ABC, abstractmethod
66
from collections import defaultdict, deque
7-
from typing import Any, BinaryIO, List, Mapping, Optional, Sequence, Tuple
7+
from typing import Any, BinaryIO, List, Mapping, Optional, Sequence, Tuple, Type
88

99
log = logging.getLogger(__name__)
1010

@@ -391,7 +391,7 @@ def extras(self) -> Mapping:
391391
return self._extras
392392

393393
@property
394-
def flow(self) -> "errbot.Flow":
394+
def flow(self) -> Type["errbot.Flow"]: # noqa: F821
395395
"""
396396
Get the conversation flow for this message.
397397

errbot/backends/irc.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@
4949
bg_default=NSC("\x03,"),
5050
fx_reset=NSC("\x03"),
5151
fx_bold=NSC("\x02"),
52-
fx_italic=NSC("\x1D"),
53-
fx_underline=NSC("\x1F"),
54-
fx_not_italic=NSC("\x0F"),
55-
fx_not_underline=NSC("\x0F"),
56-
fx_normal=NSC("\x0F"),
52+
fx_italic=NSC("\x1d"),
53+
fx_underline=NSC("\x1f"),
54+
fx_not_italic=NSC("\x0f"),
55+
fx_not_underline=NSC("\x0f"),
56+
fx_normal=NSC("\x0f"),
5757
fixed_width="",
5858
end_fixed_width="",
5959
inline_code="",

errbot/backends/telegram_messenger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22
import sys
3-
from typing import Any, BinaryIO, List, Optional, Union
3+
from typing import Any, BinaryIO, Optional, Union
44

55
from errbot.backends.base import (
66
ONLINE,

errbot/backends/xmpp.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from datetime import datetime
66
from functools import lru_cache
77
from time import sleep
8-
from typing import Callable, List, Optional, Tuple
8+
from typing import Callable, List, Optional, Tuple, Union
99

1010
from errbot.backends.base import (
1111
AWAY,
@@ -28,7 +28,6 @@
2828
try:
2929
from slixmpp import JID, ClientXMPP
3030
from slixmpp.exceptions import IqError
31-
from slixmpp.xmlstream import cert, resolver
3231

3332
except ImportError:
3433
log.exception("Could not start the XMPP backend")

errbot/botplugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def recurse_check_structure(sample: Any, to_check: Any) -> None:
4444
recurse_check_structure(sample[0], element)
4545
return
4646

47-
if sample_type == dict:
47+
if sample_type == dict: # noqa: E721
4848
for key in sample:
4949
if key not in to_check:
5050
raise ValidationException(f"{to_check} doesn't contain the key {key}.")
@@ -128,7 +128,7 @@ def __init__(
128128
self.definition = cmd_type(*((function,) + cmd_args), **cmd_kwargs)
129129

130130
def append_args(self, args, kwargs):
131-
from errbot import arg_botcmd, update_wrapper
131+
from errbot import update_wrapper
132132

133133
if hasattr(self.definition, "_err_command_parser"):
134134
update_wrapper(self.definition, args, kwargs)

errbot/cli.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from os import W_OK, access, getcwd, path, sep
2323
from pathlib import Path
2424
from platform import system
25-
from typing import Optional, Union
2625

2726
from errbot.bootstrap import CORE_BACKENDS
2827
from errbot.logs import root_logger

errbot/core.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,8 @@ def __init__(self, bot_config):
5555
log.debug(
5656
"created a thread pool of size %d.", bot_config.BOT_ASYNC_POOLSIZE
5757
)
58-
self.commands = (
59-
{}
60-
) # the dynamically populated list of commands available on the bot
61-
self.re_commands = (
62-
{}
63-
) # the dynamically populated list of regex-based commands available on the bot
58+
self.commands = {} # the dynamically populated list of commands available on the bot
59+
self.re_commands = {} # the dynamically populated list of regex-based commands available on the bot
6460
self.command_filters = [] # the dynamically populated list of filters
6561
self.MSG_UNKNOWN_COMMAND = (
6662
'Unknown command: "%(command)s". '
@@ -287,8 +283,6 @@ def process_message(self, msg: Message) -> bool:
287283
log.debug("*** username = %s", username)
288284
log.debug("*** text = %s", text)
289285

290-
suppress_cmd_not_found = self.bot_config.SUPPRESS_CMD_NOT_FOUND
291-
292286
prefixed = False # Keeps track whether text was prefixed with a bot prefix
293287
only_check_re_command = (
294288
False # Becomes true if text is determed to not be a regular command
@@ -324,10 +318,6 @@ def process_message(self, msg: Message) -> bool:
324318
'Assuming "%s" to be a command because BOT_PREFIX_OPTIONAL_ON_CHAT is True',
325319
text,
326320
)
327-
# In order to keep noise down we surpress messages about the command
328-
# not being found, because it's possible a plugin will trigger on what
329-
# was said with trigger_message.
330-
suppress_cmd_not_found = True
331321
elif not text.startswith(self.bot_config.BOT_PREFIX):
332322
only_check_re_command = True
333323
if text.startswith(self.bot_config.BOT_PREFIX):

errbot/core_plugins/chatRoom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22

3-
from errbot import BotPlugin, SeparatorArgParser, ShlexArgParser, botcmd
3+
from errbot import BotPlugin, ShlexArgParser, botcmd
44
from errbot.backends.base import RoomNotJoinedError
55

66
log = logging.getLogger(__name__)

errbot/core_plugins/plugins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def plugin_config(self, _, args):
187187
except Exception:
188188
self.log.exception("Invalid expression for the configuration of the plugin")
189189
return "Syntax error in the given configuration"
190-
if type(real_config_obj) != type(template_obj):
190+
if type(real_config_obj) is not type(template_obj):
191191
return "It looks fishy, your config type is not the same as the template!"
192192

193193
self._bot.plugin_manager.set_plugin_configuration(plugin_name, real_config_obj)

errbot/plugin_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Logic related to plugin loading and lifecycle """
1+
"""Logic related to plugin loading and lifecycle"""
22

33
import logging
44
import os

errbot/rendering/xhtmlim.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def _replace_charref(s):
190190
if num in _invalid_charrefs:
191191
return _invalid_charrefs[num]
192192
if 0xD800 <= num <= 0xDFFF or num > 0x10FFFF:
193-
return "\uFFFD"
193+
return "\ufffd"
194194
if num in _invalid_codepoints:
195195
return ""
196196
return chr(num)

errbot/repo_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from datetime import datetime, timedelta
99
from os import path
1010
from pathlib import Path
11-
from typing import Dict, Generator, List, Optional, Sequence, Tuple, Union
11+
from typing import Dict, Generator, List, Optional, Sequence, Tuple
1212
from urllib.error import HTTPError, URLError
1313
from urllib.parse import urlparse
1414
from urllib.request import Request, urlopen

errbot/storage/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
import types
32
from collections.abc import MutableMapping
43
from contextlib import contextmanager
54

@@ -36,7 +35,7 @@ def open_storage(self, storage_plugin, namespace):
3635

3736
def close_storage(self):
3837
if not self.is_open_storage():
39-
raise StoreNotOpenError(f"Storage does not appear to have been opened yet")
38+
raise StoreNotOpenError("Storage does not appear to have been opened yet")
4039
self._store.close()
4140
self._store = None
4241
log.debug("Closed storage '%s'", self.namespace)

tests/borken_plugin/broken.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import borken # fails on purpose
2-
31
from errbot import BotPlugin, botcmd
42

3+
import borken # fails on purpose # noqa: F401
54

65
class Broken(BotPlugin):
76
@botcmd

tests/cascade_dependent_plugins/child1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from errbot import BotPlugin, botcmd
1+
from errbot import BotPlugin
22

33

44
class Child1(BotPlugin):

tests/cascade_dependent_plugins/child2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from errbot import BotPlugin, botcmd
1+
from errbot import BotPlugin
22

33

44
class Child2(BotPlugin):

tests/core_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""Test _admins_to_notify wrapper functionality"""
22

3-
import pytest
4-
53
extra_config = {"BOT_ADMINS_NOTIFICATIONS": "zoni@localdomain"}
64

75

tests/flow_plugin/flowtest_flows.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# ruff: noqa: F841
12
from __future__ import absolute_import
23

34
from errbot import BotFlow, FlowRoot, botflow

tests/link_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# coding=utf-8
22
from os import path
33

4-
import pytest
54

65
extra_plugin_dir = path.join(path.dirname(path.realpath(__file__)), "test_link")
76

tests/matchall_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# coding=utf-8
22
from os import path
33

4-
import pytest
5-
64
extra_plugin_dir = path.join(path.dirname(path.realpath(__file__)), "matchall_plugin")
75

86

tests/template_plugin/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import absolute_import
22

3-
from errbot import BotPlugin, arg_botcmd, botcmd, re_botcmd
3+
from errbot import BotPlugin, arg_botcmd, botcmd
44

55

66
class Test(BotPlugin):

tests/utils_test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# coding=utf-8
2+
import logging
3+
import sys
4+
25
from datetime import timedelta
36

47
import pytest
@@ -8,7 +11,7 @@
811
from errbot.bootstrap import CORE_STORAGE, bot_config_defaults
912
from errbot.storage import StoreMixin
1013
from errbot.storage.base import StoragePluginBase
11-
from errbot.utils import *
14+
from errbot.utils import version2tuple, format_timedelta, split_string_after
1215

1316
log = logging.getLogger(__name__)
1417

tests/webhooks_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import pytest
88
import requests
99

10-
from errbot.backends.test import FullStackTest, testbot
1110

1211
log = logging.getLogger(__name__)
1312

tools/plugin-gen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def check_repo(repo):
187187
repo_entry[name] = plugin
188188
plugins[repo_name] = repo_entry
189189
log.debug("Catalog added plugin %s.", plugin["name"])
190-
except:
190+
except Exception:
191191
log.error("Invalid syntax in %s, skipping...", plug["path"])
192192
continue
193193

tox.ini

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py39,py310,py311,py312,py312,codestyle,dist-check,sort,security,docs
2+
envlist = py39,py310,py311,py312,py312,codestyle,dist-check,security,docs
33
skip_missing_interpreters = True
44

55
[testenv]
@@ -11,9 +11,9 @@ commands = pytest -v tests/
1111
recreate = true
1212

1313
[testenv:codestyle]
14-
deps = black
14+
deps = ruff
1515
commands =
16-
black --check errbot/ tests/ tools/
16+
ruff check errbot/ tests/ tools/
1717

1818
[testenv:dist-check]
1919
deps =
@@ -22,11 +22,6 @@ commands =
2222
python setup.py sdist
2323
twine check {toxinidir}/dist/*
2424

25-
[testenv:sort]
26-
deps =
27-
isort
28-
commands = isort --check-only errbot/
29-
3025
[testenv:security]
3126
deps =
3227
bandit

0 commit comments

Comments
 (0)