Skip to content

Commit

Permalink
chore: swap to using ruff for codestyle (#1706)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sijis authored Oct 26, 2024
1 parent f9c2dc8 commit 65544e2
Show file tree
Hide file tree
Showing 30 changed files with 39 additions and 63 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ jobs:
run: |
tox -e codestyle
- name: Lint - sort
if: ${{ matrix.python-version == '3.12' }}
run: |
tox -e sort
- name: Security
if: ${{ matrix.python-version == '3.12' }}
run: |
Expand Down
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ fixes:
- docs: fix telegram install command (#1697)
- chore: add python versions to test (#1705)
- chore: remove python 3.8 support (#1707)
- chore: use ruff for formatting (#1706)

v6.2.0 (2024-01-01)
-------------------
Expand Down
4 changes: 3 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import subprocess, sys, os
import subprocess
import sys
import os
sys.path.append(os.path.abspath('_themes'))
sys.path.append(os.path.abspath('_themes/err'))
sys.path.append(os.path.abspath('../'))
Expand Down
5 changes: 2 additions & 3 deletions errbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import logging
import re
import shlex
import sys
from functools import wraps
from typing import Any, Callable, List, Optional, Tuple
from typing import Any, Callable, Optional, Tuple

from .backends.base import AWAY, DND, OFFLINE, ONLINE, Message # noqa
from .botplugin import ( # noqa
Expand All @@ -16,7 +15,7 @@
ShlexArgParser,
ValidationException,
)
from .core_plugins.wsview import WebView, route
from .core_plugins.wsview import route
from .flow import FLOW_END, BotFlow, Flow, FlowRoot

__all__ = [
Expand Down
2 changes: 1 addition & 1 deletion errbot/backend_plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class PluginNotFoundException(Exception):


def enumerate_backend_plugins(
all_plugins_paths: List[Union[str, Path]]
all_plugins_paths: List[Union[str, Path]],
) -> Iterator[PluginInfo]:
plugin_places = [Path(root) for root in all_plugins_paths]
for path in plugin_places:
Expand Down
4 changes: 2 additions & 2 deletions errbot/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import time
from abc import ABC, abstractmethod
from collections import defaultdict, deque
from typing import Any, BinaryIO, List, Mapping, Optional, Sequence, Tuple
from typing import Any, BinaryIO, List, Mapping, Optional, Sequence, Tuple, Type

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -391,7 +391,7 @@ def extras(self) -> Mapping:
return self._extras

@property
def flow(self) -> "errbot.Flow":
def flow(self) -> Type["errbot.Flow"]: # noqa: F821
"""
Get the conversation flow for this message.
Expand Down
10 changes: 5 additions & 5 deletions errbot/backends/irc.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
bg_default=NSC("\x03,"),
fx_reset=NSC("\x03"),
fx_bold=NSC("\x02"),
fx_italic=NSC("\x1D"),
fx_underline=NSC("\x1F"),
fx_not_italic=NSC("\x0F"),
fx_not_underline=NSC("\x0F"),
fx_normal=NSC("\x0F"),
fx_italic=NSC("\x1d"),
fx_underline=NSC("\x1f"),
fx_not_italic=NSC("\x0f"),
fx_not_underline=NSC("\x0f"),
fx_normal=NSC("\x0f"),
fixed_width="",
end_fixed_width="",
inline_code="",
Expand Down
2 changes: 1 addition & 1 deletion errbot/backends/telegram_messenger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import sys
from typing import Any, BinaryIO, List, Optional, Union
from typing import Any, BinaryIO, Optional, Union

from errbot.backends.base import (
ONLINE,
Expand Down
3 changes: 1 addition & 2 deletions errbot/backends/xmpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from datetime import datetime
from functools import lru_cache
from time import sleep
from typing import Callable, List, Optional, Tuple
from typing import Callable, List, Optional, Tuple, Union

from errbot.backends.base import (
AWAY,
Expand All @@ -28,7 +28,6 @@
try:
from slixmpp import JID, ClientXMPP
from slixmpp.exceptions import IqError
from slixmpp.xmlstream import cert, resolver

except ImportError:
log.exception("Could not start the XMPP backend")
Expand Down
4 changes: 2 additions & 2 deletions errbot/botplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def recurse_check_structure(sample: Any, to_check: Any) -> None:
recurse_check_structure(sample[0], element)
return

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

def append_args(self, args, kwargs):
from errbot import arg_botcmd, update_wrapper
from errbot import update_wrapper

if hasattr(self.definition, "_err_command_parser"):
update_wrapper(self.definition, args, kwargs)
Expand Down
1 change: 0 additions & 1 deletion errbot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from os import W_OK, access, getcwd, path, sep
from pathlib import Path
from platform import system
from typing import Optional, Union

from errbot.bootstrap import CORE_BACKENDS
from errbot.logs import root_logger
Expand Down
14 changes: 2 additions & 12 deletions errbot/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,8 @@ def __init__(self, bot_config):
log.debug(
"created a thread pool of size %d.", bot_config.BOT_ASYNC_POOLSIZE
)
self.commands = (
{}
) # the dynamically populated list of commands available on the bot
self.re_commands = (
{}
) # the dynamically populated list of regex-based commands available on the bot
self.commands = {} # the dynamically populated list of commands available on the bot
self.re_commands = {} # the dynamically populated list of regex-based commands available on the bot
self.command_filters = [] # the dynamically populated list of filters
self.MSG_UNKNOWN_COMMAND = (
'Unknown command: "%(command)s". '
Expand Down Expand Up @@ -287,8 +283,6 @@ def process_message(self, msg: Message) -> bool:
log.debug("*** username = %s", username)
log.debug("*** text = %s", text)

suppress_cmd_not_found = self.bot_config.SUPPRESS_CMD_NOT_FOUND

prefixed = False # Keeps track whether text was prefixed with a bot prefix
only_check_re_command = (
False # Becomes true if text is determed to not be a regular command
Expand Down Expand Up @@ -324,10 +318,6 @@ def process_message(self, msg: Message) -> bool:
'Assuming "%s" to be a command because BOT_PREFIX_OPTIONAL_ON_CHAT is True',
text,
)
# In order to keep noise down we surpress messages about the command
# not being found, because it's possible a plugin will trigger on what
# was said with trigger_message.
suppress_cmd_not_found = True
elif not text.startswith(self.bot_config.BOT_PREFIX):
only_check_re_command = True
if text.startswith(self.bot_config.BOT_PREFIX):
Expand Down
2 changes: 1 addition & 1 deletion errbot/core_plugins/chatRoom.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from errbot import BotPlugin, SeparatorArgParser, ShlexArgParser, botcmd
from errbot import BotPlugin, ShlexArgParser, botcmd
from errbot.backends.base import RoomNotJoinedError

log = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion errbot/core_plugins/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def plugin_config(self, _, args):
except Exception:
self.log.exception("Invalid expression for the configuration of the plugin")
return "Syntax error in the given configuration"
if type(real_config_obj) != type(template_obj):
if type(real_config_obj) is not type(template_obj):
return "It looks fishy, your config type is not the same as the template!"

self._bot.plugin_manager.set_plugin_configuration(plugin_name, real_config_obj)
Expand Down
2 changes: 1 addition & 1 deletion errbot/plugin_manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Logic related to plugin loading and lifecycle """
"""Logic related to plugin loading and lifecycle"""

import logging
import os
Expand Down
2 changes: 1 addition & 1 deletion errbot/rendering/xhtmlim.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def _replace_charref(s):
if num in _invalid_charrefs:
return _invalid_charrefs[num]
if 0xD800 <= num <= 0xDFFF or num > 0x10FFFF:
return "\uFFFD"
return "\ufffd"
if num in _invalid_codepoints:
return ""
return chr(num)
Expand Down
2 changes: 1 addition & 1 deletion errbot/repo_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from datetime import datetime, timedelta
from os import path
from pathlib import Path
from typing import Dict, Generator, List, Optional, Sequence, Tuple, Union
from typing import Dict, Generator, List, Optional, Sequence, Tuple
from urllib.error import HTTPError, URLError
from urllib.parse import urlparse
from urllib.request import Request, urlopen
Expand Down
3 changes: 1 addition & 2 deletions errbot/storage/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import types
from collections.abc import MutableMapping
from contextlib import contextmanager

Expand Down Expand Up @@ -36,7 +35,7 @@ def open_storage(self, storage_plugin, namespace):

def close_storage(self):
if not self.is_open_storage():
raise StoreNotOpenError(f"Storage does not appear to have been opened yet")
raise StoreNotOpenError("Storage does not appear to have been opened yet")
self._store.close()
self._store = None
log.debug("Closed storage '%s'", self.namespace)
Expand Down
3 changes: 1 addition & 2 deletions tests/borken_plugin/broken.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import borken # fails on purpose

from errbot import BotPlugin, botcmd

import borken # fails on purpose # noqa: F401

class Broken(BotPlugin):
@botcmd
Expand Down
2 changes: 1 addition & 1 deletion tests/cascade_dependent_plugins/child1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from errbot import BotPlugin, botcmd
from errbot import BotPlugin


class Child1(BotPlugin):
Expand Down
2 changes: 1 addition & 1 deletion tests/cascade_dependent_plugins/child2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from errbot import BotPlugin, botcmd
from errbot import BotPlugin


class Child2(BotPlugin):
Expand Down
2 changes: 0 additions & 2 deletions tests/core_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Test _admins_to_notify wrapper functionality"""

import pytest

extra_config = {"BOT_ADMINS_NOTIFICATIONS": "zoni@localdomain"}


Expand Down
1 change: 1 addition & 0 deletions tests/flow_plugin/flowtest_flows.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: F841
from __future__ import absolute_import

from errbot import BotFlow, FlowRoot, botflow
Expand Down
1 change: 0 additions & 1 deletion tests/link_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# coding=utf-8
from os import path

import pytest

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

Expand Down
2 changes: 0 additions & 2 deletions tests/matchall_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# coding=utf-8
from os import path

import pytest

extra_plugin_dir = path.join(path.dirname(path.realpath(__file__)), "matchall_plugin")


Expand Down
2 changes: 1 addition & 1 deletion tests/template_plugin/test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import absolute_import

from errbot import BotPlugin, arg_botcmd, botcmd, re_botcmd
from errbot import BotPlugin, arg_botcmd, botcmd


class Test(BotPlugin):
Expand Down
5 changes: 4 additions & 1 deletion tests/utils_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# coding=utf-8
import logging
import sys

from datetime import timedelta

import pytest
Expand All @@ -8,7 +11,7 @@
from errbot.bootstrap import CORE_STORAGE, bot_config_defaults
from errbot.storage import StoreMixin
from errbot.storage.base import StoragePluginBase
from errbot.utils import *
from errbot.utils import version2tuple, format_timedelta, split_string_after

log = logging.getLogger(__name__)

Expand Down
1 change: 0 additions & 1 deletion tests/webhooks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import pytest
import requests

from errbot.backends.test import FullStackTest, testbot

log = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion tools/plugin-gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def check_repo(repo):
repo_entry[name] = plugin
plugins[repo_name] = repo_entry
log.debug("Catalog added plugin %s.", plugin["name"])
except:
except Exception:
log.error("Invalid syntax in %s, skipping...", plug["path"])
continue

Expand Down
11 changes: 3 additions & 8 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py39,py310,py311,py312,py312,codestyle,dist-check,sort,security,docs
envlist = py39,py310,py311,py312,py312,codestyle,dist-check,security,docs
skip_missing_interpreters = True

[testenv]
Expand All @@ -11,9 +11,9 @@ commands = pytest -v tests/
recreate = true

[testenv:codestyle]
deps = black
deps = ruff
commands =
black --check errbot/ tests/ tools/
ruff check errbot/ tests/ tools/

[testenv:dist-check]
deps =
Expand All @@ -22,11 +22,6 @@ commands =
python setup.py sdist
twine check {toxinidir}/dist/*

[testenv:sort]
deps =
isort
commands = isort --check-only errbot/

[testenv:security]
deps =
bandit
Expand Down

0 comments on commit 65544e2

Please sign in to comment.