diff --git a/.github/workflows/py-checks.yml b/.github/workflows/py-checks.yml index 1002ae4c0..bf1915989 100644 --- a/.github/workflows/py-checks.yml +++ b/.github/workflows/py-checks.yml @@ -19,15 +19,20 @@ jobs: run: | python -m pip install --upgrade pip pip install -r ./requirements.dev.txt - pip install black flake8 flake8-type-checking mypy - name: Check with black run: | VERNUM=${{ matrix.python-version }} TARGETV="py${VERNUM/./}" python -m black -t $TARGETV --diff --color --check ./ + - name: Check imports with isort (black) + run: | + python -m isort --profile=black --check --diff --color ./ - name: Check with flake8 run: | python -m flake8 ./ - name: Check with MyPy run: | mypy --python-version 3.8 --warn-unused-ignores ./*.py + - name: Check with Pylint + run: | + pylint --recursive=y . diff --git a/code_checks.sh b/code_checks.sh new file mode 100644 index 000000000..11c0659a9 --- /dev/null +++ b/code_checks.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +DO_FORMAT=0 +if [ "$1" == "format" ]; then + DO_FORMAT=1 +fi + +echo "Black on py38:" +if [ "$DO_FORMAT" == "0" ]; then + python -m black . --diff --color --check -t py38 +else + python -m black . -t py38 +fi +echo "----" +echo "" + +echo "isort imports:" +if [ "$DO_FORMAT" == "0" ]; then + isort . --check --diff --color --profile black +else + isort . --profile black +fi +echo "----" +echo "" + +echo "Flake8:" +python -m flake8 +echo "----" +echo "" + +echo "MyPy:" +mypy --python-version 3.8 --warn-unused-ignores ./*.py +echo "----" +echo "" + +echo "pylint:" +pylint --recursive=y . +echo "----" +echo "" + + + +#echo "Checking for i18n data missing from source base..." +#python ./tests/test_missing_i18n.py +#echo "----" + +#echo "Bandit:" +#bandit -r . +#echo "----" + + + diff --git a/musicbot/bot.py b/musicbot/bot.py index aa5208599..82b3ee708 100644 --- a/musicbot/bot.py +++ b/musicbot/bot.py @@ -108,7 +108,8 @@ def __init__( load_opus_lib() try: sys.stdout.write(f"\x1b]2;MusicBot {BOTVERSION}\x07") - except Exception: + # TODO: what does this raise and when would it raise it? + except Exception: # pylint: disable=broad-exception-caught log.warning( "Failed to set terminal Title via escape sequences.", exc_info=True ) @@ -341,7 +342,9 @@ async def _join_startup_channels( if not player.playlist.entries: await self.on_player_finished_playing(player) - except Exception: + # TODO: drill down through the above code and find what exceptions + # we actually want to be handling here. + except Exception: # pylint: disable=broad-exception-caught log.debug( "Error joining %s/%s", channel.guild.name, @@ -1410,9 +1413,10 @@ async def on_ready(self) -> None: mute_discord_console_log() log.debug("Connection established, ready to go.") + # Set the handler name if we have it. I don't know why, but we do. if self.ws._keep_alive: # pylint: disable=protected-access - self.ws._keep_alive.name = ( - "Gateway Keepalive" # pylint: disable=protected-access + self.ws._keep_alive.name = ( # pylint: disable=protected-access + "Gateway Keepalive" ) else: log.error( @@ -3274,6 +3278,8 @@ def check(reply: discord.Message) -> bool: delete_after=30, ) else: + # patch for loop-defined cell variable. + res_msg_ids = [] # Original code for entry in entries: result_message = await self.safe_send_message( @@ -3287,12 +3293,13 @@ def check(reply: discord.Message) -> bool: if not result_message: continue + res_msg_ids.append(result_message.id) + def check_react( reaction: discord.Reaction, user: discord.Member ) -> bool: return ( - user == message.author - and reaction.message.id == result_message.id + user == message.author and reaction.message.id in res_msg_ids ) # why can't these objs be compared directly? reactions = ["\u2705", "\U0001F6AB", "\U0001F3C1"] diff --git a/requirements.dev.txt b/requirements.dev.txt index a564ae420..3029521f0 100644 --- a/requirements.dev.txt +++ b/requirements.dev.txt @@ -5,9 +5,12 @@ yt-dlp colorlog cffi --only-binary all; sys_platform == 'win32' certifi -objgraph pymediainfo # included for coverage, could be removed later. + +objgraph flake8 flake8-type-checking black +isort mypy +pylint